@@ -13,21 +13,24 @@ import strategygames.go.variant.Variant
13
13
object Forsyth {
14
14
15
15
val initial = FEN (
16
- " 19/19/19/19/19/19/19/19/19/19/19/19/19/19/19/19/19/19/19[SSSSSSSSSSssssssssss] b - 0 75 0 0 75 1"
16
+ " 19/19/19/19/19/19/19/19/19/19/19/19/19/19/19/19/19/19/19[SSSSSSSSSSssssssssss] b - 0 75 0 0 75 0 1"
17
17
)
18
18
19
19
def <<@ (variant : Variant , fen : FEN ): Option [Situation ] = {
20
20
val apiPosition = Api .positionFromVariantNameAndFEN(variant.key, fen.value)
21
- val fenParts = fen.value.split(' ' ).toList
22
- val p1Captures = fenParts.lift(5 ).flatMap(_.toIntOption).getOrElse(0 )
23
- val p2Captures = fenParts.lift(6 ).flatMap(_.toIntOption).getOrElse(1 )
24
21
Some (
25
22
Situation (
26
23
Board (
27
24
pieces = apiPosition.pieceMap,
28
- history = History ().copy( captures= Score (p1Captures, p2Captures )),
25
+ history = History (captures = Score (fen.player1Captures, fen.player2Captures )),
29
26
variant = variant,
30
27
pocketData = apiPosition.pocketData,
28
+ uciMoves = fen.fenPassCount match {
29
+ case 0 => List ()
30
+ case 1 => List (" pass" )
31
+ case 2 => List (" pass" , " pass" )
32
+ case 3 => List (" ss:" )
33
+ },
31
34
position = apiPosition.some
32
35
),
33
36
fen.value.split(' ' )(1 ) match {
@@ -52,7 +55,6 @@ object Forsyth {
52
55
def <<<@ (variant : Variant , fen : FEN ): Option [SituationPlus ] =
53
56
<<@ (variant, fen) map { sit =>
54
57
SituationPlus (
55
- // not doing half move clock history like we do in chess
56
58
sit,
57
59
fen.value.split(' ' ).last.toIntOption.map(_ max 1 min 500 ) | 1
58
60
)
@@ -77,8 +79,41 @@ object Forsyth {
77
79
FEN (
78
80
board.apiPosition.fen.value
79
81
.split(" " )
82
+ // Update player if we have a last action of select squares that the API doesnt know about
83
+ .updated(
84
+ 1 ,
85
+ board.history.lastTurn.headOption match {
86
+ case Some (_ : Uci .SelectSquares ) if board.apiPosition.turn == " w" => " b"
87
+ case Some (_ : Uci .SelectSquares ) if board.apiPosition.turn == " b" => " w"
88
+ case _ => board.apiPosition.turn
89
+ }
90
+ )
91
+ // Update captures
80
92
.updated(5 , board.history.captures.p1.toString)
81
93
.updated(6 , board.history.captures.p2.toString)
94
+ // Update current consecutive Pass count. Use 3 to represent end of game
95
+ .updated(
96
+ 8 ,
97
+ (board.uciMoves.reverse.headOption match {
98
+ case Some (uci) if uci.startsWith(" ss:" ) => 3
99
+ case Some (uci) if uci == " pass" => {
100
+ board.uciMoves.reverse.drop(1 ).headOption match {
101
+ case Some (uci) if uci == " pass" => 2
102
+ case _ => 1
103
+ }
104
+ }
105
+ case _ => 0
106
+ }).toString
107
+ )
108
+ // Update fullTurnCount if we have a last action of select squares that the API doesnt know about
109
+ .updated(
110
+ 9 ,
111
+ board.history.lastTurn.headOption match {
112
+ case Some (_ : Uci .SelectSquares ) if board.apiPosition.turn == " w" =>
113
+ board.apiPosition.fen.value.split(" " )(9 ) + 1
114
+ case _ => board.apiPosition.fen.value.split(" " )(9 )
115
+ }
116
+ )
82
117
.mkString(" " )
83
118
)
84
119
0 commit comments