예제 #1
0
 public King(GameBoard board, Color color, ChessGame game) : base(board, color)
 {
     this.game = game;
 }
예제 #2
0
 public Bishop(GameBoard board, Color color) : base(board, color)
 {
 }
예제 #3
0
        public void Move(GameBoard _Game, Coordinate _Current, Coordinate _Next, Empty _Emptyspace)
        {
            if (!(whoseturn ^ _Game.Chessboard[Current.X, Current.Y].IsWhite))
            {
                whoseturn = !whoseturn;
                _Game.Chessboard[_Current.X, _Current.Y].didMove = true;
                _Game.Chessboard[_Current.X, _Current.Y].didMoveHelper++;
                if (_Game.Chessboard[_Next.X, _Next.Y].GetType().ToString().Contains("Empty"))
                {
                    isEmpty = true;
                }
                else if (!(_Game.Chessboard[_Next.X, _Next.Y].IsWhite))
                {
                    isEmpty = false;


                    for (byte i = 0; i < _Game.Black.Count; i++)
                    {
                        if (_Game.Chessboard[_Next.X, _Next.Y] == _Game.Black[i])
                        {
                            reversedPiece = i;
                            break;
                        }
                    }
                    reverserhelper  = true;
                    reversercoord.X = _Game.Chessboard[_Next.X, _Next.Y].Current.X;
                    reversercoord.Y = _Game.Chessboard[_Next.X, _Next.Y].Current.Y;
                    _Game.Chessboard[_Next.X, _Next.Y].Current.X = 99;
                    _Game.Chessboard[_Next.X, _Next.Y].Current.Y = 99;
                }
                else
                {
                    isEmpty = false;

                    for (byte i = 0; i < _Game.White.Count; i++)
                    {
                        if (_Game.Chessboard[_Next.X, _Next.Y] == _Game.White[i])
                        {
                            reversedPiece = i;
                            break;
                        }
                    }
                    reverserhelper  = true;
                    reversercoord.X = _Game.Chessboard[_Next.X, _Next.Y].Current.X;
                    reversercoord.Y = _Game.Chessboard[_Next.X, _Next.Y].Current.Y;
                    _Game.Chessboard[_Next.X, _Next.Y].Current.X = 99;
                    _Game.Chessboard[_Next.X, _Next.Y].Current.Y = 99;
                }

                _Game.Chessboard[_Next.X, _Next.Y]           = _Game.Chessboard[_Current.X, _Current.Y];
                _Game.Chessboard[Current.X, Current.Y]       = _Emptyspace;
                _Game.Chessboard[_Next.X, _Next.Y].Current.X = _Next.X;
                _Game.Chessboard[_Next.X, _Next.Y].Current.Y = _Next.Y;
                drawHelper = true;

                if (CommonProperties.didEnpassantmove)
                {
                    if (_Game.Chessboard[_Next.X, _Next.Y].IsWhite)
                    {
                        _Game.Chessboard[_Next.X - 1, _Next.Y] = _Emptyspace;
                    }
                    else
                    {
                        _Game.Chessboard[_Next.X + 1, _Next.Y] = _Emptyspace;
                    }
                }
            }
        }
예제 #4
0
        public bool MatetestforWhite(GameBoard Game, Empty Emptyspace, Check Checker)
        {
            Coordinate CurrentCoord = new Coordinate();
            Coordinate NextCoord    = new Coordinate();

            for (int i = 0; i < Game.White.Count; i++)
            {
                string typecheck = Game.White[i].GetType().ToString();

                CurrentCoord.X = Game.White[i].Current.X;
                CurrentCoord.Y = Game.White[i].Current.Y;
                for (byte j = 0; j < 8; j++)
                {
                    NextCoord.X = j;
                    for (byte k = 0; k < 8; k++)
                    {
                        NextCoord.Y = k;
                        switch (typecheck)
                        {
                        case "Chess.Pawn":
                            Pawn Pawnmover = new Pawn("WHITE");
                            Pawnmover = (Pawn)Game.Chessboard[CurrentCoord.X, CurrentCoord.Y];
                            if (Pawnmover.isMovable(Game, NextCoord))
                            {
                                Game.Chessboard[CurrentCoord.X, CurrentCoord.Y].Move(Game, CurrentCoord, NextCoord, Emptyspace);
                                if (!(Checker.Checktest(Game, NextCoord)))
                                {
                                    Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace);
                                }
                                else
                                {
                                    Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace);
                                    return(true);
                                }
                            }

                            break;

                        case "Chess.Bishop":

                            Bishop Bishopmover = new Bishop("a");
                            Bishopmover = (Bishop)Game.Chessboard[CurrentCoord.X, CurrentCoord.Y];
                            if (Bishopmover.isMovable(Game, NextCoord))
                            {
                                Game.Chessboard[CurrentCoord.X, CurrentCoord.Y].Move(Game, CurrentCoord, NextCoord, Emptyspace);
                                if (!(Checker.Checktest(Game, NextCoord)))
                                {
                                    Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace);
                                }
                                else
                                {
                                    Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace);
                                    return(true);
                                }
                            }
                            break;

                        case "Chess.Queen":

                            Queen Queenmover = new Queen("a");
                            Queenmover = (Queen)Game.Chessboard[CurrentCoord.X, CurrentCoord.Y];
                            if (Queenmover.isMovable(Game, NextCoord))
                            {
                                Game.Chessboard[CurrentCoord.X, CurrentCoord.Y].Move(Game, CurrentCoord, NextCoord, Emptyspace);
                                if (!(Checker.Checktest(Game, NextCoord)))
                                {
                                    Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace);
                                }
                                else
                                {
                                    Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace);
                                    return(true);
                                }
                            }
                            break;

                        case "Chess.Knight":

                            Knight Knightmover = new Knight("a");
                            Knightmover = (Knight)Game.Chessboard[CurrentCoord.X, CurrentCoord.Y];
                            if (Knightmover.isMovable(Game, NextCoord))
                            {
                                Game.Chessboard[CurrentCoord.X, CurrentCoord.Y].Move(Game, CurrentCoord, NextCoord, Emptyspace);
                                if (!(Checker.Checktest(Game, NextCoord)))
                                {
                                    Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace);
                                }
                                else
                                {
                                    Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace);
                                    return(true);
                                }
                            }
                            break;

                        case "Chess.Castle":

                            Castle Castlemover = new Castle("a");
                            Castlemover = (Castle)Game.Chessboard[CurrentCoord.X, CurrentCoord.Y];
                            if (Castlemover.isMovable(Game, NextCoord))
                            {
                                Game.Chessboard[CurrentCoord.X, CurrentCoord.Y].Move(Game, CurrentCoord, NextCoord, Emptyspace);
                                if (!(Checker.Checktest(Game, NextCoord)))
                                {
                                    Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace);
                                }
                                else
                                {
                                    Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace);
                                    return(true);
                                }
                            }
                            break;

                        case "Chess.King":

                            King Kingmover = new King("a");
                            Kingmover = (King)Game.Chessboard[CurrentCoord.X, CurrentCoord.Y];
                            if (Kingmover.isMovable(Game, NextCoord))
                            {
                                Game.Chessboard[CurrentCoord.X, CurrentCoord.Y].Move(Game, CurrentCoord, NextCoord, Emptyspace);
                                if (!(Checker.Checktest(Game, NextCoord)))
                                {
                                    Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace);
                                }
                                else
                                {
                                    Game.LastmoveReverser(Game, CurrentCoord, NextCoord, Emptyspace);
                                    return(true);
                                }
                            }


                            break;
                        }
                    }
                }
            }
            return(false);
        }
예제 #5
0
 public Queen(GameBoard board, Color color) : base(board, color)
 {
 }
예제 #6
0
        public bool isMovable(GameBoard _Game, Coordinate _Next)
        {
            bool foechecker;
            bool foeTester;

            if (IsWhite)
            {
                if (!(_Game.Chessboard[_Next.X, _Next.Y].GetType().ToString().Contains("Empty")))
                {
                    foechecker = !(_Game.Chessboard[_Next.X, _Next.Y].IsWhite);
                    foeTester  = (_Game.Chessboard[_Next.X, _Next.Y].GetType().ToString().Contains("Empty") || foechecker);
                }
                else
                {
                    foeTester = _Game.Chessboard[_Next.X, _Next.Y].GetType().ToString().Contains("Empty");
                }
            }
            else
            {
                if (!(_Game.Chessboard[_Next.X, _Next.Y].GetType().ToString().Contains("Empty")))
                {
                    foechecker = (_Game.Chessboard[_Next.X, _Next.Y].IsWhite);
                    foeTester  = (_Game.Chessboard[_Next.X, _Next.Y].GetType().ToString().Contains("Empty") || foechecker);
                }
                else
                {
                    foeTester = _Game.Chessboard[_Next.X, _Next.Y].GetType().ToString().Contains("Empty");
                }
            }
            sbyte coordX = (sbyte)(_Next.X - Current.X);
            sbyte coordY = (sbyte)(_Next.Y - Current.Y);

            if (Math.Abs(coordX) == Math.Abs(coordY))
            {
                if (coordY == 0 || coordX == 0)
                {
                    return(false);
                }
                sbyte incrementX = (sbyte)(coordX / Math.Abs(coordX));
                sbyte incrementY = (sbyte)(coordY / Math.Abs(coordY));

                sbyte incrementXX = incrementX;
                sbyte incrementYY = incrementY;

                byte movablecount = 0;

                for (; ((Math.Abs(incrementX) < Math.Abs(coordX)) && (Math.Abs(incrementY) < Math.Abs(coordY))); incrementX += incrementXX, incrementY += incrementYY)
                {
                    if (_Game.Chessboard[Current.X + incrementX, Current.Y + incrementY].GetType().ToString().Contains("Empty"))
                    {
                        movablecount++;
                    }
                }
                if ((Math.Abs(coordX) == Math.Abs(coordY)) && foeTester && (movablecount == Math.Abs(coordX) - 1))
                {
                    return(true);
                }
            }
            else if ((Current.X - _Next.X == 0))
            {
                if (coordY == 0)
                {
                    return(false);
                }
                sbyte incrementY = (sbyte)(coordY / Math.Abs(coordY));

                sbyte incrementYY = incrementY;

                byte movablecount = 0;

                for (; (Math.Abs(incrementY) < Math.Abs(coordY)); incrementY += incrementYY)
                {
                    if (_Game.Chessboard[Current.X, Current.Y + incrementY].GetType().ToString().Contains("Empty"))
                    {
                        movablecount++;
                    }
                }
                if (foeTester && (movablecount == Math.Abs(coordY) - 1))
                {
                    return(true);
                }
            }
            else if ((Current.Y - _Next.Y == 0))
            {
                if (coordX == 0)
                {
                    return(false);
                }
                sbyte incrementX  = (sbyte)(coordX / Math.Abs(coordX));
                sbyte incrementXX = incrementX;

                byte movablecount = 0;

                for (; (Math.Abs(incrementX) < Math.Abs(coordX)); incrementX += incrementXX)
                {
                    if (_Game.Chessboard[Current.X + incrementX, Current.Y].GetType().ToString().Contains("Empty"))
                    {
                        movablecount++;
                    }
                }
                if (foeTester && (movablecount == Math.Abs(coordX) - 1))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #7
0
 public Knight(GameBoard board, Color color) : base(board, color)
 {
 }
예제 #8
0
 public Rook(GameBoard board, Color color) : base(board, color)
 {
 }
예제 #9
0
        public void Run(GameBoard Game, Coordinate Current, Coordinate Next, Check Checker, Empty Emptyspace)
        {
            string typecheck;

            typecheck = Game.Chessboard[Current.X, Current.Y].GetType().ToString();

            switch (typecheck)
            {
            case "Chess.Pawn":
                Pawn Pawnmover = new Pawn("WHITE");
                Pawnmover = (Pawn)Game.Chessboard[Current.X, Current.Y];
                if (Pawnmover.isMovable(Game, Next))
                {
                    Game.Chessboard[Current.X, Current.Y].Move(Game, Current, Next, Emptyspace);
                    if (!(Checker.Checktest(Game, Next)))
                    {
                        Game.LastmoveReverser(Game, Current, Next, Emptyspace);
                    }
                    else
                    {
                        anyChanges = true;
                    }
                }

                break;

            case "Chess.Bishop":

                Bishop Bishopmover = new Bishop("a");
                Bishopmover = (Bishop)Game.Chessboard[Current.X, Current.Y];
                if (Bishopmover.isMovable(Game, Next))
                {
                    Game.Chessboard[Current.X, Current.Y].Move(Game, Current, Next, Emptyspace);
                    if (!(Checker.Checktest(Game, Next)))
                    {
                        Game.LastmoveReverser(Game, Current, Next, Emptyspace);
                    }
                    else
                    {
                        anyChanges = true;
                    }
                }
                break;

            case "Chess.Queen":

                Queen Queenmover = new Queen("a");
                Queenmover = (Queen)Game.Chessboard[Current.X, Current.Y];
                if (Queenmover.isMovable(Game, Next))
                {
                    Game.Chessboard[Current.X, Current.Y].Move(Game, Current, Next, Emptyspace);
                    if (!(Checker.Checktest(Game, Next)))
                    {
                        Game.LastmoveReverser(Game, Current, Next, Emptyspace);
                    }
                    else
                    {
                        anyChanges = true;
                    }
                }
                break;

            case "Chess.Knight":

                Knight Knightmover = new Knight("a");
                Knightmover = (Knight)Game.Chessboard[Current.X, Current.Y];
                if (Knightmover.isMovable(Game, Next))
                {
                    Game.Chessboard[Current.X, Current.Y].Move(Game, Current, Next, Emptyspace);
                    if (!(Checker.Checktest(Game, Next)))
                    {
                        Game.LastmoveReverser(Game, Current, Next, Emptyspace);
                    }
                    else
                    {
                        anyChanges = true;
                    }
                }
                break;

            case "Chess.Castle":

                Castle Castlemover = new Castle("a");
                Castlemover = (Castle)Game.Chessboard[Current.X, Current.Y];
                if (Castlemover.isMovable(Game, Next))
                {
                    Game.Chessboard[Current.X, Current.Y].Move(Game, Current, Next, Emptyspace);
                    if (!(Checker.Checktest(Game, Next)))
                    {
                        Game.LastmoveReverser(Game, Current, Next, Emptyspace);
                    }
                    else
                    {
                        anyChanges = true;
                    }
                }
                break;

            case "Chess.King":

                King Kingmover = new King("a");
                Kingmover = (King)Game.Chessboard[Current.X, Current.Y];
                if (Kingmover.isMovable(Game, Next))
                {
                    Game.Chessboard[Current.X, Current.Y].Move(Game, Current, Next, Emptyspace);
                    if (!(Checker.Checktest(Game, Next)))
                    {
                        Game.LastmoveReverser(Game, Current, Next, Emptyspace);
                    }
                    else
                    {
                        anyChanges = true;
                    }
                }

                else if (Kingmover.Rooktest1(Game, Current, Next, Emptyspace) && Checker.Checktest(Game, Current))
                {
                    Game.Chessboard[Current.X, Current.Y].Rookmover1(Game, Current, Next, Emptyspace);
                    anyChanges = true;
                }

                else if (Kingmover.Rooktest2(Game, Current, Next, Emptyspace) && Checker.Checktest(Game, Current))
                {
                    Game.Chessboard[Current.X, Current.Y].Rookmover2(Game, Current, Next, Emptyspace);
                    anyChanges = true;
                }

                break;
            }
            if (CommonProperties.enPassantfinder + 1 > Game.White.Count || CommonProperties.enPassantfinder + 1 > Game.Black.Count)
            {
                CommonProperties.enPassantfinder = 0;
            }
            if (Game.White[CommonProperties.enPassantfinder].enPassantchecker == 2)
            {
                Game.White[CommonProperties.enPassantfinder].enPassantchecker -= 1;
            }
            else if (Game.White[CommonProperties.enPassantfinder].enPassantchecker == 1)
            {
                Game.White[CommonProperties.enPassantfinder].enPassantchecker -= 1;
            }
            if (Game.Black[CommonProperties.enPassantfinder].enPassantchecker == 2)
            {
                Game.Black[CommonProperties.enPassantfinder].enPassantchecker -= 1;
            }
            else if (Game.Black[CommonProperties.enPassantfinder].enPassantchecker == 1)
            {
                Game.Black[CommonProperties.enPassantfinder].enPassantchecker -= 1;
            }
        }
예제 #10
0
 public void placeNewPiece(char column, int line, Piece piece)
 {
     GameBoard.placePiece(piece, new ChessPosition(column, line).ToPosition());
     gamePieces.Add(piece);
 }