private static ResultBoards GetPossibleBoards(ChessPieceColor movingSide, Board examineBoard) { //We are going to store our result boards here resultBoards = new ResultBoards { Positions = new List <Board>() }; for (byte x = 0; x < 64; x++) { Square sqr = examineBoard.Squares[x]; //Make sure there is a piece on the square if (sqr.Piece == null) { continue; } //Make sure the color is the same color as the one we are moving. if (sqr.Piece.PieceColor != movingSide) { continue; } //For each valid move for this piece foreach (byte dst in sqr.Piece.ValidMoves) { //We make copies of the board and move so that we can move it without effecting the parent board Board board = examineBoard.FastBoardCopy(); //Make move so we can examine it board.MovePiece(x, dst, ChessPieceType.Queen); //We Generate Valid Moves for Board board.GenerateValidMoves(); if (board.BlackCheck && movingSide == ChessPieceColor.Black) { continue; } if (board.WhiteCheck && movingSide == ChessPieceColor.White) { continue; } //We calculate the board score board.EvaluateBoardScore(); //Invert Score to support Negamax board.Score = SideToMoveScore(board.Score, GetOppositeColor(movingSide)); resultBoards.Positions.Add(board); } } return(resultBoards); }