Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Short 2 player TicTacToe program
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
A.J




PostPosted: Mon Nov 02, 2009 7:59 pm   Post subject: Short 2 player TicTacToe program

The program (about 20 lines) allows two players to play Tic Tac Toe. I store the board into one number, by representing 'X' with the binary for 1, or '01', 'O' with the binary for 2, or '10', and a blank for the binary for 0, or '00'. Each square is represented by two bits.

I check for wins by 'or'ing it with different winning positions.

How it works is you enter a number from 1->9 (inclusive) to play a move:

1 2 3
4 5 6
7 8 9

1 represents the top left corner, 2 represents the top middle square, etc...

I took out things like error checking, as I am assuming you will enter a number from 1 - 9 and that you are going to play on a square that hasn't been played on before (It is just adding 3 additional lines, anyways).



Cool TicTacToe.t
 Description:
Here it is

Download
 Filename:  Cool TicTacToe.t
 Filesize:  610 Bytes
 Downloaded:  326 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: