You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
712 B
24 lines
712 B
export function nextPlayingSeat(state, seat) {
|
|
const count = state.pieces?.length ?? state.positions.length;
|
|
for (let offset = 1; offset <= count; offset++) {
|
|
const next = (seat + offset) % count;
|
|
if (!state.withdrawn?.includes(next)) return next;
|
|
}
|
|
throw new Error('No quedan jugadores activos.');
|
|
}
|
|
|
|
export function withdrawParchis(state, seat) {
|
|
const next = structuredClone(state);
|
|
next.withdrawn = [...(next.withdrawn ?? []), seat];
|
|
next.pieces[seat] = [-1, -1, -1, -1];
|
|
if (next.turn === seat) {
|
|
next.turn = nextPlayingSeat(next, seat);
|
|
next.die = null;
|
|
next.bonus = false;
|
|
next.extraTurn = false;
|
|
next.sixes = 0;
|
|
next.lastMoved = null;
|
|
}
|
|
return next;
|
|
}
|