Thread: alternating players

  1. #1
    Registered User
    Join Date
    Oct 2013
    Posts
    9

    Question alternating players

    So I'm working on several 2v2 programs like tic-tac-toe, connect four and battleship. Generally what would be the best way to alternate players?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    An if statement usually works.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Welcome to the forum, ktype!

    Most chess programs use the simple: player=!player, where player is a bool or int value acting like a bool, with value of true/false, or 1/0.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alternating turns in C code for 2 player game
    By richardpd in forum C Programming
    Replies: 7
    Last Post: 01-20-2013, 05:41 PM
  2. Replies: 2
    Last Post: 08-23-2009, 08:52 AM
  3. alternating sum
    By alyeska in forum C++ Programming
    Replies: 20
    Last Post: 01-04-2008, 09:45 PM
  4. MP3 Players
    By Dark_Phoenix in forum Tech Board
    Replies: 5
    Last Post: 12-03-2006, 03:22 PM
  5. dvd players
    By metsman20 in forum Tech Board
    Replies: 1
    Last Post: 12-26-2003, 09:56 PM

Tags for this Thread