TIC-80 Tutorial: Machine Learning (do not get scared away by this: It is simply a part of AI) | Perceptron learning

minidavid
2 min readMay 16, 2024

--

[Pretty 3d model I made for visual flair on the page]

For a neural network, perceptron learning is the simplest introductory algorithm one may be introduced to.

It is used for simple binary classification. This means it may be used to group things together.

For a game, I believe, several ideas may sprout into mind. This may be a way to design a randomly generated level nicer or provide better enemies depending on the difficulty or general input of the player.

— — — — — — — — — — — — — — — — — — —

[Random animation I made, placed here for visual flair]

Simply put, perceptrons take input, processes it and gives an output.

  1. Perceptron learning is a simple neural network that takes the input.

2. It has some weight (that is randomly generated. This is to ensure the weights are not the same, so learning may take place (you don’t need to master all ‘at)).

3. It then gets a weighted sum (this simply means weight*input plus weight * input)

4. And finally carries in an activation function (to determine the output).

This is the code:

rnd = math.random
-- Initialize weights
local weight1 = rnd(1) - 0.5
local weight2 = rnd(1) - 0.5

-- Activation function (step function)
function activate(sum)
if sum > 0 then
return 1
else
return 0
end
end

-- Main loop
function TIC()

cls()
-- Sample input values (you can change these)
local input1 = 1
local input2 = 0

-- Calculate weighted sum
local weightedSum = input1 * weight1 + input2 * weight2

-- Activate the perceptron
local output = activate(weightedSum)

-- Print output
print("Output: " .. output, 20, 20, 15)
end

The activation function is called a step activation activation function which is pretty limited in the world of neural networks, though creatively I think one may come up with some cool stuff with it.

--

--

minidavid
0 Followers

Just making tutorials as I learn