So i tried to build a FEN loader that create a "Chess Board" in a array Square[8,8].
This is the code so far
public static void LoadPositionFromFen(string fen)
{
var PieceTypeFromSymbol = new Dictionary<char, int>()
{
['K'] = Piecies.White.King,
['k'] = Piecies.Black.King,
['P'] = Piecies.White.Pawn,
['p'] = Piecies.Black.Pawn,
['N'] = Piecies.White.Knight,
['n'] = Piecies.Black.Knight,
['B'] = Piecies.White.Bishop,
['b'] = Piecies.White.Bishop,
['R'] = Piecies.White.Rook,
['r'] = Piecies.Black.Rook,
['Q'] = Piecies.White.Queen,
['q'] = Piecies.Black.Queen
};
string fenBoard = fen.Split(' ')[0];
int rank = 0, file = 0;
foreach (char symbol in fenBoard)
{
if (symbol == '/') {
rank = 0;
file++;
} else
{
if (char.IsDigit(symbol))
{
rank += (int) char.GetNumericValue(symbol);
}
else
{
var piece = PieceTypeFromSymbol[symbol];
Square[rank, file] = piece;
rank++;
}
}
}
}`
But then i try to look some of the piecies And i get this:
15 12 0 0 0 0 2 5
This is the value of every piece:
public class White
{
public const byte None = 0;
public const byte King = 1;
public const byte Pawn = 2;
public const byte Knight = 3;
public const byte Bishop = 4;
public const byte Rook = 5;
public const byte Queen = 6;
}
public class Black
{
public const byte None = 10;
public const byte King = 11;
public const byte Pawn = 12;
public const byte Knight = 13;
public const byte Bishop = 14;
public const byte Rook = 15;
public const byte Queen = 16;
}
The numbers are completely off, as i checked for the squares, 0,0 0,1 0,2 0,3 0,4 0,5 06, 0,7
In the dictionary White and Black Bishops are inverted.
File needs to be 7. (file = 7) and get decremented each '/' (file--)
And i was checking putting first the file and then the rank but i place piecies by Square[rank,file]
= piece