![]() ![]() I didn't connect the red legs of the LEDs on the gameboard as you only need to indicate two on states for each position. I used slightly higher resistors for the green legs of the LEDs as I find these are usually brighter than the blue and red legs. Each pushbutton has a corresponding 10-20K resistor and each LED has a 220-500 ohm resistor in series with it. I sketched the circuit in Easy EDA and then designed a PCB as a shield that clips onto an Arduino Mega. If you get or have common anode LEDs then you'll need to amend the PCB design to accommodate this change. Make sure that you get common cathode RGB LEDs as this leg of the LED is tied to GND on this shield. The shield makes use of 21 digital outputs for the LEDs and 10 digital inputs for the pushbuttons. There are ways to use addressable LEDs to condense the IO to fit onto an Arduino Uno, but I already had a bunch of these RGB LEDs and an Arduino Mega lying around, so that's what I used for this project. This drastically reduces the AI's ability to win and you're left with the possibility of winning most games that you start and a fair number of games that the AI starts. To make the game a bit more fun, as it's not much fun losing or drawing games all the time, I've added a second mode that plays random moves for the first two plays before allowing the AI to finish off the game. With the AI running the minimax algorithm on the Arduino, it'll always play the best possible move, so regardless of who starts, you won't be able to beat it. The AI then plays the move that it calculates to be the best at reducing the possibility of the opponent winning. A state which results in a draw is given 0. A move that results in the AI winning is given a score of 10 and one which results in the opponent winning is given -10. The algorithm works by calculating the value of each state of the game by looking at all of the possible outcomes following each move. It's commonly used in computer-based chess games to this day. It's an old algorithm that has been around since the early 1900s and can be applied to many two-player, turn-based games. The AI works on a minimax algorithm, which is a recursive algorithm aimed at minimising the possible loss for a worst-case scenario. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |