public static Board BoardFromPositionID(string position_id, ref string error)
{
Board board = new Board();
error = "";
if (position_id.Length != 14)
{
if (position_id.Length < 12)
error = "Position ID length too short.";
else
error = "Position ID length too long.";
return null;
}
List<bool> bits2 = new List<bool>();
List<bool> bits = new List<bool>();
foreach (char c in position_id)
{
if (!base64.Contains(c))
{
error = "Position ID contains an invalid character.";
return null;
}
int dec = base64.IndexOf(c);
for (int i = 5; i >= 0; i--)
{
bits.Add((powers2[i] & dec) == powers2[i]);
//bool bit = (powers2[i] & dec) == powers2[i];
//Console.Write(bit?1:0);
if (bits.Count == 8)
{
bits.Reverse();
bits2.AddRange(bits);
bits.Clear();
}
}
}
int total_chequers = 0;
int slot = 0;
int player = 0;
foreach (bool bit in bits2)
{
if (bit)
{
if (slot == 24)
board.IncreaseCaptured(player);
else
board.AddToPoint(player, slot, 1);
total_chequers++;
}
else
{
slot++;
}
if (slot == 25)
{
board.SetFinished(player, 15 - total_chequers);
player = 1 - player;
total_chequers = 0;
slot = 0;
}
}
//Console.WriteLine(board.ToString(0));
return board;
}