Пример #1
1
 static void Main()
 {
     using (var game = new ChessGame())
         game.Run();
 }
Пример #2
0
        public dlgPawnPromotion(ChessGame chessGame)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            this.chessGame = chessGame;
        }
Пример #3
0
        public static void PrintCapturedPieces(ChessGame game)
        {
            Console.Write("Pieces captured by white player: ");
            ConsoleColor aux = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Yellow;
            PrintCapturedPiecesColor(game, Color.Black);
            Console.ForegroundColor = aux;
            Console.Write("Pieces captured by black player: ");
            PrintCapturedPiecesColor(game, Color.White);
            Console.WriteLine();
        }
Пример #4
0
        public dlgDebugArtificialIntelligence(ChessGame chessGame)
        {
            InitializeComponent();

            this.chessGame                 = new ChessGame();
            this.chessGame.Board           = Chess.ChessGame.CopyBoard(chessGame.Board);
            this.chessGame.Turn            = chessGame.Turn;
            this.chessGame.Human           = chessGame.Human;
            this.chessGame.Computer        = chessGame.Computer;
            this.ctlUIChessBoard.chessgame = this.chessGame;
            ai = new ArtificialIntelligence(this.chessGame);
        }
Пример #5
0
        public static void PrintCapturedPiecesColor(ChessGame game, Color color)
        {
            HashSet <Piece> set = game.CapturedPiecesColor(color);
            StringBuilder   str = new StringBuilder();

            str.Append("[ ");
            foreach (Piece piece in set)
            {
                str.Append(piece.ToString() + " ");
            }
            str.Append("]");
            Console.WriteLine(str.ToString());
        }
Пример #6
0
 //write the current state of the board with a grid drawn around it and axes labelled and pieces taken
 //if FLIPPED it will draw it FLIPPED
 public static void WriteGameState(ChessGame game)
 {
     if (game.Moves.Count % 2 == 0)   //then its even or zero
     {
         Console.WriteLine("╔══╦══╦══╦══╦══╦══╦══╦══╗  WHITE to move...");
     }
     else
     {
         Console.WriteLine("╔══╦══╦══╦══╦══╦══╦══╦══╗  BLACK to move...");
     }
     for (int R = 0; R < 8; R++)
     {
         for (int F = 0; F < 8; F++)
         {
             if (!game.FLIPPED)
             {
                 Console.Write("║" + game.Board[R, F]);
             }
             else
             {
                 Console.Write("║" + game.Board[7 - R, 7 - F]);
             }
             if (F == 7)
             {
                 if (!game.FLIPPED)
                 {
                     Console.Write("║ " + (8 - R).ToString());
                 }
                 else
                 {
                     Console.Write("║ " + (R + 1).ToString());
                 }
                 Console.Write("\n");
             }
         }
         if (R < 7)
         {
             Console.WriteLine("╠══╬══╬══╬══╬══╬══╬══╬══╣");
         }
     }
     Console.WriteLine("╚══╩══╩══╩══╩══╩══╩══╩══╝");
     if (!game.FLIPPED)
     {
         Console.WriteLine(" a  b  c  d  e  f  g  h    Pieces taken: " + game.StringOfPiecesTaken);
     }
     else
     {
         Console.WriteLine(" h  g  f  e  d  c  b  a    Pieces taken: " + game.StringOfPiecesTaken);
     }
     Console.WriteLine();
 }
Пример #7
0
        public static void PrintCaughtPieces(ChessGame game)
        {
            Console.WriteLine("Peças capturadas:");
            Console.Write("Brancas: ");
            PrintSet(game.CaughtPieces(Color.White));
            Console.WriteLine();
            Console.Write("Pretas: ");
            ConsoleColor aux = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Yellow;
            PrintSet(game.CaughtPieces(Color.Black));
            Console.ForegroundColor = aux;
            Console.WriteLine();
        }
Пример #8
0
        public static void PrintCapturedPieces(ChessGame chessGame)
        {
            Console.WriteLine("Captured pieces: ");
            Console.Write("White: ");
            PrintPieceSet(chessGame.CapturedPieces(Color.White));
            Console.WriteLine();
            Console.Write("Black: ");
            ConsoleColor aux = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Yellow;
            PrintPieceSet(chessGame.CapturedPieces(Color.Black));
            Console.ForegroundColor = aux;
            Console.WriteLine();
        }
Пример #9
0
        public MoveModel GetMoveCoordsAndPiece(ChessGame game, string move)
        {
            MoveModel mm  = new MoveModel();
            var       src = move.Substring(0, 2);
            var       dst = move.Substring(2, 2);

            mm.xsrc = (int)Convert.ToChar(src.Substring(0, 1));
            mm.ysrc = (int)Convert.ToChar(src.Substring(1, 1));
            mm.xdst = (int)Convert.ToChar(dst.Substring(0, 1));
            mm.ydst = (int)Convert.ToChar(dst.Substring(1, 1));

            mm.srcval = (GetVal(game.Board, src));
            mm.dstval = (GetVal(game.Board, dst));
            return(mm);
        }
Пример #10
0
        static void Main(string[] args)
        {
            try
            {
                ChessGame game = new ChessGame();

                while (!game.Finished)
                {
                    try
                    {
                        Screen.PrintGame(game);

                        Console.Write("Origem: ");
                        Position source = Screen.ReadChessPosition().ToPosition();
                        game.ValidateSourcePosition(source);

                        bool[,] posibleMovements = game.Board.Piece(source).PossibleMovements();

                        Console.Clear();
                        Screen.PrintBoard(game.Board, posibleMovements);

                        Console.WriteLine();
                        Console.Write("Destino: ");
                        Position destination = Screen.ReadChessPosition().ToPosition();
                        game.ValidateDestinationPosition(source, destination);

                        game.MakePlay(source, destination);
                    }
                    catch (BoardException e)
                    {
                        Console.WriteLine(e.Message);
                        Console.ReadLine();
                    }

                    Screen.PrintGame(game);
                }
            }
            catch (BoardException e)
            {
                Console.WriteLine(e.Message);
            }

            //ChessPosition pos = new ChessPosition('a', 1);

            //Console.WriteLine(pos);
            //Console.WriteLine(pos.ToPosition());
        }
Пример #11
0
        public void Initialize(ChessGame game, PieceTeam team)
        {
            this.Team = team;
            switch (type)
            {
            case Type.Player:
                break;

            case Type.MinMax:
                playerModel = new Player.AI.ChessMinMaxAI(game, team);
                playerModel.OnMovementDecided += OnDecideMovement;
                break;

            default:
                throw new NotImplementedException();
            }
        }
Пример #12
0
        public static void PrintPlay(ChessGame game, bool[,] possibleMoves)
        {
            Console.Clear();
            Screen.PrintBoard(game.Board, possibleMoves);

            Console.WriteLine();

            PrintCapturedPieces(game);

            Console.WriteLine("Turn #" + game.Turn.ToString());
            Console.WriteLine("Current player: " + game.CurrentPlayer);
            if (game.IsInCheck(game.CurrentPlayer))
            {
                Console.WriteLine("CHECK!");
            }
            Console.WriteLine();
        }
Пример #13
0
        static void Main(string[] args)
        {
            try
            {
                ChessGame game = new ChessGame();

                while (!game.Finished)
                {
                    try
                    {
                        Screen.PrintPlay(game, new bool[game.Board.Lines, game.Board.Columns]);

                        Console.Write("Initial position: ");
                        ChessPosition initialChessPosition = Screen.ReadPosition();
                        Position      initialPosition      = initialChessPosition.ToPosition();

                        game.CheckInitialPosition(initialPosition);
                        bool[,] possibleMoves = game.Board.GetPiece(initialPosition).PossibleMoves();

                        Screen.PrintPlay(game, possibleMoves);
                        Console.Write("Initial position: ");
                        Screen.PrintPosition(initialPosition);

                        Console.Write("Final position: ");
                        Position finalPosition = Screen.ReadPosition().ToPosition();
                        game.CheckFinalPosition(initialPosition, finalPosition);

                        game.PerformPlay(initialPosition, finalPosition);

                        Screen.EndGame(game);
                    }
                    catch (BoardException e)
                    {
                        Console.WriteLine();
                        Console.WriteLine(e.Message);
                        Console.Write("Press ENTER to re-do this play. ");
                        Console.ReadLine();
                    }
                }
            }
            catch (BoardException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #14
0
        protected void OnPieceOrder(ChessPiece piece, Point destination)
        {
            Point old = ChessGame.ConvertToPoint(piece.Position);

            Board[old.X, old.Y] = null;

            piece.Position = ChessGame.ConvertToPosition(destination);

            ChessPiece pieceAtDestination = Board[destination.X, destination.Y];

            if (pieceAtDestination != null)
            {
                OnPieceDestroyed(pieceAtDestination);
            }

            Board[destination.X, destination.Y] = piece;
            piece.UpdateTransform();
        }
Пример #15
0
        static void Main(string[] args)
        {
            try
            {
                ChessGame chessGame = new ChessGame();

                while (!chessGame.Finished)
                {
                    try
                    {
                        Console.Clear();
                        View.PrintGame(chessGame);
                        Console.WriteLine();
                        Console.Write("Origin: ");
                        Position origin = View.ReadChessPosition().ToPosition();
                        chessGame.ValidateOriginPosition(origin);

                        bool[,] PossiblePositions = chessGame.board.piece(origin).PossibleMoves();

                        Console.Clear();
                        View.PrintBoard(chessGame.board, PossiblePositions);

                        Console.WriteLine();
                        Console.Write("Destiny: ");
                        Position destiny = View.ReadChessPosition().ToPosition();
                        chessGame.ValidateDestinyPosition(origin, destiny);

                        chessGame.ExePlay(origin, destiny);
                    }
                    catch (BoardException e)
                    {
                        Console.WriteLine(e.Message);
                        Console.ReadLine();
                    }
                }
                Console.Clear();
                View.PrintGame(chessGame);
            }
            catch (BoardException e)
            {
                Console.WriteLine(e.Message);
            }
            Console.ReadLine();
        }
Пример #16
0
        public bool IsValidMove(ChessGame game, string move)
        {
            if ((move == "0") || (move == "00"))
            {
                if (IsCastlingValid(game, move))
                {
                    return(true);
                }
            }
            else
            {
                //NOW WE CAN GET THE src AND dst parts safely...
                var src = move.Substring(0, 2);
                var dst = move.Substring(2, 2);
                //XY_SRC_DST = GetXYs(move);                     //e.g. 4,2,4,4 .... ints !!! NOT USED ???
                //do some more fundamental checks !!!
                //make sure the source square is not a blank one !!!
                if (GetVal(game.Board, src) == "  ")
                {
                    return(false);
                }
                //make sure its correct turn !!!
                //if (IsItYourTurn(board, src))
                //{
                //    return false;
                //}

                //make sure it is moving somewhere
                if (src == dst)
                {
                    return(false);
                }
                //make sure move is not taking own piece
                if ((" R N B Q K P".Contains(GetVal(game.Board, src))) && (" R N B Q K P".Contains(GetVal(game.Board, dst)))
                    ||
                    (" r n b q k p".Contains(GetVal(game.Board, src))) && (" r n b q k p".Contains(GetVal(game.Board, dst))))
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #17
0
 public static void PrintGame(ChessGame chessGame)
 {
     PrintBoard(chessGame.board);
     Console.WriteLine();
     PrintCapturedPieces(chessGame);
     Console.WriteLine();
     Console.WriteLine("Turn: " + chessGame.Turn);
     Console.WriteLine("Waiting play: " + chessGame.CurrentPlayer);
     if (!chessGame.Finished)
     {
         if (chessGame.Check)
         {
             Console.WriteLine("CHECK!!");
         }
     }
     else
     {
         Console.WriteLine("CHECKMATE!!");
         Console.WriteLine("Winner: " + chessGame.CurrentPlayer);
     }
 }
Пример #18
0
        public bool IsWhiteOrBlackToMove(ChessGame game, string move)
        {
            MoveModel mm = GetMoveCoordsAndPiece(game, move);

            //blacks turn?
            if (" r n b q k p".Contains(mm.srcval))
            {
                if (game.Moves.Count % 2 == 0)
                {
                    return(false);
                }
            }
            //whites turn?
            if (" R N B Q K P".Contains(mm.srcval))
            {
                if (game.Moves.Count % 2 != 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #19
0
 private static void CommandMove(ChessGame game, string move)
 {
     if (move.StartsWith("q"))   //quit the game
     {
         PLAYING = false;
     }
     else if (move.StartsWith("r"))  //reset
     {
         game.FLIPPED = false;
         game.Board   = game.InitialiseGame();
         game.Moves.Clear();
         game.PiecesTaken.Clear();
         game.StringOfPiecesTaken.Clear();
     }
     else if (move.StartsWith("f"))      //flip the board over
     {
         game.FLIPPED = !game.FLIPPED;
     }
     else if (move.StartsWith("s"))      //save
     {
         // save the game - TODO
     }
 }
Пример #20
0
        public static void Main()
        {
            string     LowerCaseMove;
            Validation validate = new Validation();

            ChessGame Game1 = new ChessGame();

            BoardInternal Game2 = new BoardInternal();

            //test comment
            while (PLAYING)
            {
                CommonUtils.DisplayBoard(Game2);
                WriteBoard(Game1);
                Message.Clear();

                LowerCaseMove = Console.ReadLine().ToLower();

                if (validate.IsFormatValid(LowerCaseMove))
                {
                    if (LowerCaseMove == "r" || LowerCaseMove == "f" || LowerCaseMove == "s" || LowerCaseMove == "q")
                    {
                        CommandMove(Game1, LowerCaseMove);
                        CommandMove2(Game2, LowerCaseMove);
                    }
                    else
                    {
                        ChessMove(Game1, Game2, LowerCaseMove, validate);
                        ChessMove2(Game2, LowerCaseMove, validate);
                    }
                }
                else
                {
                    Message.Append("Invalid move :" + LowerCaseMove + " ");
                }
            }
        }
Пример #21
0
        void DisplayChessPieces(ChessGame chessGame)
        {
            Dictionary <int, string> pairs = new Dictionary <int, string>();

            pairs.Add(0, "A"); pairs.Add(1, "B"); pairs.Add(2, "C"); pairs.Add(3, "D"); pairs.Add(4, "E"); pairs.Add(5, "F"); pairs.Add(6, "G"); pairs.Add(7, "H");
            for (int row = 0; row < 8; row++)
            {
                for (int col = 0; col < 8; col++)
                {
                    Label      label      = (Label)Controls.Find(pairs[col] + (row + 1), true)[0];
                    ChessPiece chessPiece = chessGame.chessboard[row, col];

                    if (chessPiece == null)
                    {
                        label.Text = "";
                    }
                    else
                    {
                        if (chessPiece.color == ChessPieceColor.Black)
                        {
                            label.ForeColor = Color.Black;
                        }
                        else
                        {
                            label.ForeColor = Color.White;
                        }
                        string type = chessPiece.type.ToString().ToLower();
                        if (type == "king" || type == "queen")
                        {
                            type = chessPiece.type.ToString();
                        }
                        label.Text = type[0].ToString();
                    }
                }
            }
        }
Пример #22
0
 bool CheckMove(ChessGame chessGame, Position from, Position to)
 {
     if (chessGame.chessboard[from.row, from.column] == null)
     {
         MessageBox.Show("There is no chess piece at from-position!", "From-position error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         txtFrom.Clear();
         txtFrom.Focus();
         return(false);
     }
     else if (chessGame.chessboard[from.row, from.column].color != chessGame.turn)
     {
         MessageBox.Show("That is not your chess piece!", "From-position error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         txtFrom.Clear();
         txtFrom.Focus();
         return(false);
     }
     else if (!chessGame.ValidMove(chessGame.chessboard[from.row, from.column], from, to))
     {
         MessageBox.Show("That is not a valid move!", "Move error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         txtFrom.Focus();
         return(false);
     }
     else if (!chessGame.AvailableMove(chessGame.chessboard[from.row, from.column], from, to))
     {
         MessageBox.Show("There are pieces in the way!", "Move error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         txtFrom.Focus();
         return(false);
     }
     else if (chessGame.chessboard[to.row, to.column] != null && chessGame.chessboard[to.row, to.column].color == chessGame.turn)
     {
         MessageBox.Show("There already is a chess piece of your color at the to-position!", "Move error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         txtFrom.Focus();
         return(false);
     }
     return(true);
 }
Пример #23
0
 public void setChessGame(ChessGame chessGame)
 {
     this.chessgame = chessGame;
 }
Пример #24
0
        static void Main(string[] args)
        {
            ChessGame jogo = new ChessGame();

            jogo.GameLoop();
        }
Пример #25
0
        private ChessGame CreateGame()
        {
            ChessGame game = new ChessGame();
            game.Player = this.Player;
            game.cbcBoard.Turn = false;
            game.txtTurn.Text = "Other Players Turn";
            game.cbcBoard.Moved = (b, m) =>
            {
                Square A = game.cbcBoard.Board[m.A];
                Square B = game.cbcBoard.Board[m.B];

                if (A.Piece != null && A.Piece.TotallyValidMoves.Contains(B))
                {
                    game.txtTurn.Text = "Other Players Turn";
                    this.Player.Move(m);
                }

                return false;
            };
            this.Player.Moved += (p, m) => game.cbcBoard.InvokeIfRequired(() => { game.cbcBoard.Turn = false; game.cbcBoard.Board[m.A].To(game.cbcBoard.Board[m.B]); game.cbcBoard.Repaint(); });
            this.Player.PlayerColorChanged += (p, c) => game.cbcBoard.InvokeIfRequired(() => { game.cbcBoard.Player = c; game.cbcBoard.Repaint(); });
            this.Player.MyTurn += p => { game.cbcBoard.Turn = true; game.InvokeIfRequired(() => { game.txtTurn.Text = "Your Turn"; }); };
            game.Closed += (o, ea) => { this.Toggle(true); this.Activate(); };
            return game;
        }
Пример #26
0
        public bool IsClearPath(ChessGame game, BoardInternal game2, string move) //is the path clear?
        {
            var src = move.Substring(0, 2);
            var dst = move.Substring(2, 2);
            //real in memory coordinates..
            int srank = GetRank(src);           //source rank
            int sfile = GetFile(src);           //source file
            int drank = GetRank(dst);           //dest rank
            int dfile = GetFile(dst);           //dest file

            //if its any piece moving just one square then no spaces in between to check
            if ((Math.Abs(srank - drank) <= 1) && (Math.Abs(sfile - dfile) <= 1))
            {
                return(true);
            }
            //if a knight is moving return true as they just jump over things so dont need to check spaces
            if (" N n".Contains(GetVal(game.Board, move.Substring(0, 2))))
            {
                return(true);
            }

            //check spaces in between all other moves
            ///////// horizontal?
            if (Math.Abs(srank - drank) == 0)                     // y(rank) coordinate of src to dst not varying so moving horizontally
            {
                if (sfile < dfile)                                //x(file) moving right
                {
                    for (int i = sfile + 1; i < dfile; i++)       //so move along to the rank to the right by incrementing i
                    {
                        if (GetVal(game.Board, srank, i) != "  ") //checking each square for blank
                        {
                            return(false);                        //if its not blank then something is in the way
                        }
                    }
                    return(true);
                }
                else                                              //moving to left
                {
                    for (int i = sfile - 1; i > dfile; i--)       //so move along to the rank to the left by decrementing i
                    {
                        if (GetVal(game.Board, srank, i) != "  ") //checking each square for blank
                        {
                            return(false);                        //if its not blank then something is in the way
                        }
                    }
                    return(true);
                }
            }
            //////////////////////
            ///////// vertical?
            if (Math.Abs(sfile - dfile) == 0)                     // x(file) coordinate of src to dst not varying so moving vertically
            {
                if (srank > drank)                                //y(rank) moving down
                {
                    for (int i = srank - 1; i > drank; i--)       //so move up the file by decrementing i
                    {
                        if (GetVal(game.Board, i, sfile) != "  ") //checking each square for blank
                        {
                            return(false);                        //if its not blank then something is in the way
                        }
                    }
                    return(true);
                }
                else                                              //moving up the file
                {
                    for (int i = srank + 1; i < drank; i++)       //so move down the file by decrementing i
                    {
                        if (GetVal(game.Board, i, sfile) != "  ") //checking each square for blank
                        {
                            return(false);                        //if its not blank then something is in the way
                        }
                    }
                    return(true);
                }
            }

            //diagonal ? if the absolute difference between the source rank and the destination rank is the same
            //           as the file source and destination difference then it is diagonal movement
            int j;

            if (Math.Abs(srank - drank) == Math.Abs(sfile - dfile)) //this means it is diagonal movement
            {
                if (srank < drank)                                  //moving down the board (from the black side to the white side - source rank < destination rank)
                {
                    if (sfile < dfile)                              //so, moving generally from 0,0 towards 7,7 (in memory coordinates) top left to bottom right
                    {
                        j = sfile + 1;                              //start checks on the second square as the start square is where the piece is coming from
                        for (int i = srank + 1; i < drank; i++)     //move along the diagonal with increasing rank, dont need to check the last square.. that has already been done in a previous method
                        {
                            if (GetVal(game.Board, i, j) != "  ")   //checking for non blank square
                            {
                                return(false);
                            }
                            j++;                                    //increment the file coordinate
                        }
                    }
                    else
                    {                                             //so, moving generally from 0,7 towards 7,0 (in memory coordinates) top right to bottom left
                        j = sfile - 1;
                        for (int i = srank + 1; i < drank; i++)   //move along the diagonal with increasing rank
                        {
                            if (GetVal(game.Board, i, j) != "  ") //checking for non blank square
                            {
                                return(false);
                            }
                            j--;                                    //decrement the file coordinate
                        }
                    }
                    return(true);
                }
                if (srank > drank)          //moving up the board (from the white side to the black side - source rank > destination rank)
                {
                    if (sfile < dfile)      //so, moving generally from 7,0 towards 0,7 (in memory coordinates) bottom left to top right
                    {
                        j = sfile + 1;
                        for (int i = srank - 1; i > drank; i--)   //move along the diagonal with decreasing rank
                        {
                            if (GetVal(game.Board, i, j) != "  ") //checking for non blank square
                            {
                                return(false);
                            }
                            j++;                                    //increment the file coordinate
                        }
                    }
                    else
                    {                                             //so, moving generally from 7,7 towards 0,0 (in memory coordinates) bottom right to top left
                        j = sfile - 1;
                        for (int i = srank - 1; i > drank; i--)   //move down along the diagonal with decreasing rank
                        {
                            if (GetVal(game.Board, i, j) != "  ") //checking for non blank square
                            {
                                return(false);
                            }
                            j--;                                    //decrement the file coordinate
                        }
                    }
                    return(true);
                }
            }
            return(true);
        }
Пример #27
0
 public GameForm()
 {
     InitializeComponent();
     Board = new Board();
     game  = new ChessGame();
 }
Пример #28
0
        public bool IsPieceMoveValid(ChessGame game, string move)
        {
            MoveModel mm = GetMoveCoordsAndPiece(game, move);

            //If castling
            if ((move == "0") || (move == "00"))
            {
                if (IsCastlingValid(game, move))
                {
                    return(true);
                }
                return(false);
            }

            switch (mm.srcval)
            {
            case " r":
            case " R":
                if (!IsMovingLikeARook(mm.xsrc, mm.ysrc, mm.xdst, mm.ydst))
                {
                    return(false);
                }
                break;

            case " n":
            case " N":
                if (!IsMovingLikeAKnight(mm.xsrc, mm.ysrc, mm.xdst, mm.ydst))
                {
                    return(false);
                }
                break;

            case " b":
            case " B":
                if (!IsMovingLikeABishop(mm.xsrc, mm.ysrc, mm.xdst, mm.ydst))
                {
                    return(false);
                }
                break;

            case " q":
            case " Q":
                if (!IsMovingLikeAQueen(mm.xsrc, mm.ysrc, mm.xdst, mm.ydst))
                {
                    return(false);
                }
                break;

            case " k":
            case " K":
                if (!IsMovingLikeAKing(mm.xsrc, mm.ysrc, mm.xdst, mm.ydst))
                {
                    return(false);
                }
                break;

            case " p":
                if (!IsMovingLikeABlackPawn(mm.dstval, mm.xsrc, mm.ysrc, mm.xdst, mm.ydst))
                {
                    return(false);
                }
                break;

            case " P":
                if (!IsMovingLikeAWhitePawn(mm.dstval, mm.xsrc, mm.ysrc, mm.xdst, mm.ydst))
                {
                    return(false);
                }
                break;

            default:
                break;
            }
            return(true);
        }
Пример #29
0
 public King(GameBoard board, Color color, ChessGame game) : base(board, color)
 {
     this.game = game;
 }
Пример #30
0
 //Constructor
 public King(Color color, BoardTable board, ChessGame game) : base(color, board)
 {
     Game = game;
 }
Пример #31
0
        public void OnEndGame(PSide side, ChessGame.EndGames endType)
        {
            PlaySound(Sounds.endgame);
            switch(endType)
            {
                case (ChessGame.EndGames.Checkmate): { MessageBox.Show(null, side.ToString() + " has been checkmated!", "Game over", MessageBoxButtons.OK, MessageBoxIcon.Information); break; }
                case (ChessGame.EndGames.Draw): { MessageBox.Show(null, "Game drawn, 50/50", "Game over", MessageBoxButtons.OK, MessageBoxIcon.Information); break; }
                case (ChessGame.EndGames.Stalemate): { MessageBox.Show(null, "StaleMate, 50/50", "Game over", MessageBoxButtons.OK, MessageBoxIcon.Information); break; }
            }

            btn_reset.Enabled = true;
        }
Пример #32
0
 static void Main()
 {
     using (var game = new ChessGame())
         game.Run();
 }
Пример #33
0
        public bool IsCastlingValid(ChessGame game, string move)
        {
            if (!IsEmptySquaresInBetween(game, move))
            {
                return(false);
            }

            string src;

            if (game.Moves.Count % 2 == 0)
            {
                //white moving
                for (int i = 0; i < game.Moves.Count; i++)        //look at all previous moves
                {
                    src = game.Moves.ElementAt(i).Substring(0, 2);
                    if (src == "e1")                            //if the king has already been moved then castling is not allowed
                    {
                        return(false);
                    }

                    if (move == "0")                        //king side castle
                    {
                        if (src == "h1")                    //castle on king side has already moved
                        {
                            return(false);
                        }
                    }
                    else                                    //must be queen side castle - 00
                    {
                        if (src == "a1")                    //castle on queen side has already moved
                        {
                            return(false);
                        }
                    }
                }
            }
            else
            {
                //black castling
                for (int i = 0; i < game.Moves.Count; i++)        //look at all previous moves
                {
                    src = game.Moves.ElementAt(i).Substring(0, 2);
                    if (src == "e8")                            //if the king has already been moved then castling is not allowed
                    {
                        return(false);
                    }

                    if (move == "0")                        //king side castle
                    {
                        if (src == "h8")                    //castle on king side has already moved
                        {
                            return(false);
                        }
                    }
                    else                                    //must be queen side castle - 00
                    {
                        if (src == "a8")                    //castle on queen side has already moved
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }