The continuation of my 3D TicTacToe LED Matrix project. See Introduction and Part 2.
Download the code directly here: LED_Matrix_TTT4.pde
Some general notes:
1. The AI is based on game theory taken from a book I read about 20 years ago. Unfortunately I don’t remember the name of it. It uses a Minimax algorithm as well as Alpha-beta pruning to decrease the number of nodes that need to be evaluated. Wikipedia offers a concise description of these with many external links. I spent about a month learning the algorithms and coding them, so I’m sure they can be greatly enhanced, especially since more than 20 years has past. However, I am proud to say that pitting this program up against another 3D TTT I found online, that mine trounced the other.
2. I wanted the LED matrix cube to be constantly displaying the player LED spot selection, the current cube moves, or the computer thinking (LEDs going on and off). In order to do this, even while the Arduino is off doing other things, I needed to use interrupts. Using the MsTimer2 library I was able to set up a routine, disp_LED_cube, that was called every 200 ms with 1 of 4 states:
3. The current program uses a keypad to make the moves. The keys 1-4 are for selection of the player’s move. It first uses a ‘wall’ to select the z-direction, with the keys moving the wall. After the proper wall is selected, the ’5′ key will then lock-in that wall, and display a column that represents the y-direction. Again, the 1-4 keys allow for the selection of the wished-upon column. Player then pushes ’5′ key to lock-in column. Finally, user selects for the specific LED in column they wish to use as their move. Pressing the ’5′ key will begin the Arduino deciding its move. I’m currently working on code to use a thumbstick rather than the keypad.
4. The code is GPL. Please use it as you like and definitely improve upon it. I would, of course, really like you to credit me for the work I’ve put into it should you use it.

Categories
Tag Cloud
Blog RSS
Comments RSS
Last 50 Posts
Back
Void
Life « Default
Earth
Wind
Water
Fire
Light 