Пример #1
0
        public IEnumerable <BoardPosition> RookMoves(BoardPosition p)
        {
            List <BoardPosition> positions = new List <BoardPosition>();
            //Translate (ex 1 up 1 right) until inbounds == false and flip directions from starting positions until youve gone all 4 ways
            BoardPosition temp = p;

            //up
            while (ChessBoard.PositionInBounds(temp.Translate(1, 0)) == true)
            {
                positions.Add(temp);
            }
            temp = p;
            //right
            while (ChessBoard.PositionInBounds(temp.Translate(0, 1)) == true)
            {
                positions.Add(temp);
            }
            temp = p;
            //down
            while (ChessBoard.PositionInBounds(temp.Translate(-1, 0)) == true)
            {
                positions.Add(temp);
            }
            temp = p;
            //left
            while (ChessBoard.PositionInBounds(temp.Translate(0, -1)) == true)
            {
                positions.Add(temp);
            }
            return(positions);
        }
Пример #2
0
        public IEnumerable <BoardPosition> PawnMoves(BoardPosition p)
        {
            List <BoardPosition> positions = new List <BoardPosition>();
            BoardPosition        temp      = p;

            /*
             * player one moves up the board
             * must write if statement for if its the starting turn then add move forward two
             * also if an enemy is to the diagonal then a possible move is there
             * also if enpassant is possible add that as well
             */
            while (ChessBoard.PositionInBounds(temp.Translate(1, 0)) == true)
            {
                positions.Add(temp);
            }
            temp = p;

            /*
             * player two moves down the board
             * must write if statement for if its the starting turn then add move forward two
             * also if an enemy is to the diagonal then a possible move is there
             * also if enpassant is possible add that as well
             */
            while (ChessBoard.PositionInBounds(temp.Translate(-1, 0)) == true)
            {
                positions.Add(temp);
            }
            return(positions);
        }
        public static IEnumerable <BoardPosition> GetBishopMoves(BoardPosition pos, ChessBoard board)
        {
            List <BoardPosition> moves = new List <BoardPosition>();
            //while loop front-right
            int row_adder = -1;
            int col_adder = -1;

            for (int i = 0; i < 4; i++)
            {
                if (i == 1)
                {
                    col_adder = 1;
                }
                if (i == 2)
                {
                    row_adder = 1; col_adder = -1;
                }
                if (i == 3)
                {
                    col_adder = 1;
                }

                BoardPosition temp = new BoardPosition(pos.Row + row_adder, pos.Col + col_adder);
                while (ChessBoard.PositionInBounds(temp))
                {
                    moves.Add(temp);
                    if (!board.GetPieceAtPosition(temp).PieceType.Equals(ChessPieceType.Empty))
                    {
                        break;
                    }
                    temp = new BoardPosition(temp.Row + row_adder, temp.Col + col_adder);
                }
            }
            return((IEnumerable <BoardPosition>)moves);
        }
        public static IEnumerable <BoardPosition> GetKnightMoves(BoardPosition pos, ChessBoard board)
        {
            List <BoardPosition> moves = new List <BoardPosition>();

            // front left and front right
            for (int i = -2; i <= 2; i += 4)
            {
                //front and back
                for (int j = -1; j <= 1; j += 2)
                {
                    BoardPosition back = new BoardPosition(pos.Row + i, pos.Col + j);
                    if (ChessBoard.PositionInBounds(back))
                    {
                        moves.Add(back);
                    }
                }
                //right and left
                for (int j = -1; j <= 1; j += 2)
                {
                    BoardPosition right = new BoardPosition(pos.Row + j, pos.Col + i);
                    if (ChessBoard.PositionInBounds(right))
                    {
                        moves.Add(right);
                    }
                }
            }
            return(moves);
        }
Пример #5
0
        public IEnumerable <BoardPosition> KnightMoves(BoardPosition p)
        {
            List <BoardPosition> positions = new List <BoardPosition>();
            //Translate (ex 1 up 1 right) until inbounds == false and flip directions from starting positions until youve gone all 8 ways
            BoardPosition temp = p;

            //up and right
            while (ChessBoard.PositionInBounds(temp.Translate(-2, 1)) == true)
            {
                positions.Add(temp);
            }
            //down and right
            temp = p;
            while (ChessBoard.PositionInBounds(temp.Translate(2, 1)) == true)
            {
                positions.Add(temp);
            }
            //down and left
            temp = p;
            while (ChessBoard.PositionInBounds(temp.Translate(2, -1)) == true)
            {
                positions.Add(temp);
            }
            //up and left
            temp = p;
            while (ChessBoard.PositionInBounds(temp.Translate(-2, -1)) == true)
            {
                positions.Add(temp);
            }
            temp = p;
            //right and up
            while (ChessBoard.PositionInBounds(temp.Translate(-1, 2)) == true)
            {
                positions.Add(temp);
            }
            temp = p;
            //right and down
            while (ChessBoard.PositionInBounds(temp.Translate(1, 2)) == true)
            {
                positions.Add(temp);
            }
            temp = p;
            //left and up
            while (ChessBoard.PositionInBounds(temp.Translate(-1, -2)) == true)
            {
                positions.Add(temp);
            }
            temp = p;
            //left and down
            while (ChessBoard.PositionInBounds(temp.Translate(1, -2)) == true)
            {
                positions.Add(temp);
            }
            return(positions);
        }
        public static IEnumerable <BoardPosition> GetRookMoves(BoardPosition pos, ChessBoard board)
        {
            List <BoardPosition> moves = new List <BoardPosition>();
            int row_adder = 1;
            int col_adder = 0;

            for (int i = 0; i < 4; i++)
            {
                if (i == 1)
                {
                    row_adder = -1;
                }
                if (i == 2)
                {
                    row_adder = 0; col_adder = 1;
                }
                if (i == 3)
                {
                    col_adder = -1;
                }
                BoardPosition temp = new BoardPosition(pos.Row + row_adder, pos.Col + col_adder);
                while (ChessBoard.PositionInBounds(temp))
                {
                    moves.Add(temp);
                    if (!board.GetPieceAtPosition(temp).PieceType.Equals(ChessPieceType.Empty))
                    {
                        break;
                    }
                    temp = new BoardPosition(temp.Row + row_adder, temp.Col + col_adder);
                }
            }
            //BoardPosition temp = new BoardPosition(pos.Row + 1, pos.Col);
            //while (ChessBoard.PositionInBounds(temp))
            //{
            //    moves.Add(temp);
            //    if (! board.GetPieceAtPosition(temp).PieceType.Equals(ChessPieceType.Empty))
            //        break;
            //    temp = new BoardPosition(temp.Row+1, temp.Col);
            //}
            ////while loop right
            //temp = new BoardPosition(pos.Row, pos.Col + 1);
            //while (ChessBoard.PositionInBounds(temp))
            //{
            //    moves.Add(temp);
            //    if (!board.GetPieceAtPosition(temp).PieceType.Equals(ChessPieceType.Empty))
            //        break;
            //    temp = new BoardPosition(temp.Row, temp.Col + 1);
            //}
            ////while loop back
            //temp = new BoardPosition(pos.Row - 1, pos.Col);
            //while (ChessBoard.PositionInBounds(temp))
            //{
            //    moves.Add(temp);
            //    if (!board.GetPieceAtPosition(temp).PieceType.Equals(ChessPieceType.Empty))
            //        break;
            //    temp = new BoardPosition(temp.Row - 1, temp.Col);
            //}
            ////while loop left
            //temp = new BoardPosition(pos.Row, pos.Col-1);
            //while (ChessBoard.PositionInBounds(temp))
            //{
            //    moves.Add(temp);
            //    if (!board.GetPieceAtPosition(temp).PieceType.Equals(ChessPieceType.Empty))
            //        break;
            //    temp = new BoardPosition(temp.Row, temp.Col-1);
            //}

            return((IEnumerable <BoardPosition>)moves);
        }
        public static IEnumerable <BoardPosition> GetKingMoves(BoardPosition pos, ChessBoard board)
        {
            List <BoardPosition> moves = new List <BoardPosition>();
            BoardPosition        left  = new BoardPosition(pos.Row, pos.Col - 1);

            if (ChessBoard.PositionInBounds(left))
            {
                moves.Add(left);
            }
            BoardPosition right = new BoardPosition(pos.Row, pos.Col + 1);

            if (ChessBoard.PositionInBounds(right))
            {
                moves.Add(right);
            }

            BoardPosition front = new BoardPosition(pos.Row + 1, pos.Col);

            if (ChessBoard.PositionInBounds(front))
            {
                moves.Add(front);
            }

            BoardPosition back = new BoardPosition(pos.Row - 1, pos.Col);

            if (ChessBoard.PositionInBounds(back))
            {
                moves.Add(back);
            }

            //diagonal
            BoardPosition front_left = new BoardPosition(pos.Row + 1, pos.Col - 1);

            if (ChessBoard.PositionInBounds(front_left))
            {
                moves.Add(front_left);
            }
            BoardPosition front_right = new BoardPosition(pos.Row + 1, pos.Col + 1);

            if (ChessBoard.PositionInBounds(front_right))
            {
                moves.Add(front_right);
            }

            BoardPosition back_left = new BoardPosition(pos.Row - 1, pos.Col - 1);

            if (ChessBoard.PositionInBounds(back_left))
            {
                moves.Add(back_left);
            }

            BoardPosition back_right = new BoardPosition(pos.Row - 1, pos.Col + 1);

            if (ChessBoard.PositionInBounds(back_right))
            {
                moves.Add(back_right);
            }


            return(moves);
        }
        public static IEnumerable <BoardPosition> GetPawnMoves(BoardPosition pawn_pos, ChessBoard board)
        {
            List <BoardPosition> pawn_moves = new List <BoardPosition>();
            //ChessPiece pawn = board.GetPieceAtPosition(pawn_pos);

            /*
             * //front
             * BoardPosition one_front = new BoardPosition(pawn_pos.Row + 1, pawn_pos.Col);
             * if (ChessBoard.PositionInBounds(one_front))
             *  pawn_moves.Add(one_front);
             */
            //front right
            int player = board.GetPlayerAtPosition(pawn_pos);

            if (player == 1)
            {
                BoardPosition front_right = new BoardPosition(pawn_pos.Row - 1, pawn_pos.Col - 1);
                if (ChessBoard.PositionInBounds(front_right))
                {
                    pawn_moves.Add(front_right);
                }
                //front-left
                BoardPosition one_left = new BoardPosition(pawn_pos.Row - 1, pawn_pos.Col + 1);
                if (ChessBoard.PositionInBounds(one_left))
                {
                    pawn_moves.Add(one_left);
                }

                /*
                 *  if (pawn_pos.Row == 1)
                 * {
                 *  BoardPosition two_front = new BoardPosition(pawn_pos.Row - 2, pawn_pos.Col);
                 *  pawn_moves.Add(two_front);
                 * }
                 */
            }
            else
            {
                BoardPosition front_right = new BoardPosition(pawn_pos.Row + 1, pawn_pos.Col + 1);
                if (ChessBoard.PositionInBounds(front_right))
                {
                    pawn_moves.Add(front_right);
                }
                //front-left
                BoardPosition one_left = new BoardPosition(pawn_pos.Row + 1, pawn_pos.Col - 1);
                if (ChessBoard.PositionInBounds(one_left))
                {
                    pawn_moves.Add(one_left);
                }

                /*
                 *
                 *  if (pawn_pos.Row == 1)
                 * {
                 *  BoardPosition two_front = new BoardPosition(pawn_pos.Row + 2, pawn_pos.Col);
                 *  pawn_moves.Add(two_front);
                 * }
                 */
            }

            return(pawn_moves);
        }