Skip to content

Commit

Permalink
Remove unnecessary try catch as we fixed it
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh committed Feb 29, 2024
1 parent 2ddc26f commit d1fc7ec
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions src/main/scala/Chess.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,26 @@ import chess.opening.{ Opening, OpeningDb }
import chess.Square
import chess.bitboard.Bitboard
import chess.variant.{ Crazyhouse, Variant }
import com.typesafe.scalalogging.Logger
import cats.syntax.option.*

import ipc.*

object Chess:

private val logger = Logger(getClass)

def apply(req: ClientOut.AnaMove): ClientIn =
Monitor.time(_.chessMoveTime):
try
chess
.Game(req.variant.some, req.fen.some)(req.orig, req.dest, req.promotion)
.map((game, move) => makeNode(game, Uci.WithSan(Uci(move), move.san), req.path, req.chapterId))
.getOrElse(ClientIn.StepFailure)
catch
case e: java.lang.ArrayIndexOutOfBoundsException =>
logger.warn(s"${req.fen} ${req.variant} ${req.orig}${req.dest}", e)
ClientIn.StepFailure
chess
.Game(req.variant.some, req.fen.some)(req.orig, req.dest, req.promotion)
.map((game, move) => makeNode(game, Uci.WithSan(Uci(move), move.san), req.path, req.chapterId))
.getOrElse(ClientIn.StepFailure)

def apply(req: ClientOut.AnaDrop): ClientIn =
Monitor.time(_.chessMoveTime):
try
chess
.Game(req.variant.some, req.fen.some)
.drop(req.role, req.square)
.map((game, drop) => makeNode(game, Uci.WithSan(Uci(drop), drop.san), req.path, req.chapterId))
.getOrElse(ClientIn.StepFailure)
catch
case e: java.lang.ArrayIndexOutOfBoundsException =>
logger.warn(s"${req.fen} ${req.variant} ${req.role}@${req.square}", e)
ClientIn.StepFailure
chess
.Game(req.variant.some, req.fen.some)
.drop(req.role, req.square)
.map((game, drop) => makeNode(game, Uci.WithSan(Uci(drop), drop.san), req.path, req.chapterId))
.getOrElse(ClientIn.StepFailure)

def apply(req: ClientOut.AnaDests): ClientIn.Dests =
Monitor.time(_.chessDestTime):
Expand Down

0 comments on commit d1fc7ec

Please sign in to comment.