what is the easy way to switching between players in a tic tac toe game
Printable View
what is the easy way to switching between players in a tic tac toe game
I like that its simple and to the point. So i will do something like this:
INT or STRING or CHAR play;
play=X
if ( play == 'X' )
play = 'O';
else play = 'X';
Something like that... I know its not clean or writing right.
You could always just use a number to represent the player:
Something like that would suffice. :DCode:/* player enumerations for whatever */
enum { Player1, Player2 };
/* pick a random player to start */
int player = rand( ) & Player1;
... do stuff ...
/* switch players */
player = !player;
Quzah.
Doh. Yeah. I spaced that one. I had it as a % Player2 first, then realized that Player2 was 1, so I changed it to & ... but then I changed the 2 to a 1.:rolleyes:Quote:
Originally posted by Salem
> int player = rand( ) & Player1;
Tsk Tsk - what's the value of the first enum in an enumeration?
I usually do my enumerations with a final one depicting the "total" enumerations for things like list counts and random numbers and the like:
My brain threw an exception since I didn't put one in my enum list in the example code. :PCode:enum { foo, foo1, foo2, totalfoo };
list[ totalfoo ];
Quzah.