Use named time constants · HansSam/hyperbot@1c5175f · GitHub
Skip to content

Commit 1c5175f

Browse files
committed
Use named time constants
1 parent e1fa878 commit 1c5175f

3 files changed

Lines changed: 27 additions & 29 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions

server.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const fooVersion = '1.0.43'
5151

5252
const lichessBotName = process.env.BOT_NAME || "chesshyperbot"
5353

54-
const { isEnvTrue, formatTime, formatName } = require('@easychessanimations/tinyutils')
54+
const { isEnvTrue, formatTime, formatName, SECOND, MINUTE } = require('@easychessanimations/tinyutils')
5555

5656
let envKeys = []
5757

@@ -215,8 +215,6 @@ fetch(`https://raw.githubusercontent.com/hyperbotauthor/hyperbot/docs/docs.json`
215215

216216
const lichessUtils = require("@easychessanimations/lichessutils")
217217

218-
console.log(lichessUtils)
219-
220218
const { streamNdjson } = require('@easychessanimations/fetchutils')
221219

222220
const { makeUciMoves } = require("@easychessanimations/scalachess/lib/outopt.js")
@@ -474,11 +472,11 @@ async function makeMove(gameId, state, moves, analyzejob, actualengine){
474472
}
475473

476474
if(!enginePromise){
477-
let doPonder = ( ( state.botTime > 15000 ) || isEnvTrue("ALLOW_LATE_PONDER") ) && allowPonder
475+
let doPonder = ( ( state.botTime > ( 15 * SECOND ) ) || isEnvTrue("ALLOW_LATE_PONDER") ) && allowPonder
478476

479477
if(isEnvTrue('REDUCE_LATE_TIME')){
480-
if(state.botTime < 30000) state.botTime = Math.floor(state.botTime * 0.75)
481-
if(state.botTime < 15000) state.botTime = Math.floor(state.botTime * 0.75)
478+
if(state.botTime < ( 30 * SECOND ) ) state.botTime = Math.floor(state.botTime * 0.75)
479+
if(state.botTime < ( 15 * SECOND ) ) state.botTime = Math.floor(state.botTime * 0.75)
482480
}
483481

484482
logPage(`engine time ${state.botTime} ponder ${doPonder} thinking with ${engineThreads} thread(s) ${engineHash} hash and overhead ${engineMoveOverhead}`)
@@ -492,8 +490,8 @@ async function makeMove(gameId, state, moves, analyzejob, actualengine){
492490
}
493491
:
494492
{
495-
wtime: correspondenceThinkingTime * 1000, winc: 0,
496-
btime: correspondenceThinkingTime * 1000, binc: 0
493+
wtime: correspondenceThinkingTime * SECOND, winc: 0,
494+
btime: correspondenceThinkingTime * SECOND, binc: 0
497495
}
498496

499497
analyzejob.setTimecontrol(timecontrol)
@@ -531,7 +529,7 @@ async function makeMove(gameId, state, moves, analyzejob, actualengine){
531529

532530
engine.spawn() // restart engine for retry move
533531

534-
setTimeout(_ => makeMove(gameId, state, moves, analyzejob, actualengine), gameStartDelay * 5000)
532+
setTimeout(_ => makeMove(gameId, state, moves, analyzejob, actualengine), 10 * SECOND)
535533
}
536534
}
537535
}
@@ -587,8 +585,8 @@ function playGame(gameId){
587585
if(realtime){
588586
playingGameId = gameId
589587

590-
setTimeout(_=>lichessUtils.gameChat(gameId, "all", welcomeMessage), 2000)
591-
setTimeout(_=>lichessUtils.gameChat(gameId, "all", goodLuckMessage), 4000)
588+
setTimeout(_=>lichessUtils.gameChat(gameId, "all", welcomeMessage), 2 * SECOND)
589+
setTimeout(_=>lichessUtils.gameChat(gameId, "all", goodLuckMessage), 4 * SECOND)
592590

593591
engine.spawn()
594592

@@ -607,9 +605,9 @@ function playGame(gameId){
607605
const initial = clock.initial || 0
608606
const increment = clock.increment || 0
609607

610-
duration = initial + 40 * increment
608+
duration = initial + lichessUtils.AVERAGE_GAME_LENGTH * increment
611609
}else{
612-
duration = ( 180 * 60 * 1000 ) + ( 40 * 180 * 1000 )
610+
duration = ( 180 * MINUTE ) + ( lichessUtils.AVERAGE_GAME_LENGTH * 180 * SECOND )
613611
}
614612

615613
console.log("duration", duration)
@@ -623,7 +621,7 @@ function playGame(gameId){
623621
console.log(`opponent failed to make their opening move for ${abortAfter} seconds`)
624622

625623
abortGame(gameId)
626-
}, abortAfter * 1000)
624+
}, abortAfter * SECOND)
627625

628626
whiteName = blob.white.name
629627
whiteTitle = blob.white.title
@@ -800,7 +798,7 @@ function streamEvents(){
800798
if(blob.type == "gameStart"){
801799
let gameId = blob.game.id
802800

803-
setTimeout(_=>playGame(gameId), gameStartDelay * 1000)
801+
setTimeout(_=>playGame(gameId), gameStartDelay * SECOND)
804802
}
805803

806804
if(blob.type == "gameFinish"){
@@ -814,7 +812,7 @@ function streamEvents(){
814812
engine.stop()
815813
}
816814

817-
setTimeout(_=>lichessUtils.gameChat(gameId, "all", goodGameMessage), 2000)
815+
setTimeout(_=>lichessUtils.gameChat(gameId, "all", goodGameMessage), 2 * SECOND)
818816
}
819817
}})
820818
}
@@ -1200,19 +1198,19 @@ app.listen(port, _ => {
12001198
console.log(`hours ok: ${hours}, keep alive`)
12011199
fetch(KEEP_ALIVE_URL)
12021200
}
1203-
}, KEEP_ALIVE_INTERVAL * 60 * 1000)
1201+
}, KEEP_ALIVE_INTERVAL * MINUTE)
12041202
}
12051203

12061204
streamEvents()
12071205

12081206
setInterval(_=>{
12091207
if(!playingGameId){
1210-
if((new Date().getTime() - lastPlayedAt) > challengeTimeout * 60 * 1000){
1208+
if((new Date().getTime() - lastPlayedAt) > challengeTimeout * MINUTE){
12111209
console.log(`idle timed out`)
12121210
challengeRandomBot()
12131211
}
12141212
}
1215-
}, challengeInterval * 60 * 1000)
1213+
}, challengeInterval * MINUTE)
12161214
})
12171215

12181216
// end launch

yarn.lock

Lines changed: 8 additions & 8 deletions

0 commit comments

Comments
 (0)