예제 #1
0
        public override List <string> GetPossibleMove()
        {
            possibleMoves = new List <string>();

            Bishop fakeBishop = new Bishop(pos, color, board);
            Rook   fakeRook   = new Rook(pos, color, board);

            possibleMoves.AddRange(fakeBishop.GetPossibleMove());
            possibleMoves.AddRange(fakeRook.GetPossibleMove());

            return(possibleMoves);
        }
예제 #2
0
 public Bishop(Chessman fromPiece, BoardSpace initPos)
 {
     if (fromPiece.GetType() == typeof(Bishop))
     {
         Bishop from = (Bishop)fromPiece;
         score      = from.score;
         position   = initPos;
         this.color = from.color;
         whiteImage = from.whiteImage;
         blackImage = from.blackImage;
     }
     else
     {
         throw new Exception($"Cant Create Copy of Piece becasue it is the wrong type");
     }
 }
예제 #3
0
        public override List <Move> getAvailableMoves(Board boardState)
        {
            List <Move> validMoveList = new List <Move>();


            validMoveList.AddRange(Bishop.getMovesForBishop(boardState, color, position));
            validMoveList.AddRange(Rook.getMovesForRook(boardState, color, position));
            // Amend Score for Pieces now attacking this piece
            if (boardState.isKingInCheck(color))
            {
                List <Move> afterCheckMoveList = getCheckBlockingMoves(boardState, validMoveList, color);
                validMoveList.Clear();
                validMoveList.AddRange(afterCheckMoveList);
            }

            return(validMoveList);
        }
예제 #4
0
        public object Clone()
        {
            Piece newPiece;

            switch (this.GetType().FullName)
            {
            case "King":
                newPiece = new King(this.Color, this.Id);
                break;

            case "Queen":
                newPiece = new Queen(this.Color, this.Id);
                break;

            case "Rook":
                newPiece = new Rook(this.Color, this.Id);
                break;

            case "Bishop":
                newPiece = new Bishop(this.Color, this.Id);
                break;

            case "Knight":
                newPiece = new Knight(this.Color, this.Id);
                break;

            case "Pawn":
                newPiece = new Pawn(this.Color, this.Id);
                break;

            default:
                return(null);
            }

            newPiece.Location = this.Location;
            newPiece.Moved    = this.Moved;
            newPiece.Captured = this.Captured;

            return(newPiece);
        }
예제 #5
0
파일: Game.cs 프로젝트: malibrud/Peritum
        public void SetupBoard()
        {
            piece[0] = new Rook(false, "rbk");
            piece[1] = new Knight(false, "nbk");
            piece[2] = new Bishop(false, "bbk");
            piece[3] = new Queen(false, "qb");
            piece[4] = new King(false, "kb");
            piece[5] = new Bishop(false, "bbq");
            piece[6] = new Knight(false, "nbq");
            piece[7] = new Rook(false, "rbq");

            piece[8]  = new Pawn(false, "pba");
            piece[9]  = new Pawn(false, "pbb");
            piece[10] = new Pawn(false, "pbc");
            piece[11] = new Pawn(false, "pbd");
            piece[12] = new Pawn(false, "pbe");
            piece[13] = new Pawn(false, "pbf");
            piece[14] = new Pawn(false, "pbg");
            piece[15] = new Pawn(false, "pbh");

            piece[16] = new Rook(true, "rwk");
            piece[17] = new Knight(true, "nwk");
            piece[18] = new Bishop(true, "bwk");
            piece[19] = new Queen(true, "qw");
            piece[20] = new King(true, "kw");
            piece[21] = new Bishop(true, "bbw");
            piece[22] = new Knight(true, "nbw");
            piece[23] = new Rook(true, "rbw");

            piece[24] = new Pawn(true, "pba");
            piece[25] = new Pawn(true, "pbb");
            piece[26] = new Pawn(true, "pbc");
            piece[27] = new Pawn(true, "pbd");
            piece[28] = new Pawn(true, "pbe");
            piece[29] = new Pawn(true, "pbf");
            piece[30] = new Pawn(true, "pbg");
            piece[31] = new Pawn(true, "pbh");

            // set the first turn to white
            turn = true;

            // Adds the black home row to the board
            for (int i = 0; i < 8; i++)
            {
                piece[i].Location = new Point(i, 0);
            }

            // Adds the black pawns to the board
            for (int i = 8; i < 16; i++)
            {
                piece[i].Location = new Point(i - 8, 1);
            }

            // Adds the white home row to the board
            for (int i = 16; i < 24; i++)
            {
                piece[i].Location = new Point(i - 16, 7);
            }

            // Adds the White pawns to the board
            for (int i = 24; i < 32; i++)
            {
                piece[i].Location = new Point(i - 24, 6);
            }
        }
예제 #6
0
        private Chessman movePieceOnBoard(BoardSpace fromSpace, BoardSpace toSpace, String extraArgs = "")
        {
            // This is kust updating the data model. Validation Should occur prior to this
            // This function Assumes that the moves are valid.

            Chessman fromPiece   = fromSpace.piece;
            Chessman killedPiece = null;

            if (toSpace.piece != null)
            {
                // We killed piece remove it.
                killedPiece = toSpace.piece;
            }
            fromPiece.position = toSpace;
            toSpace.piece      = fromPiece;
            fromSpace.piece    = null;

            if (toSpace.piece.GetType() == typeof(King))
            {
                King kp = (King)toSpace.piece;
                if (kp.canCastle)
                {
                    kp.canCastle = false;
                }
                if (kp.color == ChessmanColor.white)
                {
                    whiteKingPos = toSpace;
                }
                else
                {
                    blackKingPos = toSpace;
                }
            }
            else if (toSpace.piece.GetType() == typeof(Rook))
            {
                Rook rp = (Rook)toSpace.piece;
                if (rp.canCastle)
                {
                    rp.canCastle = false;
                }
            }
            else if (toSpace.piece.GetType() == typeof(Pawn))
            {
                ((Pawn)toSpace.piece).canMoveTwice = false;  // Pawns Can only Move Twice on the first move
                if ((toSpace.piece.color == ChessmanColor.black && toSpace.position.Item2 == 1) || (toSpace.piece.color == ChessmanColor.white && toSpace.position.Item2 == 8))
                {
                    Char promotionType = 'q';
                    if (extraArgs.Length > 0)
                    {
                        promotionType = extraArgs.ToLower()[0];
                    }

                    switch (promotionType)
                    {
                    case 'q':
                        // Promote to Queen
                        Queen q = new Queen(toSpace, toSpace.piece.color);
                        toSpace.piece = q;
                        break;

                    case 'b':
                        // Promote to Queen
                        Bishop b = new Bishop(toSpace, toSpace.piece.color);
                        toSpace.piece = b;
                        break;

                    case 'n':
                        // Promote to Queen
                        Knight kn = new Knight(toSpace, toSpace.piece.color);
                        toSpace.piece = kn;
                        break;

                    case 'r':
                        // Promote to Queen
                        Rook r = new Rook(toSpace, toSpace.piece.color);
                        toSpace.piece = r;
                        break;
                    }
                }
            }

            updateAttacksOnKing(toSpace.piece.color);

            return(killedPiece);
        }