From Test-Scratch-Wiki

Artificial Intelligence, commonly abbreviated by AI, is the name given to a computerized mind that consists entirely of programming code.

Its usage in Scratch is most common in projects in which a user can play a game against the computer.

How to make an AI

Optimal AIs

An optimal AI will need an indefinite amount of If () Then, Else blocks, loops, and/or time, so that an AI has a response to every action that the player does and/or time to examine every possible outcome. However, this is impossible to program.

Simple AIs

Most projects that use AI use special techniques, such as using variables to store different values. Those values may be previous locations, user input, and so on. They help to calculate different actions that allow the computer to make a good challenge to the player, and succeed in its task.

Perfect AIs

A practical and optimal AI will use recursion to try to adapt to the circumstances itself. Given:

  • What all moves are possible
  • An algorithm to tell if a given position is a win for the computer, loss for the computer, tie, or incomplete game

A recursive function to return the best move for a player given a board and which player can be written under the following logic:

  • If position is tied, won, or lost, return tied, won, or lost and the board
  • Otherwise:
    • Iterating through each continuation of the game for the player:
      • If the best move for the other player results in a loss for him, return "Win" and the continued position
      • If the best move for the other player results in a tie for him, return "Tie" and the continued position
      • If the best move for the other player results in a win for him, return "Loss" and the continued position

See this project for an example of strategic artificial intelligence

See the article on game trees for more on recursive functions and their use in constructing AI.

Common AIs

There is also another class of AI that depends solely upon only one of the factors. Such AI are a lot simpler and, in many cases, effective. However, they have not fulfilled the true requirements of an AI. For example, in the project Agent White, the AI moves along a given path and only tries to shoot at you. In this AI, only the user's position matters to the AI; it will rotate so that its gun turns towards the user. In the project Broomsticks, the AI only changes its position with respect to the ball.

Learning AIs

AI which can take external stimulus and decide upon the best way to use it is called a learning AI, or an AI that uses something called machine learning. Neural networks are also commonly used for learning AIs. A learning AI is able to learn off of its present and past experiences. One popular way of making a learning AI is by using a neural network. Another is by making a list of things and creating a list of things for every reply (which can be done in Scratch, although with some difficulty as 2D arrays are not easily implemented).

Other AIs

Another type of AI is used in a remix of Agent White found here. In this remix, the AI picks a random path and follows it. It uses Math and future x and y positions based on the current position of a character which you control. Then it slowly moves toward that new position until it either reaches its destination or hits a wall. In this case, instead of Artificial Intelligence, it is more of Artificial Random because it never uses intelligence other than running into walls.

Limitations of AI

One of the biggest limitations AI has been facing is speed. Scratch is a rather slow programming language; hence most AIs on Scratch are slow because their scripts are too long.

AI also can be easily tricked. A paradox(self-contradicting statement) will shut AI down. This can annoy the creators because the data will have to be reset and the AI will have to start from scratch. However, if a programmer adds a paradox filter the AI will recognize it as a paradox and ignore.

Complications also have been a major problem for AI as all AI programs are very large and complicated, thus the scripts may become long and too laggy to make without crashing Scratch. For example, a simple game of Tic-Tac-Toe with AI will have a script running into multiple pages due to many conditions in if blocks, and sometimes an attempt to speed it up will be made by making it Single Frame.

The complicated script also makes remixing a problem. Because of all this, most AI projects have no improvements, causing the AI to remain glitchy. AIs may make mistakes that are easily avoidable by users, and most mistakes like these are hilariously known as artificial stupidity.

Common Uses

  • 2 player (Computer vs Player) games
  • Path-finding
  • Having a conversation with the user (commonly referred to as a chatbot)

Example Projects

These projects have been using AI in the truest sense possible practically:

See Also


Cookies help us deliver our services. By using our services, you agree to our use of cookies.