diff --git a/modules/game/src/test/Arbitraries.scala b/modules/game/src/test/Arbitraries.scala index 0d1b68f56887..d95bd78adb66 100644 --- a/modules/game/src/test/Arbitraries.scala +++ b/modules/game/src/test/Arbitraries.scala @@ -1,7 +1,7 @@ package lila.game import chess.* -import chess.CoreArbitraries.given +import chess.CoreArbitraries.{ castleGen, given } import org.scalacheck.{ Arbitrary, Gen } import play.api.libs.json.JsObject import chess.variant.Crazyhouse @@ -12,21 +12,16 @@ object Arbitraries: given [S, T](using SameRuntime[S, T], Arbitrary[S]): Arbitrary[T] = Arbitrary: Arbitrary.arbitrary[S].map(summon[SameRuntime[S, T]].apply) - // TODO move Move.Castle to scalachess given Arbitrary[Event.Castling] = Arbitrary: for color <- Arbitrary.arbitrary[Color] - king <- Gen.oneOf(color.backRank.squares) - kingTo <- Gen.oneOf(color.fold(List(Square.G1, Square.C1), List(Square.G8, Square.C8))) - rookTo <- Gen.oneOf(color.fold(List(Square.F1, Square.D1), List(Square.F8, Square.D8))) - rook <- Gen.oneOf(color.backRank.squares.filter(_ != king)) - castle = Move.Castle(king, kingTo, rook, rookTo) + castle <- castleGen(color) yield Event.Castling(castle, color) given Arbitrary[Event.Enpassant] = Arbitrary: for color <- Arbitrary.arbitrary[Color] - pos <- Gen.oneOf(color.passablePawnRank.squares) + pos <- Gen.oneOf(color.passablePawnRank.bb.squares) yield Event.Enpassant(pos, color) // We use Event.Castling as a cookie for this test because We don't have an Arbitrary instance for JsObject yet @@ -48,8 +43,6 @@ object Arbitraries: blackOffersDraw <- Arbitrary.arbitrary[Boolean] yield Event.State(turns, status, winner, whiteOffersDraw, blackOffersDraw) - given Arbitrary[PromotableRole] = Arbitrary(Gen.oneOf(Rook, Knight, Bishop, Queen)) - given Arbitrary[Event.Promotion] = Arbitrary: for role <- Arbitrary.arbitrary[PromotableRole] @@ -63,21 +56,6 @@ object Arbitraries: nextLag <- Arbitrary.arbitrary[Option[Centis]] yield Event.Clock(whiteTime, blackTime, nextLag) - given Arbitrary[Crazyhouse.Pocket] = Arbitrary: - for - pawn <- Gen.oneOf(0 to 8) - knight <- Gen.oneOf(0 to 2) - bishop <- Gen.oneOf(0 to 2) - rook <- Gen.oneOf(0 to 2) - queen <- Gen.oneOf(0 to 2) - yield Crazyhouse.Pocket(pawn, knight, bishop, rook, queen) - - given Arbitrary[Crazyhouse.Data] = Arbitrary: - for - pockets <- Arbitrary.arbitrary[ByColor[Crazyhouse.Pocket]] - promoted <- Arbitrary.arbitrary[chess.bitboard.Bitboard] - yield Crazyhouse.Data(pockets, promoted) - given Arbitrary[Event.Move] = Arbitrary: for orig <- Arbitrary.arbitrary[Square] @@ -110,5 +88,3 @@ object Arbitraries: possibleDrops, crazyData ) - - extension (rank: Rank) def squares: List[Square] = Square.all.filter(_.rank == rank)