This script allows a player to compete against a computer in tic tac toe. The game was written in SQL 2005 and may not work correctly in other versions. The game has a little more kick than a game of tic tac toe with an inadequate opponent. This is because to make the game feel more realistic; I added a layer of AI to the computer. The computer can logically determine if he should block the player from wnning the game or go for the win itself.
To Play
Playing the game is very simple. The game feeds off three main stored procedures.
- usp_PlayTicTacToe: marks the board with your move
- usp_Redraw_Board: Renders the game board, in its current state
- usp_New_Game: Starts a new game by clearing the tables
usp_PlayTicTacToe has 2 mandatory inputs Quadrant and Mark. Quadrant is the spot you want to mark on the game board. Examples of a quadrant are a1,a2,a3,b1,b2,b3,c1,c2,c3. Mark is a one character notation of your player. Mark can be either 'X' or 'O'.
usp_Redraw_Board simply renders the game board by reading the data from the table and redrawing the board.
usp_New_Game is used once the game has completed to start a fresh game. It just resets the necessary columns in the table to start afresh.
Other than these three stored procedures, the game itself will tell you if something is wrong with your inputs. Additionally, after each of the computer's moves; you can view where the computer moved on his last turn.
This design really has scalablity for future enhancesments. The table could be created as a Global Temp table and the game could be played by remote players.
That's about it. Enjoy.
Thanks,
Adam