refactor: clean up code formatting and improve readability across multiple files
This commit is contained in:
@@ -11,9 +11,9 @@ import de.nowchess.rules.sets.DefaultRules
|
||||
|
||||
object ClassicalBot:
|
||||
def apply(
|
||||
difficulty: BotDifficulty,
|
||||
rules: RuleSet = DefaultRules,
|
||||
book: Option[PolyglotBook] = None,
|
||||
difficulty: BotDifficulty,
|
||||
rules: RuleSet = DefaultRules,
|
||||
book: Option[PolyglotBook] = None,
|
||||
): Bot =
|
||||
val search = AlphaBetaSearch(rules, weights = EvaluationClassic)
|
||||
val timeBudgetMs = 1000L
|
||||
|
||||
@@ -14,12 +14,12 @@ import de.nowchess.rules.sets.DefaultRules
|
||||
|
||||
object HybridBot:
|
||||
def apply(
|
||||
difficulty: BotDifficulty,
|
||||
rules: RuleSet = DefaultRules,
|
||||
book: Option[PolyglotBook] = None,
|
||||
nnueEvaluation: Evaluation = EvaluationNNUE,
|
||||
classicalEvaluation: Evaluation = EvaluationClassic,
|
||||
vetoReporter: String => Unit = println(_),
|
||||
difficulty: BotDifficulty,
|
||||
rules: RuleSet = DefaultRules,
|
||||
book: Option[PolyglotBook] = None,
|
||||
nnueEvaluation: Evaluation = EvaluationNNUE,
|
||||
classicalEvaluation: Evaluation = EvaluationClassic,
|
||||
vetoReporter: String => Unit = println(_),
|
||||
): Bot =
|
||||
val search = AlphaBetaSearch(rules, TranspositionTable(), classicalEvaluation)
|
||||
context =>
|
||||
|
||||
@@ -12,9 +12,9 @@ import de.nowchess.rules.sets.DefaultRules
|
||||
|
||||
object NNUEBot:
|
||||
def apply(
|
||||
difficulty: BotDifficulty,
|
||||
rules: RuleSet = DefaultRules,
|
||||
book: Option[PolyglotBook] = None,
|
||||
difficulty: BotDifficulty,
|
||||
rules: RuleSet = DefaultRules,
|
||||
book: Option[PolyglotBook] = None,
|
||||
): Bot =
|
||||
val search = AlphaBetaSearch(rules, weights = EvaluationNNUE)
|
||||
context =>
|
||||
|
||||
+6
-4
@@ -16,16 +16,18 @@ class OfficialBotChallengeResource:
|
||||
@POST
|
||||
@Path("/{botId}")
|
||||
def challengeWithDifficulty(
|
||||
@PathParam("botId") botId: String,
|
||||
@QueryParam("difficulty") difficulty: Int
|
||||
@PathParam("botId") botId: String,
|
||||
@QueryParam("difficulty") difficulty: Int,
|
||||
): Response =
|
||||
DifficultyMapper.fromElo(difficulty) match
|
||||
case None =>
|
||||
Response.status(Response.Status.BAD_REQUEST)
|
||||
Response
|
||||
.status(Response.Status.BAD_REQUEST)
|
||||
.entity(s"""{"error":"difficulty must be between 1000 and 2800"}""")
|
||||
.build()
|
||||
case Some(botDifficulty) =>
|
||||
// TODO: wire to account service challenge creation + bot routing
|
||||
Response.status(Response.Status.CREATED)
|
||||
Response
|
||||
.status(Response.Status.CREATED)
|
||||
.entity(s"""{"botId":"$botId","difficulty":$difficulty,"status":"pending"}""")
|
||||
.build()
|
||||
|
||||
+14
-2
@@ -46,7 +46,13 @@ class OfficialBotService:
|
||||
watchGame(botName, gameId, playingAs, difficulty, botAccountId)
|
||||
catch case _: Exception => ()
|
||||
|
||||
private def watchGame(botName: String, gameId: String, playingAs: String, difficulty: Int, botAccountId: String): Unit =
|
||||
private def watchGame(
|
||||
botName: String,
|
||||
gameId: String,
|
||||
playingAs: String,
|
||||
difficulty: Int,
|
||||
botAccountId: String,
|
||||
): Unit =
|
||||
val handler: Consumer[String] = msg => handleGameEvent(botName, gameId, playingAs, difficulty, botAccountId, msg)
|
||||
redis.pubsub(classOf[String]).subscribe(s"${redisConfig.prefix}:game:$gameId:s2c", handler)
|
||||
()
|
||||
@@ -69,7 +75,13 @@ class OfficialBotService:
|
||||
computeAndSendMove(botName, gameId, fen, difficulty, botAccountId)
|
||||
catch case _: Exception => ()
|
||||
|
||||
private def computeAndSendMove(botName: String, gameId: String, fen: String, difficulty: Int, botAccountId: String): Unit =
|
||||
private def computeAndSendMove(
|
||||
botName: String,
|
||||
gameId: String,
|
||||
fen: String,
|
||||
difficulty: Int,
|
||||
botAccountId: String,
|
||||
): Unit =
|
||||
val level = DifficultyMapper.fromElo(difficulty).getOrElse(BotDifficulty.Medium)
|
||||
botController.getBot(botName).orElse(botController.getBot(level.toString.toLowerCase)).foreach { bot =>
|
||||
FenParser.parseFen(fen).toOption.foreach { context =>
|
||||
|
||||
@@ -11,7 +11,6 @@ import org.scalatest.matchers.should.Matchers
|
||||
import de.nowchess.rules.sets.DefaultRules
|
||||
|
||||
class ClassicalBotTest extends AnyFunSuite with Matchers:
|
||||
|
||||
|
||||
test("nextMove on initial position returns a move"):
|
||||
val bot = ClassicalBot(BotDifficulty.Easy)
|
||||
|
||||
Reference in New Issue
Block a user