Jump to content

Determining who's turn it is

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
I'm just wondering what strategy you would use to determine what players turn it is in a game with more than two people. For two players I would just have a value increase after each player went then use the remainder operator to determine if the number is even or odd, if it is even player 1's turn, if its odd, player 2's turn...something like this

if(count % 2 == 0){
//player 1's turn
} else {
//player 2's turn
}

but I'm not sure what strategy i should use with, say a game with 4 players, any ideas?

Edit:
Other than manually coding, because there is infinity moves and I cant code that many lines, something like this is unreasonable imo

if count = 0
//player 1
else if count = 1
//player 2
else if count = 2
//player 3
else if count = 3
//player 4
else if count = 4
//player 1
else if count = 5
//player 2

and so on indefinitely

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
cout >> "it is player " >> count % players + 1 >> "'s turn";
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
Thanks :D

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
No problem. I love math problems!
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog