Page 1 of 1

Changing player colours during game

Posted: 09 August 2021, 15:53
by ShaPhi7
It makes sense for my game to fix colours to white/black, (ignoring player preferences), similar to chess or Go.

It also makes sense to allow players to play two rounds of the game, once as white, once as black (as the goals are different for each colour).

Is it safe to swap the player colours part way through the game?
Would anything break?
Are there any games that do this already?

P.S. I can work around this if it's a bad idea, but if its possible, this would be the simplest way.

Re: Changing player colours during game

Posted: 10 August 2021, 03:47
by Peyrol
Hex implements the pie rule, also known as the swap rule. Say the colors are red versus blue, and red moves first by placing the first stone on an otherwise empty board. At that point in the game ONLY, the second player has the option to swap sides. If sides are swapped, the player who moved first as red becomes blue, and makes the next move. This is called swapping sides, or swapping dolors. If the second player chooses not to swap at that point in the game, then sides may not be swapped at all in that game. This is called the pie rule because it is like sharing the last of the pie. One person cuts the pie into two slices, and the other chooses which slice to eat. It should be mentioned that without this rule for Hex, the first player would have a strong advantage, much stronger than in chess.

Unfortunately, this swap move is not implemented ideally here. Player names are still colored red and blue the same way they were before swap. The only way to tell what color you are after swap is in the message "playerx has to move" where the name is colored correctly.

There could be another way to implement swap for some games such as Hex, which is called swapping the first piece. A blue token is added to the board IN THE CORRESPONDING LOCATION for blue, and the red token is returned to red's virtual supply. For example if red makes the first move at A4 and blue clicks on swap firstpiece, a blue token would be added to the cell D1 and the red token is removed. This is effectively the same as swapping sides as far as the game position is concerned. It might be more convenient for players to keep their assigned colors this way.

For chess, if white plays 1.b3 and black clicks on swap-sides, the first player becomes black and makes the next move. Or if black clicks swap-firstmove instead, white's b3 pawn would return to b2 and black would play b6. I'm not saying such an option would be a good idea for chess, just explaining how the swap move would work.

Re: Changing player colours during game

Posted: 15 August 2021, 00:49
by Victoria_La
Everything is possible but it could be very complex unless you can swap player colors in the player table (which I never attempted before).
In player table there is player_color, if you change it you have to call self::reloadPlayersBasicInfos() to re-cache and would have to make a notification
to reload the game for client. Not sure effect on logs - it will be probably wrong.

The other (complex) option is to create another column for player_color2 and manage it completely separately, overriding the color everywhere on client side (and its a lot of places). For example you cannot send ${player_name} in the log - because this will use color

Re: Changing player colours during game

Posted: 15 August 2021, 11:18
by jmcl99
It's definitely possible to change player colours as Terra Mystica does it. Most games (it's an option) start with an auction for which faction to play - each faction has a fixed colour so the player colours are changed to that of the relevant faction once the auction is over.

Re: Changing player colours during game

Posted: 24 August 2021, 04:41
by Idsky
Here's another option:
You could remove the 2 colours you use from your game's supported color list so the players get something else (one of their preferred colours)…
then show their current play-colour another way, a coloured bar in the player control panel perhaps, with a title or tooltip explaining it.