Of course, the algorithm we use in this game is very simple, because the game is very simple. If we design the game tree we can discover some winning strategies and easily implement them in code or we can let the CPU compute the game tree in real time and chose the best move by itself. This algorithm can be implemented in Arduino easily, because the Tic-Tac-Toe game is very simple, and we can easily analyze it and solve it. This is not the best tic tac toe game algorithm, but one of the simplest. That’s it, this simple algorithm can beat the human player every time or at the worst case scenario the game will result in a draw. If the player can’t win in a single move, it plays a corner move if it is available or a random one from the remaining. From this point on, the Arduino first checks if the player can win in the next move and blocks that move. The, second move for the Arduino is also a random corner from the remaining without caring about the player move at all. This decision alone, makes the game much easier for the Arduino to win. To answer this question, let’s look at the algorithm I have implemented. But how can a $2 chip, the Arduino CPU, beat the human brain? Is the program we developed smarter than the human brain? By adding two more lines to the code of the game, we can make the Arduino impossible to lose the game. I intentionally designed this algorithm to make some mistakes in order to give the human player a chance to win. It will win most of the games, or if you are a very good player the game will end in a draw. We can then press the play again button to start the game again. When the game is over, the Game Over screen appears. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row wins the game. The Arduino then plays its move and so on. We can then play our move simply by touching the screen. After connecting the screen to the Arduino Uno, we can load the code and we are ready to play.Īt first, we press the “Start Game” button and the game starts.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |