private void AddPieces(PlayerPieceSet pieces, Players player) { Debug.Assert(pieces != null); AddPiece(player, Exports.Pieces.King, pieces.KingsCell); for (uint i = 0, e = pieces.QueensCount; i < e; ++i) { AddPiece(player, Exports.Pieces.Queen, pieces.GetQueenCell(i)); } for (uint i = 0, e = pieces.RooksCount; i < e; ++i) { AddPiece(player, Exports.Pieces.Rook, pieces.GetRookCell(i)); } for (uint i = 0, e = pieces.BishopsCount; i < e; ++i) { AddPiece(player, Exports.Pieces.Bishop, pieces.GetBishopCell(i)); } for (uint i = 0, e = pieces.KnightsCount; i < e; ++i) { AddPiece(player, Exports.Pieces.Knight, pieces.GetKnightCell(i)); } for (uint i = 0, e = pieces.PawnsCount; i < e; ++i) { AddPiece(player, Exports.Pieces.Pawn, pieces.GetPawnCell(i)); } }
private static void MakeKnightMoves(PlayerPieceSet my_pieces, PlayerPieceSet other_pieces, List<Move> moves) { for (uint i = 0, e = my_pieces.KnightsCount; i < e; ++i) { uint cell_index; var knight_cell = new ChessboardCell(my_pieces.GetKnightCell(i, out cell_index)); if (knight_cell.Row - 2 >= Chessboard.ROW_MIN && knight_cell.Row + 2 <= Chessboard.ROW_MAX && knight_cell.Column - 2 >= Chessboard.COLUMN_MIN && knight_cell.Column + 2 <= Chessboard.COLUMN_MAX) { // In this case we do not need to check that new cells are within // the chessboard foreach (var move_delta in m_knight_moves) { var new_cell = ChessboardCell.CalculateValue( knight_cell.Row + move_delta.m_delta_row, knight_cell.Column + move_delta.m_delta_column); if (!my_pieces.IsOccupiedCell(new_cell)) { bool is_capture = other_pieces.IsOccupiedCell(new_cell); moves.Add(new Move(Exports.Pieces.Knight, knight_cell.Value, new_cell, cell_index, is_capture ? Move.Flags.Capture : 0)); } } } else { // Do range check for every new cell foreach (var move_delta in m_knight_moves) { int new_row = knight_cell.Row + move_delta.m_delta_row; if (new_row < Chessboard.ROW_MIN || new_row > Chessboard.ROW_MAX) { continue; } int new_column = knight_cell.Column + move_delta.m_delta_column; if (new_column < Chessboard.COLUMN_MIN || new_column > Chessboard.COLUMN_MAX) { continue; } var new_cell = ChessboardCell.CalculateValue(new_row, new_column); if (!my_pieces.IsOccupiedCell(new_cell)) { bool is_capture = other_pieces.IsOccupiedCell(new_cell); moves.Add(new Move(Exports.Pieces.Knight, knight_cell.Value, new_cell, cell_index, is_capture ? Move.Flags.Capture : 0)); } } } } }