FEN加载器转换为位置并生成数字。

huangapple go评论90阅读模式
英文:

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&lt;char, int&gt;()
        {
            [&#39;K&#39;] = Piecies.White.King,
            [&#39;k&#39;] = Piecies.Black.King,
            [&#39;P&#39;] = Piecies.White.Pawn,
            [&#39;p&#39;] = Piecies.Black.Pawn,
            [&#39;N&#39;] = Piecies.White.Knight,
            [&#39;n&#39;] = Piecies.Black.Knight,
            [&#39;B&#39;] = Piecies.White.Bishop,
            [&#39;b&#39;] = Piecies.White.Bishop,
            [&#39;R&#39;] = Piecies.White.Rook,
            [&#39;r&#39;] = Piecies.Black.Rook,
            [&#39;Q&#39;] = Piecies.White.Queen,
            [&#39;q&#39;] = Piecies.Black.Queen
        };
        string fenBoard = fen.Split(&#39; &#39;)[0];
        int rank = 0, file = 0;

        foreach (char symbol in fenBoard)
        {
            if (symbol == &#39;/&#39;) {
                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

huangapple
  • 本文由 发表于 2023年7月3日 20:47:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76604886.html
  • fen
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定