Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option(x) -> Some(x) #487

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/scala/Board.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ case class Board(
if v == Crazyhouse then copy(variant = v).ensureCrazyData
else copy(variant = v)

def withCrazyData(data: Crazyhouse.Data) = copy(crazyData = Option(data))
def withCrazyData(data: Crazyhouse.Data) = copy(crazyData = Some(data))
def withCrazyData(data: Option[Crazyhouse.Data]) = copy(crazyData = data)
def withCrazyData(f: Crazyhouse.Data => Crazyhouse.Data): Board =
withCrazyData(f(crazyData | Crazyhouse.Data.init))
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/Clock.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ case class Clock(

def isRunning = timer.isDefined

def start = if isRunning then this else copy(timer = Option(now))
def start = if isRunning then this else copy(timer = Some(now))

def stop =
timer.fold(this) { t =>
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/Color.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ enum Color(val name: String, val letter: Char) derives Eq:
object Color:

def fromName(n: String): Option[Color] =
if n == "white" then Option(White)
else if n == "black" then Option(Black)
if n == "white" then Some(White)
else if n == "black" then Some(Black)
else None

def apply(c: Char): Option[Color] =
if c == 'w' then Option(White)
else if c == 'b' then Option(Black)
if c == 'w' then Some(White)
else if c == 'b' then Some(Black)
else None

val white: Color = White
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/Drop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ case class Drop(
val board = after.variant.finalizeBoard(
after updateHistory { h =>
h.copy(
lastMove = Option(Uci.Drop(piece.role, square)),
lastMove = Some(Uci.Drop(piece.role, square)),
unmovedRooks = before.unmovedRooks,
halfMoveClock = if piece.is(Pawn) then HalfMoveClock.initial else h.halfMoveClock + 1
)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/History.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ case class History(

inline def withCastles(inline c: Castles) = copy(castles = c)

inline def withLastMove(inline m: Uci) = copy(lastMove = Option(m))
inline def withLastMove(inline m: Uci) = copy(lastMove = Some(m))

def withCheck(color: Color, check: Check) =
if check.yes then copy(checkCount = checkCount add color) else this
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/LagTracker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final case class LagTracker(
val e = lagEstimator.record((lag atMost quotaMax).centis.toFloat)
copy(
lagEstimator = e,
compEstimate = Option(Centis.ofFloat(e.mean - .8f * e.deviation).nonNeg atMost quota)
compEstimate = Some(Centis.ofFloat(e.mean - .8f * e.deviation).nonNeg atMost quota)
)

def moves = lagStats.samples
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/Move.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ case class Move(
val board = after.variant.finalizeBoard(
after updateHistory { h1 =>
val h2 = h1.copy(
lastMove = Option(toUci),
lastMove = Some(toUci),
unmovedRooks = before.unmovedRooks,
halfMoveClock =
if piece.is(Pawn) || captures || promotes then HalfMoveClock.initial
Expand Down Expand Up @@ -117,7 +117,7 @@ case class Move(
for
b2 <- after take dest
b3 <- b2.place(color - p, dest)
yield copy(after = b3, promotion = Option(p))
yield copy(after = b3, promotion = Some(p))
else this.some

inline def withAfter(newBoard: Board) = copy(after = newBoard)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/MoveMetrics.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ case class MoveMetrics(

// Calculate client reported lag given the server's duration for the move.
def reportedLag(elapsed: Centis) =
clientMoveTime.fold(clientLag)(mt => Option(elapsed - mt))
clientMoveTime.fold(clientLag)(mt => Some(elapsed - mt))

object MoveMetrics:
val empty = MoveMetrics()
10 changes: 5 additions & 5 deletions src/main/scala/Role.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ object Role:

def valueOf(r: Role): Option[Int] =
r match
case Pawn => Option(1)
case Knight => Option(3)
case Bishop => Option(3)
case Rook => Option(5)
case Queen => Option(9)
case Pawn => Some(1)
case Knight => Some(3)
case Bishop => Some(3)
case Rook => Some(5)
case Queen => Some(9)
case King => None

case class ByRole[A](pawn: A, knight: A, bishop: A, rook: A, queen: A, king: A):
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/Situation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ case class Situation(board: Board, color: Color):
)

private def normalMove(orig: Square, dest: Square, role: Role, capture: Boolean): Option[Move] =
val taken = if capture then Option(dest) else None
val taken = if capture then Some(dest) else None
val after =
if capture then board.taking(orig, dest, taken)
else board.move(orig, dest)
Expand All @@ -311,7 +311,7 @@ case class Situation(board: Board, color: Color):
promotion: PromotableRole,
capture: Boolean
): Option[Move] =
val taken = if capture then Option(dest) else None
val taken = if capture then Some(dest) else None
board
.promote(orig, dest, color - promotion)
.map(board =>
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/format/pgn/Binary.scala
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ object Binary:
case SimplePieceR(piece, capture, square, check) =>
simplePiece(piece, square, capture, check)
case FullPawnR(file, square, promotion, check) =>
fullPawn(Option(file), square, check, Option(promotion))
fullPawn(Some(file), square, check, Some(promotion))
case FullPieceR(piece, orig, capture, square, check) =>
fullPiece(piece, orig, square, capture, check)
case DropR(role, square, check) => drop(role, square, check)
Expand Down
8 changes: 4 additions & 4 deletions test-kit/src/test/scala/AntichessVariantTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ g4 {[%emt 0.200]} 34. Rxg4 {[%emt 0.172]} 0-1"""
val position = EpdFen("8/5P2/8/2b5/8/8/4B3/8 w - -")
val originalGame = fenToGame(position, Antichess)

val newGame = originalGame flatMap (_.apply(Square.F7, Square.F8, Option(King))) map (_._1)
val newGame = originalGame flatMap (_.apply(Square.F7, Square.F8, Some(King))) map (_._1)

newGame must beRight:
(_: Game).board(Square.F8).mustEqual(Option(White - King))
(_: Game).board(Square.F8).mustEqual(Some(White - King))

"deal with 2 white kings" in:
val position = EpdFen("K3k1nr/p2q2pp/p2p1p2/8/2PP4/8/PP4PP/RNBQK1NR w - - 0 11")
Expand Down Expand Up @@ -194,7 +194,7 @@ g4 {[%emt 0.200]} 34. Rxg4 {[%emt 0.172]} 0-1"""
val position = EpdFen("8/6p1/4B1P1/4p3/4P3/8/2p5/8 b - - 1 28")
val originalGame = fenToGame(position, Antichess)

val newGame = originalGame flatMap (_.apply(Square.C2, Square.C1, Option(Bishop))) map (_._1)
val newGame = originalGame flatMap (_.apply(Square.C2, Square.C1, Some(Bishop))) map (_._1)

newGame must beRight.like { case (drawnGame: Game) =>
drawnGame.situation.end must beTrue
Expand All @@ -206,7 +206,7 @@ g4 {[%emt 0.200]} 34. Rxg4 {[%emt 0.172]} 0-1"""
val position = EpdFen("8/6p1/1B4P1/4p3/4P3/8/3p4/8 b - -")
val originalGame = fenToGame(position, Antichess)

val newGame = originalGame flatMap (_.apply(Square.D2, Square.D1, Option(Bishop))) map (_._1)
val newGame = originalGame flatMap (_.apply(Square.D2, Square.D1, Some(Bishop))) map (_._1)

newGame must beRight.like { case nonDrawnGame =>
nonDrawnGame.situation.end must beFalse
Expand Down
6 changes: 3 additions & 3 deletions test-kit/src/test/scala/BoardTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ class BoardTest extends ChessTest:

"allow a piece to be placed" in:
board.place(White - Rook, E3) must beSome:
(_: Board)(E3) mustEqual Option(White - Rook)
(_: Board)(E3) mustEqual Some(White - Rook)

"allow a piece to be taken" in:
board take A1 must beSome:
(_: Board)(A1) must beNone

"allow a piece to move" in:
board.move(E2, E4) must beSome:
(_: Board)(E4) mustEqual Option(White - Pawn)
(_: Board)(E4) mustEqual Some(White - Pawn)

"not allow an empty position to move" in:
board.move(E5, E6) must beNone
Expand All @@ -75,7 +75,7 @@ class BoardTest extends ChessTest:
_.place(White - Pawn, A3),
_.move(A2, A4)
) must beSome:
(_: Board)(A4) mustEqual Option(White - Pawn)
(_: Board)(A4) mustEqual Some(White - Pawn)

"fail on bad actions chain" in:
makeEmptyBoard.seq(
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/ChessTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ trait ChessTest extends Specification with EitherMatchers:
): Either[ErrorStr, Game] =
game(orig, dest, promotion).map(_._1)

def withClock(c: Clock) = game.copy(clock = Option(c))
def withClock(c: Clock) = game.copy(clock = Some(c))

extension (sit: Situation)
def movesAt(s: Square): List[Move] =
Expand Down
6 changes: 3 additions & 3 deletions test-kit/src/test/scala/ClockTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class ClockTest extends ChessTest:
val clock = Clock(5 * 60 * 1000, 0)
val game = makeGame withClock clock.start
"new game" in:
game.clock map { _.color } must_== Option(White)
game.clock map { _.color } must_== Some(White)
"one move played" in:
game.playMoves(E2 -> E4) must beRight.like { case g: Game =>
g.clock map { _.color } must_== Option(Black)
g.clock map { _.color } must_== Some(Black)
}
"create a clock" should:
"with time" in:
Expand All @@ -47,7 +47,7 @@ class ClockTest extends ChessTest:
"with 30 seconds" in:
Clock(30, 0).limitInMinutes must_== 0.5
"lag compensation" should:
def durOf(lag: Int) = MoveMetrics(clientLag = Option(Centis(lag)))
def durOf(lag: Int) = MoveMetrics(clientLag = Some(Centis(lag)))

def clockStep(clock: Clock, wait: Int, lags: Int*) =
(lags.foldLeft(clock) { (clk, lag) =>
Expand Down
14 changes: 7 additions & 7 deletions test-kit/src/test/scala/PawnTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,29 @@ class PawnTest extends ChessTest:
board destsFrom D5 must bePoss(D6)
"with irrelevant history" in:
board withHistory defaultHistory(
lastMove = Option(Uci.Move(A2, A4))
lastMove = Some(Uci.Move(A2, A4))
) destsFrom D5 must bePoss(D6)
"with relevant history on the left" in:
board withHistory defaultHistory(
lastMove = Option(Uci.Move(C7, C5))
lastMove = Some(Uci.Move(C7, C5))
) destsFrom D5 must bePoss(D6, C6)
"with relevant history on the right" in:
board withHistory defaultHistory(
lastMove = Option(Uci.Move(E7, E5))
lastMove = Some(Uci.Move(E7, E5))
) destsFrom D5 must bePoss(D6, E6)
"enemy not-a-pawn" in:
makeBoard(
D5 -> White.pawn,
E5 -> Black.rook
) withHistory defaultHistory(
lastMove = Option(Uci.Move(E7, E5))
lastMove = Some(Uci.Move(E7, E5))
) destsFrom D5 must bePoss(D6)
"friend pawn (?!)" in:
makeBoard(
D5 -> White.pawn,
E5 -> White.pawn
) withHistory defaultHistory(
lastMove = Option(Uci.Move(E7, E5))
lastMove = Some(Uci.Move(E7, E5))
) destsFrom D5 must bePoss(D6)

"a black pawn" should:
Expand Down Expand Up @@ -158,12 +158,12 @@ class PawnTest extends ChessTest:
board destsFrom D4 must bePoss(D3)
"with relevant history on the left" in:
board withHistory defaultHistory(
lastMove = Option(Uci.Move(C2, C4))
lastMove = Some(Uci.Move(C2, C4))
) destsFrom D4 must bePoss(D3, C3)
"enemy not-a-pawn" in:
makeBoard(
D4 -> Black.pawn,
E4 -> White.rook
) withHistory defaultHistory(
lastMove = Option(Uci.Move(E2, E4))
lastMove = Some(Uci.Move(E2, E4))
) destsFrom D4 must bePoss(D3)
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/PromotionTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class PromotionTest extends ChessTest:
val fen = EpdFen("8/1P6/8/8/8/8/7k/1K6 w - -")
val game = fenToGame(fen, Standard).toOption.get

val failureGame = game(Square.B7, Square.B8, Option(King)).map(_._1)
val failureGame = game(Square.B7, Square.B8, Some(King)).map(_._1)

failureGame must beLeft
12 changes: 6 additions & 6 deletions test-kit/src/test/scala/RacingKingsVariantTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,37 @@ class RacingKingsVariantTest extends ChessTest:
val fenPosition = EpdFen("4krn1/K2b4/8/8/8/8/8/8 w - - 4 3")
val game = fenToGame(fenPosition, RacingKings).toOption.get
game.situation.end must beTrue
game.situation.winner mustEqual Option(Black)
game.situation.winner mustEqual Some(Black)

"game end to black 2" in:
val fenPosition = EpdFen("4brk1/8/5n2/K7/8/8/8/8 w - - 6 4")
val game = fenToGame(fenPosition, RacingKings).toOption.get
game.situation.end must beTrue
game.situation.winner mustEqual Option(Black)
game.situation.winner mustEqual Some(Black)

"game end to black 3" in:
val fenPosition = EpdFen("3kbrn1/8/8/K7/8/8/8/8 w - - 4 3")
val game = fenToGame(fenPosition, RacingKings).toOption.get
game.situation.end must beTrue
game.situation.winner mustEqual Option(Black)
game.situation.winner mustEqual Some(Black)

"game end to black 4" in:
val fenPosition = EpdFen("4brk1/4n3/8/K7/8/8/8/8 w - - 4 3")
val game = fenToGame(fenPosition, RacingKings).toOption.get
game.situation.end must beTrue
game.situation.winner mustEqual Option(Black)
game.situation.winner mustEqual Some(Black)

"game end to white" in:
val fenPosition = EpdFen("K3br2/5k2/8/8/6n1/8/8/8 w - - 4 3")
val game = fenToGame(fenPosition, RacingKings).toOption.get
game.situation.end must beTrue
game.situation.winner mustEqual Option(White)
game.situation.winner mustEqual Some(White)

"game end to white 2" in:
val fenPosition = EpdFen("K3b2r/5k2/5n2/8/8/8/8/8 w - - 4 3")
val game = fenToGame(fenPosition, RacingKings).toOption.get
game.situation.end must beTrue
game.situation.winner mustEqual Option(White)
game.situation.winner mustEqual Some(White)

"game is draw if both kings are in 8th rank" in:
val fenPosition = EpdFen("K3brk1/8/5n2/8/8/8/8/8 w - - 4 3")
Expand Down
20 changes: 10 additions & 10 deletions test-kit/src/test/scala/format/pgn/ParserTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ class ParserTest extends ChessTest:
"as a queen" in:
parse("b8=Q ") must beRight.like: parsed =>
parsed.mainline.headOption must beSome { (san: San) =>
san === Std(Square.B8, Pawn, promotion = Option(Queen))
san === Std(Square.B8, Pawn, promotion = Some(Queen))
}

"as a rook" in:
parse("b8=R ") must beRight { (parsed: ParsedPgn) =>
parsed.mainline.headOption must beSome { (san: San) =>
san.asInstanceOf[Std].promotion must_== Option(Rook)
san.asInstanceOf[Std].promotion must_== Some(Rook)
}
}

Expand Down Expand Up @@ -97,7 +97,7 @@ class ParserTest extends ChessTest:
"glyphs" in:

parseMove("b8=B ") must beRight.like: node =>
node.value.san === Std(Square.B8, Pawn, promotion = Option(Bishop))
node.value.san === Std(Square.B8, Pawn, promotion = Some(Bishop))

parseMove("1. e4") must beRight.like: node =>
node.value.san must_== Std(Square.E4, Pawn)
Expand All @@ -121,15 +121,15 @@ class ParserTest extends ChessTest:
parse(withNag) must beRight

parse("Ne7g6+! $13") must beRight.like: parsed =>
parsed.metas.glyphs.move must_== Option(Glyph.MoveAssessment.good)
parsed.metas.glyphs.position must_== Option(Glyph.PositionAssessment.unclear)
parsed.metas.glyphs.move must_== Some(Glyph.MoveAssessment.good)
parsed.metas.glyphs.position must_== Some(Glyph.PositionAssessment.unclear)

"non-nags" in:
parse(withGlyphAnnotations) must beRight

parse("Bxd3?? ∞") must beRight.like { parsed =>
parsed.tree.firstMove.metas.glyphs.move must_== Option(Glyph.MoveAssessment.blunder)
parsed.tree.firstMove.metas.glyphs.position must_== Option(Glyph.PositionAssessment.unclear)
parsed.tree.firstMove.metas.glyphs.move must_== Some(Glyph.MoveAssessment.blunder)
parsed.tree.firstMove.metas.glyphs.position must_== Some(Glyph.PositionAssessment.unclear)
}

"comments" in:
Expand Down Expand Up @@ -347,16 +347,16 @@ class ParserTest extends ChessTest:
"year" in:
"full date" in:
parse(recentChessCom) must beRight.like { parsed =>
parsed.tags.year must_== Option(2016)
parsed.tags.year must_== Some(2016)
}
"only year" in:
parse(explorerPartialDate) must beRight.like { parsed =>
parsed.tags.year must_== Option(1978)
parsed.tags.year must_== Some(1978)
}

"weird variant names" in:
parse(stLouisFischerandom) must beRight.like { parsed =>
parsed.tags.variant must_== Option(variant.Chess960)
parsed.tags.variant must_== Some(variant.Chess960)
}

"example from chessgames.com with weird comments" in:
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/format/pgn/ReaderTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ReaderTest extends ChessTest:
"promoting to a rook" in:
Reader.full(fromLichessBadPromotion) must beRight.like { case Complete(replay) =>
replay.chronoMoves lift 10 must beSome:
(_: MoveOrDrop).fold(_.promotion, _ => None) must_== Option(Rook)
(_: MoveOrDrop).fold(_.promotion, _ => None) must_== Some(Rook)
}
"chessbase arrows" in:
Reader.full(chessbaseArrows) must beRight
Expand Down
Loading
Loading