Skip to content
Merged
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
4 changes: 4 additions & 0 deletions shared/src/main/scala/com/mogproject/mogami/core/State.scala
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ case class State(turn: Player = BLACK, board: BoardType = Map.empty, hand: HandT
case None => List()
}

/**
* Check if the in-hand piece is non-empty.
*/
def hasHand(h: Hand): Boolean = hand.get(h).exists(_ > 0)
}

object State extends CsaStateReader with SfenStateReader {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,4 +882,11 @@ class StateSpec extends FlatSpec with MustMatchers with GeneratorDrivenPropertyC
|P-00HI00KA00KI00GI00KE00KY00FU
|-""".stripMargin).get.isMated mustBe false
}

"State#hasHand" must "return if the in-hand piece exists" in {
State.HIRATE.hasHand(Hand(BP)) mustBe false
State.empty.updateHandPiece(BP, 1).get.hasHand(Hand(BP)) mustBe true
State.empty.updateHandPiece(BP, 2).get.hasHand(Hand(BP)) mustBe true
State.empty.updateHandPiece(BP, 18).get.hasHand(Hand(BP)) mustBe true
}
}