Vary required round sum by player count
3 players → -105, 4-6 → -110, 7-8 → -100. Adds requiredRoundSum() to scoring.ts and threads it through isRoundScoreValid and the sum display in EnterScores. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+8
-1
@@ -2,8 +2,15 @@ export function isIndividualScoreValid(n: number): boolean {
|
|||||||
return n % 5 === 0 && n <= 110
|
return n % 5 === 0 && n <= 110
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function requiredRoundSum(playerCount: number): number {
|
||||||
|
if (playerCount === 3) return -105
|
||||||
|
if (playerCount >= 7) return -100
|
||||||
|
return -110
|
||||||
|
}
|
||||||
|
|
||||||
export function isRoundScoreValid(scores: number[]): boolean {
|
export function isRoundScoreValid(scores: number[]): boolean {
|
||||||
return scores.every(isIndividualScoreValid) && scores.reduce((a, b) => a + b, 0) === -110
|
return scores.every(isIndividualScoreValid)
|
||||||
|
&& scores.reduce((a, b) => a + b, 0) === requiredRoundSum(scores.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns totals[i][j] = cumulative score for player j after round i.
|
// Returns totals[i][j] = cumulative score for player j after round i.
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { useState } from 'react'
|
|||||||
import PageFrame from '../components/PageFrame'
|
import PageFrame from '../components/PageFrame'
|
||||||
import PrimaryButton from '../components/PrimaryButton'
|
import PrimaryButton from '../components/PrimaryButton'
|
||||||
import HelpModal from '../components/HelpModal'
|
import HelpModal from '../components/HelpModal'
|
||||||
import { isIndividualScoreValid, isRoundScoreValid } from '../game/scoring'
|
import { isIndividualScoreValid, isRoundScoreValid, requiredRoundSum } from '../game/scoring'
|
||||||
import { type GameState } from '../types'
|
import { type GameState } from '../types'
|
||||||
import styles from './EnterScores.module.css'
|
import styles from './EnterScores.module.css'
|
||||||
import sharedStyles from '../styles/shared.module.css'
|
import sharedStyles from '../styles/shared.module.css'
|
||||||
@@ -33,6 +33,7 @@ export default function EnterScores({ game, onSubmit, onBack, initialValues }: P
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const target = requiredRoundSum(game.players.length)
|
||||||
const parsed = values.map(v => parseInt(v, 10))
|
const parsed = values.map(v => parseInt(v, 10))
|
||||||
const fieldError = values.map((v, i) => v !== '' && (isNaN(parsed[i]) || !isIndividualScoreValid(parsed[i])))
|
const fieldError = values.map((v, i) => v !== '' && (isNaN(parsed[i]) || !isIndividualScoreValid(parsed[i])))
|
||||||
const allFilled = parsed.every(n => !isNaN(n))
|
const allFilled = parsed.every(n => !isNaN(n))
|
||||||
@@ -66,8 +67,8 @@ export default function EnterScores({ game, onSubmit, onBack, initialValues }: P
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
<p className={`${styles.sumLine}${sum === -110 ? ` ${styles.sumValid}` : ''}`}>
|
<p className={`${styles.sumLine}${sum === target ? ` ${styles.sumValid}` : ''}`}>
|
||||||
Sum: {sum} / −110
|
Sum: {sum} / {target}
|
||||||
</p>
|
</p>
|
||||||
</PageFrame>
|
</PageFrame>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user