@@ -45,6 +45,42 @@ export const initialClockSeconds = (timeControl: string): number => {
4545 return minutes === 0 ? ZERO_BASE_START_SECONDS : minutes * 60
4646}
4747
48+ /** The increment in seconds (0 for unlimited). */
49+ export const incrementSeconds = ( timeControl : string ) : number => {
50+ if ( timeControl === 'unlimited' || ! timeControl . includes ( '+' ) ) return 0
51+ const seconds = parseInt ( timeControl . split ( '+' ) [ 1 ] , 10 )
52+ return Number . isFinite ( seconds ) ? seconds : 0
53+ }
54+
55+ // What the backend tells Maia about a game without clocks: 3 minutes each.
56+ // Sent as a real clock, so that "Human-like" thinking time takes time there
57+ // too (no clock at all is the backend's sign to move at once).
58+ export const UNLIMITED_MAIA_CLOCK_SECONDS = 180
59+
60+ /**
61+ * The clocks sent with a request for Maia's move: the game's own, so that
62+ * Maia plays the time control being played, and spends time as it would.
63+ * With "Instant" thinking time, its reply's delay is not waited for.
64+ */
65+ export const maiaMoveClocks = (
66+ timeControl : string ,
67+ maiaClockSeconds : number ,
68+ ) : { initialClock : number ; increment : number ; currentClock : number } => {
69+ const initialClock = initialClockSeconds ( timeControl )
70+ if ( initialClock === 0 ) {
71+ return {
72+ initialClock : UNLIMITED_MAIA_CLOCK_SECONDS ,
73+ increment : 0 ,
74+ currentClock : UNLIMITED_MAIA_CLOCK_SECONDS ,
75+ }
76+ }
77+ return {
78+ initialClock,
79+ increment : incrementSeconds ( timeControl ) ,
80+ currentClock : maiaClockSeconds ,
81+ }
82+ }
83+
4884/**
4985 * A time control as PGN's TimeControl header writes it: the starting time and
5086 * increment in seconds ("300+3"), or "-" for a game without clocks.
0 commit comments