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
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ case class Branch(initialHash: StateHash,

def clearComment(pos: Int): Branch = updateComments(comments - pos)

def getState(pos: Int): Option[State] = history.isDefinedAt(pos - offset).option(stateCache.get(history(pos - offset))).flatten

/**
* history of state hashes
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ case class Game(trunk: Branch = Branch(),
getBranch(branchNo).map { br => trunk.moves.take(br.offset - trunk.offset) ++ br.moves }.getOrElse(Vector.empty)
}

def getState(gamePosition: GamePosition): Option[State] = withBranch(gamePosition.branch)(_.getState(gamePosition.position)).flatten

def hasComment(gamePosition: GamePosition): Boolean = if (gamePosition.isTrunk) {
trunk.hasComment(gamePosition.position)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,6 @@ class GameSpec extends FlatSpec with MustMatchers with GeneratorDrivenPropertyCh
Game().truncated(GamePosition(0, 1)) mustBe Game()
Game().truncated(GamePosition(1, 0)) mustBe Game()


val s1 = SfenExtendedGame(
SfenExtendedBranch(
"lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 0 2g2f 5a4b 2f2e",
Expand Down Expand Up @@ -813,4 +812,10 @@ class GameSpec extends FlatSpec with MustMatchers with GeneratorDrivenPropertyCh
g1.truncated(GamePosition(0, 1)).branches.length mustBe 1
g1.truncated(GamePosition(0, 0)).branches.length mustBe 1
}

"Game#getState" must "return state" in {
Game().getState(GamePosition(0, 0)) mustBe Some(HIRATE)
Game().getState(GamePosition(0, 1)) mustBe None
Game().getState(GamePosition(1, 0)) mustBe None
}
}