Commit 12bfd434 authored by Tomas Hamsa's avatar Tomas Hamsa
Browse files

Reflect evaluating side in zobrist hash

parent 4953abc9
Pipeline #57878 failed with stages
in 23 seconds
......@@ -27,8 +27,9 @@ class MoveController @Inject()(cc: ControllerComponents) extends AbstractControl
implicit request: Request[JsValue] =>
try {
val playerMarks = request.body.as[Array[String]]
val board = Board.construct(playerMarks)
player.makeMove(board, startTime, playerOnMove - 1)
val sideToMove = playerOnMove - 1
val board = Board.construct(playerMarks, sideToMove)
player.makeMove(board, startTime, sideToMove)
.map(move => Json.toJson(move))
.map(json => Ok(json).as(JSON))
.getOrElse(BadRequest("Can't place any move on board " + board))
......
......@@ -51,6 +51,7 @@ object Board {
), Array(
-7126580416890112952L, -1782447980347338418L, -2526344961250908015L, -1378500423292696720L, 4207501070433209994L, 6397452736235751868L, -4066758331280355425L, -7131309795230044561L, 5410465996976108602L, 1268500705752846945L, -6424781857546715749L, -8309202878572384611L, 2585006347675412925L, 2043873514263250047L, 8480246476151866067L, -1914678766279131707L, -2693506737043665808L, -535081200508741350L, 6341168295270091151L, 5613591495603081472L, 3590596494706185875L, -3032524102469029509L, 289883121385828801L, -4716175090982955675L, 5326834200688793302L, -5764088009668063474L, -1070457973221587856L, 6036810095434497806L, -4461539667447982215L, 2833198819691925426L, -8937181656384804063L, -7417901542845911385L, -8649951278815316051L, 1081412033375045710L, 4312867601193623813L, -1443409540255551927L, -9102745935873937605L, -2834835827832099077L, -1020750277205502516L, 9125995914355418081L, -8955190292308860570L, -7694377995816315549L, 3877520570276105414L, 3477498631113967250L, 1626804700037038693L, 6103519723240706154L, -8857620778177247005L, -4408374019167353921L, -4848204035061493853L, 2187613357476190197L, -4823480531394302637L, -6118781183357278286L, -6259030617253278412L, -8543767785398820349L, 150293853105698470L, 814872441454200232L, -6909933772322780257L, 4857626764745923885L, -4707965600163741699L, 5718038262786530193L, 5812515835018169284L, 6974579464361100284L, 1811945923636509590L, -6060677059763415048L
))
private final val SIDE_HASHES: Array[Long] = Array(-2135228578154510254L, 1680719277508214808L)
final val WIN_MASKS: Array[Long] = Array(
-576460752303423488L,
......@@ -151,10 +152,10 @@ object Board {
4328785936L
)
def construct(playerMarks: Array[String]): Board = {
def construct(playerMarks: Array[String], sideToMove: Int): Board = {
val player1Marks = java.lang.Long.parseUnsignedLong(playerMarks(0), 2)
val player2Marks = java.lang.Long.parseUnsignedLong(playerMarks(1), 2)
val zobristHash = appendZobristHash(0, player1Marks) ^ appendZobristHash(1, player2Marks)
val zobristHash = appendZobristHash(0, player1Marks) ^ appendZobristHash(1, player2Marks) ^ SIDE_HASHES(sideToMove)
return new Board(Array(player1Marks, player2Marks), zobristHash)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment