Custom turn order that automatically skips turns #904
-
I am build a card game where each player has 1 move per turn, however, if a player does not fit particular criteria and it is their turn then the game should automatically pass them and give the turn to the next player in line. I have tried to evaluate the skip criteria in the onBegin of turn but this does not work. What is the best way to implement this type of feature? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
@dondragon2 You can implement this using a custom turn order. Here’s a basic example that re-implements the default behaviour: const game = {
turn: {
order: {
// Get the initial value of playOrderPos at the beginning of the phase.
first: (G, ctx) => 0,
// Get the next value of playOrderPos at the end of each turn.
next: (G, ctx) => {
const nextPos = (ctx.playOrderPos + 1) % ctx.numPlayers;
return nextPos;
},
},
},
}; In your case, you would find the next player based on your criteria and return their position in the play order. For example, if you have some function that can return the next player ID, you might write a next method like: next: (G, ctx) => {
const playerID = getNextPlayerID(G, ctx);
const playOrderPos = ctx.playOrder.indexOf(playerID);
return playOrderPos;
}, (To be clear, Here’s a demo of a game where players can be eliminated that uses some similar ideas to skip eliminated players: https://codesandbox.io/s/boardgameio-elimination-demo-2rezv?file=/src/Game.js |
Beta Was this translation helpful? Give feedback.
-
thanks @delucis that is working as expected. |
Beta Was this translation helpful? Give feedback.
@dondragon2 You can implement this using a custom turn order. Here’s a basic example that re-implements the default behaviour:
In your case, you would find the next player based on your criteria and return their position in the play order. For example, if you have some function that can return the next player ID, you might write a next method…