英文:
FEN Loader to Position giving off numbers
问题
这是目前的代码:
public static void LoadPositionFromFen(string fen)
{
var PieceTypeFromSymbol = new Dictionary<char, int>()
{
['K'] = Pieces.White.King,
['k'] = Pieces.Black.King,
['P'] = Pieces.White.Pawn,
['p'] = Pieces.Black.Pawn,
['N'] = Pieces.White.Knight,
['n'] = Pieces.Black.Knight,
['B'] = Pieces.White.Bishop,
['b'] = Pieces.Black.Bishop,
['R'] = Pieces.White.Rook,
['r'] = Pieces.Black.Rook,
['Q'] = Pieces.White.Queen,
['q'] = Pieces.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++;
}
}
}
}
这是每个棋子的值:
public class Pieces
{
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;
}
}
你提到的数字看起来不正确,但没有提供足够的上下文来解释为什么数字不正确。如果需要更多帮助,请提供更多信息。
英文:
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
答案1
得分: 0
在字典中,白色和黑色的主教被颠倒了。
文件需要是7。(文件=7),每个'/'都会减少一个文件(文件--)
我先检查文件,然后检查等级,但我是通过Square[rank,file]
= piece来放置棋子的。
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论