Exemplo n.º 1
0
 public Board()
 {
     spaces      = new ChessPiece[8, 8];
     whitePlayer = new ChessPlayer(true);
     blackPlayer = new ChessPlayer(false);
     boardBMP    = Properties.Resources.board;
     InitializeBoard();
 }
Exemplo n.º 2
0
        public void Run(ChessPlayer player)
        {
            double best = int.MinValue;



            foreach (Move move in  currentBoard.GetOrderedMoves(player))
            {
                currentBoard.MakeMove(move);
                double value = -AlphaBeta(depth - 1, int.MinValue, int.MaxValue, player is Computer ? MainWindow.Player1 : MainWindow.Player2);
                if (value > best)
                {
                    bestMove = move;
                    best     = value;
                }

                currentBoard.UndoMove(move);
            }
        }
Exemplo n.º 3
0
        public Piece(Point position, ChessPieces pi, bool isblack)
        {
            isBlack       = isblack;
            this.position = position;
            pieceType     = pi;
            if (this.isBlack && MainWindow.Player1.isBlack)
            {
                player   = MainWindow.Player1;
                opposite = MainWindow.Player2;
            }
            else
            {
                player   = MainWindow.Player2;
                opposite = MainWindow.Player1;
            }



            this.SizeMode = PictureBoxSizeMode.StretchImage;
            this.Size     = new Size(40, 40);
        }
Exemplo n.º 4
0
        public List <Move> GetOrderedMoves(ChessPlayer player)
        {
            List <Move> possibleMoves = new List <Move>();

            possibleMoves.Clear();

            foreach (BoardTile bd in grid)
            {
                if (bd.IsOccuppied())
                {
                    if ((bd.GetPiece().IsBlack() && player.isBlack) || (!bd.GetPiece().IsBlack() && !player.isBlack))
                    {
                        List <Point> points = bd.GetPiece().GetPoints();

                        for (int i = 1; i < points.Count; i++)
                        {
                            possibleMoves.Add(new Move(bd.GetPiece().position, points[i]));
                        }
                    }
                }
            }
            return(possibleMoves);
        }
Exemplo n.º 5
0
        private void buttonMove_Click(object sender, EventArgs e)
        {
            ChessFigure figureToMove = GetFigure();

            if (figureToMove == null)
            {
                if (comboFrom.Text.Contains("Give In"))
                {
                    MessageBox.Show("You lose!");
                    GameBegins();
                    return;
                }
                if (comboFrom.Text.Contains("Draw"))
                {
                    DialogResult result = MessageBox.Show("Other player, do you want to draw?", "Draw proposal",
                                                          MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        MessageBox.Show("Draw!");
                        GameBegins();
                    }
                    return;
                }

                ChessKing        king  = Game.CurrentPlayer.Figures.OfType <ChessKing>().First();
                List <ChessRook> rooks = Game.CurrentPlayer.Figures.OfType <ChessRook>().ToList();
                ChessRook        rook  = null;
                if (comboFrom.Text == "Long Roque")
                {
                    rook = rooks.First(r => r.CurrentField.Column == 'A');
                }
                if (comboFrom.Text == "Short Roque")
                {
                    rook = rooks.First(r => r.CurrentField.Column == 'H');
                }
                if (rook == null)
                {
                    return;
                }
                rook.MakeRoque(Game.Board, king, Game.CurrentMoveNumber);
            }
            else
            {
                char[]      columnAndRow = comboTo.Text.ToCharArray();
                ChessField  field        = Game.Board.GetField(int.Parse(columnAndRow[1].ToString()), columnAndRow[0]);
                ChessPlayer enemy        = Game.CurrentPlayer.Color == ChessColor.WHITE ? Game.BlackPlayer : Game.WhitePlayer;
                figureToMove.Move(field, enemy, Game.Board, Game.CurrentMoveNumber, Game.CurrentPlayer.Figures);
            }

            bool check = Check();
            bool mate  = CheckMate();

            Game.ChangePlayer();
            DrawFigures();
            PrepareFigures();
            if (mate)
            {
                MessageBox.Show("MATE!");
                GameBegins();
            }
            else if (check)
            {
                MessageBox.Show("CHECK!");
            }
        }