Пример #1
0
        ///Methods
        //Overidden with King piece logic
        //Does not include that a king cannot move to an attacked square, that is added in FilteringMoves
        public override MoveList getPieceMoves(GameBoard board, Location startLocation, ColorEnum color)
        {
            MoveList moves = new MoveList();

            for (int i = 0; i < 8; i++)
            {
                Location possible = startLocation.Shift(Location.directionIndex(i));
                if (board.locationOnBoard(possible))
                {// Cannot include the idea that a king cant move to an attack space as it links to the king and creates an infinite loop
                    //Needs to be filtered on the outside of the gameboard
                    if (!board.pieceAtLocation(possible))
                    {
                        Move newMove = new Move(startLocation, possible);
                        newMove.AddNeededEmtpyLocations(possible.Copy());
                        moves.Add(newMove);
                    }
                    else if (board.getPiece(possible).color != color)
                    {
                        Move attack = new Move(startLocation, possible);
                        attack.AddAttackedLocation(possible);
                        moves.Add(attack);
                    }
                }
            }

            return(moves);
        }
Пример #2
0
        ///Methods
        //Overidden with Knight piece logic
        public override MoveList getPieceMoves(GameBoard board, Location startLocation, ColorEnum color)
        {
            MoveList moves = new MoveList();

            for (int i = 0; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j += 2)
                {
                    for (int k = -1; k <= 1; k += 2)
                    {
                        int      xShift = (1 + i) * j, yShift = (2 - i) * k;
                        Location poss = startLocation.Shift(xShift, yShift);
                        if (board.locationOnBoard(poss))
                        {
                            if (!board.pieceAtLocation(poss))
                            {
                                Move newMove = new Move(startLocation, poss);
                                newMove.AddNeededEmtpyLocations(poss.Copy());
                                moves.Add(newMove);
                            }
                            else if (board.getPiece(poss).color != color)
                            {
                                Move attack = new Move(startLocation, poss);
                                attack.AddAttackedLocation(poss);

                                moves.Add(attack);
                            }
                        }
                    }
                }
            }

            return(moves);
        }
Пример #3
0
        ///Methods
        //Overidden with Queen piece logic
        public override MoveList getPieceMoves(GameBoard board, Location startLocation, ColorEnum color)
        {
            MoveList moves = new MoveList();

            Location local;

            for (int i = 0; i < 8; i++)
            {
                local = new Location(startLocation);


                IList <Location> previousEmpty = new List <Location>();
                while (true)
                {
                    local = local.Shift(Location.directionIndex(i));

                    //Conditional for stopping the array
                    if (!board.locationOnBoard(local))
                    {
                        break;
                    }
                    if (board.pieceAtLocation(local))
                    {
                        if (board.getPiece(local).color != color)
                        {
                            Move attack = new Move(startLocation, local);
                            attack.AddAttackedLocation(local);

                            foreach (Location empty in previousEmpty)
                            {
                                attack.AddNeededEmtpyLocations(empty.Copy());
                            }

                            moves.Add(attack);
                        }

                        break;
                    }

                    previousEmpty.Add(local);

                    Move nonAttack = new Move(startLocation, local);

                    //Includes the end location as it is non attack
                    foreach (Location empty in previousEmpty)
                    {
                        nonAttack.AddNeededEmtpyLocations(empty.Copy());
                    }

                    moves.Add(nonAttack);
                }
            }

            return(moves);
        }
Пример #4
0
        //Makes the Pawn into a queen if it has reached the end of the board
        public override void afterMoveAction(GameBoard board)
        {
            Location forwardLoc = location.Shift(0, getYForward());

            if (!board.locationOnBoard(forwardLoc))
            {
                //Perform the queen me
                Queen upgrade = new Queen(this);
                board.removePiece(this);
                board.addPiece(upgrade);
            }
        }
Пример #5
0
        ///Methods
        //Overidden with Pawn piece logic
        public override MoveList getPieceMoves(GameBoard board, Location startLocation, ColorEnum color)
        {
            MoveList moves = new MoveList();

            int      forward    = getYForward();
            Location forwardLoc = startLocation.Shift(0, forward);

            if (board.locationOnBoard(forwardLoc) && !board.pieceAtLocation(forwardLoc))
            {
                Move newMove = new Move(startLocation, forwardLoc);
                newMove.AddNeededEmtpyLocations(forwardLoc.Copy());
                moves.Add(newMove);


                //Needs to be able to do the first forward in order to do the second one
                Location doubleForwardLoc = forwardLoc.Shift(0, forward);
                if (board.locationOnBoard(doubleForwardLoc) && !board.pieceAtLocation(doubleForwardLoc) && !getHasMoved())
                {
                    Move doubleForwardNewMove = new Move(startLocation, doubleForwardLoc);
                    doubleForwardNewMove.AddNeededEmtpyLocations(forwardLoc.Copy());
                    doubleForwardNewMove.AddNeededEmtpyLocations(doubleForwardLoc.Copy());
                    moves.Add(doubleForwardNewMove);
                }
            }


            //Two attacks
            for (int i = -1; i <= 1; i += 2)
            {
                Location sideAttack = startLocation.Shift(i, forward);
                if (board.locationOnBoard(sideAttack) && board.pieceAtLocation(sideAttack) && board.getPiece(sideAttack).color != color)
                {
                    Move sideAttackMove = new Move(startLocation, sideAttack);
                    sideAttackMove.AddAttackedLocation(sideAttack);
                    moves.Add(sideAttackMove);
                }
            }

            return(moves);
        }