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 @@ -5,6 +5,7 @@ import com.mogproject.mogami.core.io.RecordFormatException
import com.mogproject.mogami.core.move.{Move, MoveBuilderSfen, SpecialMove}
import com.mogproject.mogami.core.state.{State, StateCache}
import com.mogproject.mogami.core.state.StateHash.StateHash
import com.mogproject.mogami.util.Implicits._

import scala.util.{Failure, Success, Try}

Expand Down Expand Up @@ -102,7 +103,10 @@ trait SfenBranchWriter extends SfenLike {
*/
override def toSfenString: String = (offset.toString +: moves.map(_.toSfenString).toList).mkString(" ")

def toSfenExtendedBranch: SfenExtendedBranch = SfenExtendedBranch(toSfenString, finalAction.map(_.toSfenExtendedString), comments)
def toSfenExtendedBranch(addInitialState: Boolean = false): SfenExtendedBranch = {
val mv = addInitialState.fold(initialState.toSfenString + " ", "") + toSfenString
SfenExtendedBranch(mv, finalAction.map(_.toSfenExtendedString), comments)
}
}

trait SfenGameWriter extends SfenLike {
Expand All @@ -117,5 +121,5 @@ trait SfenGameWriter extends SfenLike {
*/
override def toSfenString: String = trunk.initialState.toSfenString + " " + trunk.toSfenString

def toSfenExtendedGame: SfenExtendedGame = SfenExtendedGame(trunk.toSfenExtendedBranch, branches.map(_.toSfenExtendedBranch))
def toSfenExtendedGame: SfenExtendedGame = SfenExtendedGame(trunk.toSfenExtendedBranch(true), branches.map(_.toSfenExtendedBranch(false)))
}
4 changes: 2 additions & 2 deletions shared/src/main/scala/com/mogproject/mogami/package.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.mogproject

import com.mogproject.mogami.core.move.Resign

package object mogami {

type Player = com.mogproject.mogami.core.Player
Expand Down Expand Up @@ -84,6 +82,8 @@ package object mogami {
type Branch = com.mogproject.mogami.core.game.Branch
val Branch = com.mogproject.mogami.core.game.Branch

type BranchNo = com.mogproject.mogami.core.game.Game.BranchNo

type GamePosition = com.mogproject.mogami.core.game.Game.GamePosition
val GamePosition = com.mogproject.mogami.core.game.Game.GamePosition

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.mogproject.mogami.core.io.sfen
import com.mogproject.mogami.core.Player.BLACK
import com.mogproject.mogami.core.Ptype.KING
import com.mogproject.mogami.core.Square
import com.mogproject.mogami.core.game.{Game, GameGen}
import com.mogproject.mogami.core.move.{IllegalMove, Move, Resign}
import com.mogproject.mogami.core.state.StateCache.Implicits._
import org.scalatest.prop.GeneratorDrivenPropertyChecks
Expand Down Expand Up @@ -62,5 +63,9 @@ class SfenGameIOSpec extends FlatSpec with MustMatchers with GeneratorDrivenProp
g2.branches(1).comments mustBe Map(2 -> "v2", 3 -> "v3")
g2.branches(2).finalAction mustBe Some(IllegalMove(Move(BLACK, Some(Square(76)), Square(4), KING, false, false, None, None, false, None, false)))
}
it must "restore games" in forAll(GameGen.games, minSuccessful(10)) { g =>
val s = g.toSfenExtendedGame
Game.parseSfenExtendedGame(s).toSfenExtendedGame mustBe s
}

}