示例#1
0
        public IEnumerable <IGameMove> GetPossibleMoves()
        {
            // printHistory();
            if (promotion)
            {
                return(GetPromotionMoves());
            }
            List <BoardPosition> positions = GetPlayerPieces(CurrentPlayer);
            List <ChessMove>     possible  = new List <ChessMove>();

            foreach (BoardPosition position in positions)
            {
                ChessPiecePosition cpos = GetPieceAtPosition(position);
                if (cpos.PieceType == ChessPieceType.Pawn)
                {
                    List <ChessMove> temp = PawnPossible(position);                   //convertMoveList(position, PawnPossible(position));
                    possible.AddRange(temp);
                }
                else if (cpos.PieceType == ChessPieceType.Knight)
                {
                    possible.AddRange(KnightPossible(position));                    //convertMoveList(position, KnightPossible(position)));
                }
                else if (cpos.PieceType == ChessPieceType.Bishop)
                {
                    possible.AddRange(BishopPossible(position));                    //convertMoveList(position, BishopPossible(position)));
                }
                else if (cpos.PieceType == ChessPieceType.RookKing ||
                         cpos.PieceType == ChessPieceType.RookPawn ||
                         cpos.PieceType == ChessPieceType.RookQueen)
                {
                    possible.AddRange(RookPossible(position));                    //convertMoveList(position, RookPossible(position)));
                }
                else if (cpos.PieceType == ChessPieceType.Queen)
                {
                    possible.AddRange(QueenPossible(position));                    //convertMoveList(position, QueenPossible(position)));
                }
                else
                {
                    possible.AddRange(KingPossible(position));                    //convertMoveList(position, KingPossible(position)));
                }
            }
            //Console.WriteLine($"board preval is {Value}");
            possible = EndangerKing(possible, findKing(CurrentPlayer));
            //Console.WriteLine($"Board postvalue {Value}");
            return(possible);
        }
示例#2
0
        /// <summary>
        /// Gets a sequence of all positions on the board that are threatened by the given player. A king
        /// may not move to a square threatened by the opponent.
        /// </summary>
        public IEnumerable <BoardPosition> GetThreatenedPositions(int byPlayer)
        {
            // TODO: implement this method. Make sure to account for "special" moves.
            List <BoardPosition> positions  = GetPlayerPieces(byPlayer);
            List <ChessMove>     threatened = new List <ChessMove>();

            foreach (BoardPosition position in positions)
            {
                ChessPiecePosition cpos = GetPieceAtPosition(position);
                if (cpos.PieceType == ChessPieceType.Pawn)
                {
                    threatened.AddRange(PawnThreat(position));
                }
                else if (cpos.PieceType == ChessPieceType.Knight)
                {
                    threatened.AddRange(KnightThreat(position));
                }
                else if (cpos.PieceType == ChessPieceType.Bishop)
                {
                    threatened.AddRange(BishopThreat(position));
                }
                else if (cpos.PieceType == ChessPieceType.RookKing ||
                         cpos.PieceType == ChessPieceType.RookPawn ||
                         cpos.PieceType == ChessPieceType.RookQueen)
                {
                    threatened.AddRange(RookThreat(position));
                }
                else if (cpos.PieceType == ChessPieceType.Queen)
                {
                    threatened.AddRange(QueenThreat(position));
                }
                else
                {
                    threatened.AddRange(KingThreat(position));
                }
            }
            return(convertMoveList(threatened, byPlayer));
        }
示例#3
0
 /// <summary>
 /// Manually places the given piece at the given position.
 /// </summary>
 // This is used in the constructor
 private void SetPosition(BoardPosition position, ChessPiecePosition piece)
 {
     mBoard[position.Row, position.Col] = (sbyte)((int)piece.PieceType * (piece.Player == 2 ? -1 :
                                                                          piece.Player));
 }