Skip to content

Commit

Permalink
Add Promotable Role & Crazyhouse.Data arbitrary
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh committed Oct 9, 2024
1 parent 45d55d7 commit ebc6623
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion test-kit/src/main/scala/chess/CoreArbitraries.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package chess
import chess.bitboard.Bitboard
import chess.format.pgn.{ Glyph, Glyphs }
import chess.format.{ Uci, UciCharPair }
import chess.variant.Variant
import chess.variant.{ Crazyhouse, Variant }
import org.scalacheck.{ Arbitrary, Cogen, Gen }

object CoreArbitraries:
Expand All @@ -28,6 +28,8 @@ object CoreArbitraries:
given Arbitrary[Castles] = Arbitrary(castlesGen)
given Arbitrary[Bitboard] = Arbitrary(Gen.long.map(Bitboard(_)))

given Arbitrary[PromotableRole] = Arbitrary(Gen.oneOf(Rook, Knight, Bishop, Queen))

given Arbitrary[Uci] = Arbitrary(Gen.oneOf(normalUciMoveGen, promotionUciMoveGen, dropUciMoveGen))

given Cogen[Color] = Cogen.cogenBoolean.contramap(_.white)
Expand All @@ -40,6 +42,21 @@ object CoreArbitraries:
b <- Arbitrary.arbitrary[A]
yield ByColor(w, b)

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[Bitboard]
yield Crazyhouse.Data(pockets, promoted)

def normalUciMoveGen =
for
orig <- Arbitrary.arbitrary[Square]
Expand Down

0 comments on commit ebc6623

Please sign in to comment.