The AI Extension is here! šŸ’“

The AI / Neural Networks extension is finally here!

I’m warning you right now. THIS IS A LONG POST. It is well over A THOUSAND WORDS. If just the explanation of the extension is THIS long, the extension must be much more complicated! This is not meant for beginners, although with dedication you can definitely learn.

I’m so excited to finally unveil the extension!! It took me a while, and you can see my progress here in the making thread.

Blocks

MakeNet

Parameters:

  • Inputs: The number of inputs of your neural network
  • Outputs: The number of outputs in your neural network

Creates a neural network in the form of a nested array. See image 1 for a visual description. Each value is automatically set to 0.

RandomNet

Parameters:

  • Inputs, Outputs: See MakeNet description

Creates a neural network in the form of a nested array. See image 1 for a visual description. Each value is automatically set to a random number between 0.00 and 1.00.

Mix

Parameters:

  • Net 1: The first neural network
  • Inputs, Outputs: See MakeNet description
  • Net 2: The second neural network

Randomly mixes two arrays together, mimicking how animals share DNA with offspring. Creates a net that is similar to both parents. Most useful for creating a batch of neural networks similar to the best 2 nets so you can pick the best one using the ā€˜Accuracy’ function described below. (This is how the neural networks reproduce and become better)

Think

Parameters:

  • Net: The neural network that is doing the thinking
  • Inputs: An array of the inputs being fed into the net. Even if there is only one input, this should still be an array.
  • Outputs: See MakeNet description.

Feeds inputs into the neural network to get its response. This is the most complicated part of the neural network, beware! If you want a quick description, a neural network is actually a REALLY big math problem. You run the inputs into the neural network, and get a result between 0-1 for each output. You could also think of it as the inputs being the ā€˜eyes’ of the net, it takes in what it sees, processes it, and spits out a response such as ā€œ0 - run!!ā€ or ā€œ1 - Fight!!ā€. I’ll be happy to describe in detail how it actually works, but I’m not the best teacher, so try this website!

Accuracy

Parameters:

  • Net: The neural network you are testing.
  • Inputs, Outputs: See MakeNet description.
  • InputOutput: An array, filled with a bunch of arrays, which are each filled with an array of inputs and an array of desired outputs each.
    Okay, this one sounds complicated, but it’s really just a shortcut to help with training! The Input/Output array is formatted uniquely, so check Image 2 for a visual representation. Each array inside of it has an array of the inputs the neural network is given and an array of the outputs that you WANT it to give out. This is like a test sheet for the neural network, with questions and answers! The function takes the average amount of error of the neural network’s answers. If the function returns 0, or something close, then it has high accuracy. If the value is farther from 0, such as being closer to -1 or 1, then the net has low accuracy. (For all of you math-brains out there, yes, this could be better measured with standard deviation instead. Maybe a future update, but it works for now.)

How to use a Neural Network
It’s great to know what the blocks are, but you probably still don’t know how a neural network answers a question. Here’s a step by step to use your own neural network!

1. Think of Inputs and Outputs!

Think of the outputs first: What do I want my Network to put out? In my color guessing game, the frogs had to output 1 number between 0-1 representing how much they thought you liked that color.

For the inputs, think of what information your Net needs to know to figure out what to do. A tip for making the net work better is making your inputs more ā€˜specialized’- basically, choose a form that works best. That’s not very intuitive, but here’s an example: In a fighting game, instead of just giving the enemy the x and y coordinates of the player, instead gave it the DISTANCE of it to the player on the x and y axes. This is more useful info! In my color guessing game, the frogs had to know the color that was on the screen, which is represented in RGB format. RGB values are 3 values ranging from 0-255, but all inputs and outputs are between 0-1, so I divided the numbers by 255!

2. Get the Inputs and wanted Outputs! (The data / the test)

This step will vary a lot depending on what you’re using the net for. (Feel free to ask me if you need help!) For the color guessing game AI, I gathered a bunch of inputs in the form of the RBG values of a color, and gathered a bunch of wanted outputs in the form of a 0-1 value of how much the player liked the color. You can then run all of this data through the accuracy block to get the net’s score!

4. Run the tests, pick the 2 best nets, mix them, and repeat!

On each of your many neural networks (yes, many! I suggest at least 5, but more speeds up the process.) check their accuracy. Pick the 2 networks that have the best accuracy (the ones with the least distance to 0, which you can get by taking the absolute value of the accuracy) and mix them a few times. Test the new mixes/offspring and pick the best 2 of THOSE nets. Repeat until satisfied! See image 3 for details.

5. Show off your super awesome net!

Show the player your net! In the AI color guessing game, this means telling the player what the AI thinks your favorite colors are. This is mostly up to you, but I’m happy to help!

Images




(Did you like my little images? :3)

There will be a demo game coming soon! AND a YouTube video about this extension for my online school newspaper! (If you give me permission in your reply, I would love to include your comments on this extension!)

Seriosly, thanks for reading my super long extension. It has taken me nearly half a year to get this out. One of the key features even had to be scrapped simply because makecode arcade couldn’t handle that many computations. This is probably the most complicated coding, math, or research project I’ve ever done! I’d love to hear feedback, good or bad. I’m 100% open to help you use the extension! I just cant wait to have someone put my research to good use!
– Randomuser / Dragondoodle

32 Likes

Amazing!!!

4 Likes

Thank you!! :sparkling_heart:

6 Likes

Good news! The demo is here!

Controls:

  • WASD / Arrows to place character
  • A to end the training and see results

Place your character and see these cute little AI’s find the best path to you!

17 Likes

This could revolutionize bots in makecode games! Great work, very impressive!

9 Likes

Jeez this is WAAAY too hard to understand. I was so excited to use it, and of course I still AM happy that this has been released, especially after how much time you put into it, but YIKES this is confusing…

7 Likes

this is… AWESOME!!!

5 Likes

Don’t worry! I’m working on making an automatic training block, basically combining the past blocks into an even EASIER to use block. You could simply input the situations you would put the AI in and the outputs you want and it would automatically train a bunch! I’m very happy you are excited :smiley:

7 Likes

THANKS So MUCH!! :smiley:

6 Likes

Ah, that was one of my main inspirations! I don’t quite have the time now, as I need to get this demo out to the newspaper, but after that I’m 100% making an auto-fighting robot. (Can you beleive that? Enemies that learn how you fight as you play? It sounds like magic!)

12 Likes

I’m going to be on a long journey… figuring out how to use this extension. But I’ll get there eventually!

4 Likes

I probably missed it but is there a way to give the AI some training so it doesn’t have to learn everything from scratch every time the game restarts?

4 Likes

Yes! I’m open to help!

6 Likes

Ah, that’s a great idea! There are two ways to do this, depending on what you meant:

  1. Save the AI as a setting, either whole or deconstructed and then reassembled. This is if you meant when the game restarts each time the same player restarts the game.
  2. Use ā€˜console log’ or ā€˜splash’ to get each value in the network, and then manually make the network as a code block. This is if you meant that you wanted a base network to be in every run of the game.

Here’s a diagram explaining how the network is formatted:


As always, I’d love to help you figure it out!

6 Likes

I just realized… I have neural networks… and I have robot-making parts…
… AI ROBOTS!?

15 Likes

There’s an entire movie franchise about how that’s a terrible idea :laughing:

9 Likes

I can only imagine the crazy games people will make with this.

5 Likes

Thanks!

2 Likes

lol

6 Likes

More than one lol

3 Likes