Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Tic Tac Toe TSQL Style

By Adam Haines,

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.

  1. usp_PlayTicTacToe: marks the board with your move
  2. usp_Redraw_Board: Renders the game board, in its current state
  3. 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

Total article views: 2745 | Views in the last 30 days: 14
 
Related Articles
FORUM

4 Quadrant Scatter Plot ChartUsing SSRS 2008R2

Create a 'Gartner Magic Quadrant Chart'

BLOG

Adobe Flash Player Update Available

There is an Adobe Flash Player available to address a security issue. The bulletin shows as being re...

FORUM

Computed Column

Computed Column

FORUM

Computed Columns

Computed Columns

BLOG

PASS Board Elections

Here is the list of suckers, uh, I mean, candidates, that actually want to subject themselves to the...

Tags
games    
sql server 2005    
t-sql    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones