Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tic-tac-toe program

Status
Not open for further replies.

spiller

Technical User
Nov 8, 2002
1
IE
Hi,

I'm currently coding a tic-tac-toe program which has been going o.k. until now. The problem I'm having is alternating between two players in the two player mode. I need a flag or something to set one player off and the other on when it is that player's turn. I know it's something small but I just can't seem to get it working. Any suggestions would be greatly appreciated.
thanks in advance,
spiller
 
Say you have a variable player representing the player. On the board, when it is 0, it is empty, when it is 1, it is one player, when it is 2, it is the other one. Flipping it between players is just

player = 3 - player;
opponent = 3 - player;

The player can use any position that is 0 or try to make a line with positions containing player or try to block lines with positions containing opponent.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top