Thread: switching between players

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    34

    switching between players

    what is the easy way to switching between players in a tic tac toe game

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    34
    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.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You could always just use a number to represent the player:
    Code:
    /* player enumerations for whatever */
    enum { Player1, Player2 };
    
    /* pick a random player to start */
    int player = rand( ) & Player1;
    
    ... do stuff ...
    
    /* switch players */
    player = !player;
    Something like that would suffice.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Salem
    > int player = rand( ) & Player1;
    Tsk Tsk - what's the value of the first enum in an enumeration?
    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.

    I usually do my enumerations with a final one depicting the "total" enumerations for things like list counts and random numbers and the like:
    Code:
    enum { foo, foo1, foo2, totalfoo };
    list[ totalfoo ];
    My brain threw an exception since I didn't put one in my enum list in the example code. :P

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dice game: How to handle 2 players and separate totals?
    By crazychile in forum C Programming
    Replies: 7
    Last Post: 10-20-2008, 12:01 AM
  2. Structure of a program
    By stef569 in forum C Programming
    Replies: 6
    Last Post: 12-03-2006, 12:13 AM
  3. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  4. mp3 players vs mp3 cd players
    By Geo-Fry in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-06-2003, 09:22 PM
  5. Switching frequency and Bandwidth???
    By pastecopy in forum Tech Board
    Replies: 0
    Last Post: 03-23-2003, 11:13 AM