Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
VirtuosoChess authored Jul 29, 2024
1 parent d6815da commit dd7a880
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions ui/analyse/src/TablebaseService.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.unmarshalling.Unmarshal

// Case class to parse the tablebase result
case class TablebaseResult(
dtz: Int, // Distance to zeroing (moves to convert to a simpler endgame)
wdl: Int, // Win/draw/loss indicator
bestMove: String
)

object TablebaseService {
def getTablebaseEvaluation(fen: String): Future[TablebaseResult] = {
val url = s"https://api.chessdb.cn:81/tablebase?fen=$fen"
val response = Http().singleRequest(HttpRequest(uri = url))

response.flatMap {
case HttpResponse(StatusCodes.OK, _, entity, _) =>
Unmarshal(entity).to[TablebaseResult]
case _ =>
Future.failed(new Exception("Failed to fetch tablebase data"))
}
}
}

0 comments on commit dd7a880

Please sign in to comment.