Skip to content

Commit

Permalink
Use DUEL_SIZE between duel matches
Browse files Browse the repository at this point in the history
  • Loading branch information
williamgrosset committed Feb 10, 2024
1 parent ce9a610 commit fd199ce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/lib/match/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface Options {
kFactor?: number
}

export const DEFAULT_K_FACTOR = 32
export const DUEL_SIZE = 2
export const DEFAULT_MIN_CONTESTANTS = 2
export const DEFAULT_MAX_CONTESTANTS = 256
export const DEFAULT_K_FACTOR = 32
13 changes: 5 additions & 8 deletions src/main/matches/duel/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import { Player } from '../../contestants/player'
import { Match } from '../../../lib/match'
import { Options } from '../../../lib/match/options'
import { Options, DUEL_SIZE } from '../../../lib/match/options'
import { PlayerResult } from '../../../lib/match/results'
import { MatchError, ErrorType } from '../../../lib/match/error'

type DuelOptions = Partial<Pick<Options, 'kFactor'>>

const MIN_PLAYERS = 2
const MAX_PLAYERS = 2

export class Duel extends Match {
constructor(options?: DuelOptions) {
super({
...options,
minContestants: MIN_PLAYERS,
maxContestants: MAX_PLAYERS
minContestants: DUEL_SIZE,
maxContestants: DUEL_SIZE
})
}

addPlayer(player: Player) {
if (this.contestants.size === MAX_PLAYERS) {
if (this.contestants.size === DUEL_SIZE) {
throw new MatchError(ErrorType.MAX_PLAYERS)
}

Expand All @@ -31,7 +28,7 @@ export class Duel extends Match {
throw new MatchError(ErrorType.MATCH_COMPLETE)
}

if (this.contestants.size !== MIN_PLAYERS) {
if (this.contestants.size !== DUEL_SIZE) {
throw new MatchError(ErrorType.MIN_PLAYERS)
}

Expand Down
15 changes: 8 additions & 7 deletions src/main/matches/team-duel/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { Team } from '../../contestants/team'
import { Match } from '../../../lib/match'
import { Options } from '../../../lib/match/options'
import { Options, DUEL_SIZE } from '../../../lib/match/options'
import { TeamResult } from '../../../lib/match/results'
import { MatchError, ErrorType } from '../../../lib/match/error'

type TeamDuelOptions = Partial<Pick<Options, 'kFactor'>>

const MIN_TEAMS = 2
const MAX_TEAMS = 2

export class TeamDuel extends Match {
constructor(options?: TeamDuelOptions) {
super({ ...options, minContestants: MIN_TEAMS, maxContestants: MAX_TEAMS })
super({
...options,
minContestants: DUEL_SIZE,
maxContestants: DUEL_SIZE
})
}

addTeam(team: Team) {
if (this.contestants.size === MAX_TEAMS) {
if (this.contestants.size === DUEL_SIZE) {
throw new MatchError(ErrorType.MAX_TEAMS)
}

Expand All @@ -27,7 +28,7 @@ export class TeamDuel extends Match {
throw new MatchError(ErrorType.MATCH_COMPLETE)
}

if (this.contestants.size !== MIN_TEAMS) {
if (this.contestants.size !== DUEL_SIZE) {
throw new MatchError(ErrorType.MIN_TEAMS)
}

Expand Down

0 comments on commit fd199ce

Please sign in to comment.