Introduction

T3 is a 3-dimensional variation of Tic-Tac-Toe where a human plays against a computer. The game can be won in the same ways as traditional Tic-Tac-Toe, but many new "3 in a row" patterns come into play. Three pieces of the same color placed directly on top of one another, diagonally "climbing", or in the traditional pattern only two layers higher are some of the new ways to win. In addition to adding an extra dimension to Tic-Tac-Toe, the game also requires "stacking" in the vertical axis; a piece cannot be played on the second or third level unless the piece directly beneath it are already in play.

 

High Level Design

In order to make this game a reality, a method for a digital computer to observe and react to the analog world had to be designed. To detect where the human player made his or her move, force sensing resistors were used at the base of each of the nine stacks that made up the game board. These sensors needed only to be able to detect when additional force was applied. The hardware would then use this input to make a decision as to where it should play its next piece and execute this move by means of a mechanical arm. In order to simplify the control issues of the design, two slides were constructed so that the arm would only need two pick-up routines instead of a potential fourteen. also, because of the stacking rule, only nine drop routines were required. In addition, a LCD character display was implemented into the design to provide the human player with various messages and options, and push buttons were used to allow the player to select these options.


Figure 1: Overview of High Level Design

 

Member Task Distribution

Jeff Sacks Software organization, Game board/pieces fine tuning, Arm control software, sensor hardware, LCD Display hardware/software, duct tape engineering
Chris Babuska Game board/pieces construction, Arm hardware/timers, sensor software, LCD Display hardware/software, krazy glue engineering

 

Hardware Design

Arm: The mechanical arm was comprised of five indepently controlled servo motors, each with an operating range of 180 degrees. The orientation of these motors at any given time was determined by a signal with a 20 ms period and a duty cycle such that the output is high for 0.9 ms to 2.1 ms.

Generating these control signals required a counter for the 20 ms period, along with a register and comparator for each of the five servos to determine the pulse width. Writing a value to one of the specified memory locations would cause that particular output signal to remain high until the counter reached the written value at which point the output would go to a low state. The signal would then remain in that state until the counter reached 20ms, when it would be reset and the output would return to a high state.

Sensors: The force sensing resistors used to detect the human player's game piece placement decrease their resistance as greater force is applied. Thus the voltage across these resistors was used to determine whether or not an additional game piece had been added to one of the stacks. The nine different sensors were connected via an analog multiplexor to a single input into the analog to digital converter on the EECS 373 lab board, and the address lines to the mux were controlled by a write command to the appropriate memory address. The end of conversion signal from the ADC triggered a bit at a specified memory location to flip to one, notifying the polling software that the digital data could then be read. This bit could then be reset by writing a one to the same address.

LCD: The LCD character display was controlled by 4 signals: register select, read/write, enable, and 8 data bits. The register select state was determined by the last bit of the address being written to. The read/write signal was tied low, as only writes were required to interface to the display. The timing of the enable signal had to meet the HD44780U controller specifications, which was accomplished by means of a series of flip-flops in hardware. Because the LCD controller would only read the data lines when an enable signal was received, the 8 data bits were driven at all times from the primary data bus.

Buttons: Switches 1 and 2 were used in the design. Pressing one of the buttons would write a bit to a particular flip flop. These flip-flops could then be cleared by writing a one to a specified memory address.

 

Software Design

Arm: The arm was able to pick up pieces from two separate locations and drop them at the nine different spots on the game board. Four main functions were used in the control of the arm. The first function was written in assembly and simply wrote a value to memory which was used to generate the appropriate duty cycle. The other three functions were written in C and all of them called the saveToMem function many times. One of these functions put the arm into a reset position. The second one was passed a parameter of either 1 or 0 and based on that picked up a piece from either the left or the ride side of the board. The final function had all nine drop routines and would select the appropriate one based on the input parameter from the game algorithm.

Sensors: In order to check the value of one of the nine sensors, a write was used to start an analog to digital conversion. The data written selected the address used in the analog multiplexor. Following the start of a conversion, the software would poll to determine if an EOC signal had been generated by the ADC. Once the EOC was generated, the converted digital value was read. This code was written in assembly. At the beginning of each of the human's moves, the values on each of the nine sensors would be read in a total of 50 times to determine the maximum value. The software would then loop through and check to see if any sensor's value was greater than its previous maximum. Once a value was detected that was greater than the previous maximum, a slight pause would occur followed by another loop to double check and make sure a move actually occurred at that spot. This portion of the code was written in C.

LCD: All of the code to control the LCD was written in assembly. The first function called initialized the display according to the specification. Following initialization, sequences of letter were written along with the locations that each line would start on. Each addition message we wrote would clear the display before writing to it. We had functions to display a welcome message, starting menu, who's turn it is, who won, and a play again message.

Game Algorithm: The entire function to determine the computer's next move was coded in C. The input to the function was the current state of the board and a "randomly" generated number and the output was the updated board. To determine the "random" number, an ADC conversion was called on one of our sensors at the start of the game. The random number was the converted value % 4. The first thing the computer looked for in a move was if it could win in its next move. Secondly, it checked to see if the human could win and if so it blocked that move. The next thing the computer looked for was if it was a legal move to take the middle piece since this is the most valuable move in the game. If the first three conditions were not met, the random number would come into play. We created four separate routines which were aimed at taking corner pieces on the lowest level and block the human from winning on the lowest level. Once the lowest level was filled, the computer moved to any open spot.

Overall Organization: When our program first starts, the LCD is initialized, the arm is moved to its reset position, and a power setting is changed to allow for accurate control of the arm. Next, the welcome menu is displayed followed by a pause and a prompt asking who will go first. Once the game starts a loop is used until one player wins. The LCD displays which player's turn it current is. Players rotate making moves and once the game ends either a victor or defeat message is displayed along with the arm either taunting or falling down in defeat. After a few seconds pass, the arm goes back to its reset position and a message is displayed saying to clear the board and press a button in order to play again.


Figure 2: High Level Software Flow Chart

 

Results of the Design

While the design in large part worked as expected, there two unresolved issues: the occasional "miss" by the mechanical arm, and misdetections by the sensors.

The case where the arm would pickup and drop a game piece in such a manner that it missed the stack can best be described as a control problem. Operating within the limited resolution of the servo motors and the fairly high degree of accuracy this game called for, the hardware and software were designed as well as they could have been regarding this problem. The issue was primarily a result of poor pick ups due to the imperfect nature of the delivery slide (re: it was made out of cardboard and duct tape). A better constructed pick-up location would most likely have prevented most of these misses.

Regarding the force sensing resistors, both false positives (detecting a move when no piece was played) and misses of pieces actually played were encountered. The main issue was that the pieces themselves had a very low mass. Consequently the added weight of a new piece would sometimes have no effect on the voltage across the resistor. In order to counter this problem the threshold voltage at which a new piece is detected could be lowered, but this would increase the likelihood of false positives. Eliminating this problem entirely would either require more accurate sensors or constructing significantly heavier game pieces.

 

Conclusions

Given the time constraints, the game worked nearly as well as it could have. Implementing a "perfect" version of this design would require a reworking of the general game board and piece design, but is entirely possible with components on that were used. The game piece detection likely could have been improved upon with additional modification of the game board and software however. Finally, a version of the game where the board is 4 spaces wide, long, and high would have been ideal, but was ruled out due to the arm's limited flexibility and range.

 

Media

Click here to see a video of the game

 

References

HD44780 Controller Spec
Optrex 16433 Manufacturers Spec
FSR Guide
Servo Manual