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
1 change: 1 addition & 0 deletions jvm/src/test/resources/ki2/game/003.ki2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
▲7六歩△8四歩▲5六歩△3四歩▲5五歩△6二銀▲5八飛△5二金右▲4八玉△4二玉▲3八玉△3二玉▲6八銀△5四歩▲5七銀△5五歩▲4六銀△8五歩▲7七角△4二銀▲5五銀△5三銀右▲5四歩△4四銀▲同銀△同歩▲5三銀△4三金▲4二銀成△同金直▲5三銀△5二歩▲4二銀成△同玉
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,6 @@ class JVMGameSpec extends FlatSpec with MustMatchers with GeneratorDrivenPropert
"Game#parseKi2String" must "create games from files" in StateCache.withCache { implicit cache =>
Game.parseKi2String(loadFile("ki2/game/001.ki2")).trunk.moves.length mustBe 111
Game.parseKi2String(loadFile("ki2/game/002.ki2")).trunk.moves.length mustBe 111
Game.parseKi2String(loadFile("ki2/game/003.ki2")).trunk.moves.length mustBe 34
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,16 @@ trait KifGameReader extends KifBranchReader with KifGameIO with KifGameFactory[G
}

protected[io] def splitMovesKi2(lines: Lines): Lines = lines.flatMap {
case (x, n) if isNormalMoveKi2(x) => x.split(" ").filter(_.nonEmpty).map((_, n))
case (x, n) if isNormalMoveKi2(x) => x.replaceAll("▲", " ▲").replaceAll("△", " △").split(" ").filter(_.nonEmpty).map((_, n))
case _ => Seq.empty
}

private[this] def sectionSplitterCommon(nel: NonEmptyLines, isHeader: String => Boolean): (Lines, NonEmptyLines, Lines) = {
val (header, body) = nel.lines.span { case (x, _) => isHeader(x) }
val (st, gi) = header.partition(ln => isInitialState(ln._1))

if (st.isEmpty) throw new RecordFormatException(header.lastOption.map(_._2).getOrElse(0), "initial state must be defined")
(gi, NonEmptyLines(st), body)
/** @note allows no initial state line (complement with HIRATE) */
(gi, NonEmptyLines(st.isEmpty.fold(Seq(("手合割:平手", 0)), st)), body)
}

private[this] def sectionSplitterKif(nel: NonEmptyLines): (Lines, NonEmptyLines, Lines, Option[Line]) = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ case class MoveBuilderKi2(player: Player,
case Some(Dropped) => Some(None)
case Some(mvmt) =>
state.attackBBOnBoard(player).find { case (sq, bb) =>
state.board(sq).ptype == oldPtype && bb.get(moveTo) && getMovement(state, Some(sq), moveTo, oldPtype).contains(mvmt)
state.board(sq).ptype == oldPtype && bb.get(moveTo) && getMovement(state, Some(sq), moveTo, oldPtype).exists(compareMovement(_, mvmt))
}.map { case (sq, _) => Some(sq) }
}

private[this] def compareMovement(a: Movement, b: Movement): Boolean = {
/** @note allows ambiguity between Upward and Vertical */
a == b || a == Movement.Upward && b == Movement.Vertical
}

override def toMove(state: State, lastMoveTo: Option[Square] = None, isStrict: Boolean): Option[Move] = for {
moveTo <- to match {
case Some(t) => Some(t)
Expand Down