Fix age fields

This commit is contained in:
Kenneth Allen 2021-10-15 17:39:57 +11:00
parent 5abba327ba
commit 9fc770d086

View File

@ -377,7 +377,7 @@ export function countPoints(state: State, playerIdx: number): number {
})) }))
} }
function beginAge(state: State): State { function beginAge(state: State): State {
const age = (state.age ?? minAge - 1) + 1 const age = state.age === undefined ? 0 : state.age + 1
const deck = shuffle(buildDeck(age, state.players.length).map(s => s.name)) const deck = shuffle(buildDeck(age, state.players.length).map(s => s.name))
const handSize = Math.ceil(deck.length / state.players.length) const handSize = Math.ceil(deck.length / state.players.length)
const hands = chunk(deck, handSize) const hands = chunk(deck, handSize)
@ -453,7 +453,7 @@ function doTurn(state: State): State {
} }
if (state.turnsRemaining === 0) { if (state.turnsRemaining === 0) {
state = endAge(state) state = endAge(state)
if (state.age === maxAge) { if (state.age === numAges - 1) {
return { return {
...state, ...state,
stage: 'finished', stage: 'finished',
@ -503,7 +503,7 @@ const reducers: { [type: string]: (state: State, action: any) => State } = {
} }
return { return {
...state, ...state,
players: state.players.map(p => p.name === action.player ? { ...p, wonder: action.wonder }: p), players: state.players.map(p => p.name === action.player ? { ...p, wonder: action.wonder } : p),
} }
}, },
'start game': (state, action: StartGameAction) => { 'start game': (state, action: StartGameAction) => {