SebLague/Chess-Coding-Adventure

board.GetAllPieceLists() returns a None-PieceTyp for the last moved

haase-laurenz opened this issue · 0 comments

double EvaluatePosition(Board board){

        double score = 0;
  
        Dictionary<PieceType, double> pieceValues = new Dictionary<PieceType, double>
        {
            { PieceType.None, 0 },
            { PieceType.Pawn, 1 },
            { PieceType.Knight, 3 },
            { PieceType.Bishop, 3 },
            { PieceType.Rook, 5 },
            { PieceType.Queen, 9 },
            { PieceType.King, 0 }
        };

        Console.WriteLine(board.GetFenString());
        PieceList[] allPieceLists = board.GetAllPieceLists();

        foreach (PieceList pieceList in allPieceLists)
        {
            foreach (Piece piece in pieceList)
            {   
                Console.WriteLine("WHITE?: "+piece.IsWhite+" "+piece.PieceType);
                double pieceValue = pieceValues[piece.PieceType]; 

                if (piece.IsWhite)
                {
                   
                    score += pieceValue;
                }
                else
                {
               
                    score -= pieceValue;
                }
            }
        }
        
        return score;
        

    } 

For the beginning I wrote this little Eval Script, simply counting the Piece Values for White and Black. I was already wondering why there was a Null Exception, so I added the PieceTyp.None in my Dict. After some fast tests and printing, I found out that the last moving Piece was from Type Null. The FEN String for the Board is correct. Can anyone help with this issue? Thanks a lot!