Skip to content

Commit

Permalink
Allow multi-digit held pieces in SFEN
Browse files Browse the repository at this point in the history
  • Loading branch information
TollyH committed Feb 23, 2023
1 parent 9e8aac3 commit f80a8e8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion ShogiGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ public static ShogiGame FromShogiForsythEdwards(string forsythEdwards)
};

int numberToAdd = 1;
bool numberChanged = false;
foreach (char pieceChar in fields[2])
{
switch (pieceChar)
Expand Down Expand Up @@ -912,7 +913,17 @@ public static ShogiGame FromShogiForsythEdwards(string forsythEdwards)
if (pieceChar is > '0' and <= '9')
{
// char - '0' gets numeric value of ASCII number
numberToAdd = pieceChar - '0';
int charValue = pieceChar - '0';
if (!numberChanged)
{
numberToAdd = charValue;
numberChanged = true;
}
else
{
numberToAdd *= 10;
numberToAdd += charValue;
}
continue;
}
else
Expand All @@ -921,6 +932,7 @@ public static ShogiGame FromShogiForsythEdwards(string forsythEdwards)
}
}
numberToAdd = 1;
numberChanged = false;
}

// Shogi Forsyth–Edwards doesn't define what the previous moves were, so they moves list starts empty
Expand Down

0 comments on commit f80a8e8

Please sign in to comment.