コード例 #1
0
        //Async task to handle solving puzzle. Enables buttons when done
        async private void SolveAsync()
        {
            cts = new CancellationTokenSource();
            bool solved = true;

            try
            {
                await Task.Run(() => board.solve2(followAlgorithm, cts.Token));
            }
            catch (OperationCanceledException)
            {
                board.clear();
                Solvebutton.Enabled    = true;
                FollowCheckbox.Enabled = true;
                solved = false;
            }

            if (solved)
            {
                ClearButton.Enabled = true;
            }

            CancelButton_.Enabled  = false;
            GameBoardPanel.Enabled = true;
            GameBoardPanel.Invalidate();

            cts.Dispose();
        }
コード例 #2
0
ファイル: Game.cs プロジェクト: vroyibg/minimax-ai-chess
        private void GameBoardPanel_MouseClick(object sender, MouseEventArgs e)
        {
            int x = e.Y / (BoardHeight / 8), y = e.X / (BoardWidth / 8);

            if (ChessBoard.selecting == -1)
            {
                if (((char.IsUpper(ChessBoard.charBoard[x, y]) && ChessBoard.white) || (!char.IsUpper(ChessBoard.charBoard[x, y]) && !ChessBoard.white)) && ChessBoard.charBoard[x, y] != ' ')
                {
                    ChessBoard.selecting = x * 8 + y;
                    GameBoardPanel.Invalidate();
                }
            }
            else
            {
                if ((char.IsUpper(ChessBoard.charBoard[x, y]) && ChessBoard.white) & ChessBoard.charBoard[x, y] != ' ' || (!char.IsUpper(ChessBoard.charBoard[x, y]) && !ChessBoard.white) & ChessBoard.charBoard[x, y] != ' ')
                {
                    ChessBoard.UnSelect();
                    GameBoardPanel.Invalidate();
                    GameBoardPanel.Refresh();
                }
                else
                {
                    string move = ChessBoard.checkMove(x, y);
                    if (move != null)
                    {
                        ChessBoard.makeMove(move);
                        GameBoardPanel.Invalidate();
                        GameBoardPanel.Refresh();
                        if (ChessBoard.gameOver && ChessBoard.staledraw)
                        {
                            MessageBox.Show("Draw");
                        }
                        else
                        if (ChessBoard.gameOver)
                        {
                            MessageBox.Show(!ChessBoard.white ? "White won!" : "Black won!");
                        }
                        else
                        {
                            ChessBoard.makeBestMoves();
                            GameBoardPanel.Invalidate();
                            if (ChessBoard.gameOver && ChessBoard.staledraw)
                            {
                                MessageBox.Show("Draw");
                            }
                            else
                            if (ChessBoard.gameOver)
                            {
                                MessageBox.Show(!ChessBoard.white ? "White won!" : "Black won!");
                            }
                        }
                    }
                    else
                    {
                        ChessBoard.UnSelect();
                        GameBoardPanel.Invalidate();
                    }
                }
            }
        }
コード例 #3
0
        public Game()
        {
            InitializeComponent();
            initDifficultyComboBox();
            MaximizeBox     = false;
            FormBorderStyle = FormBorderStyle.FixedSingle;
            graphics        = GameBoardPanel.CreateGraphics();
            chessGame       = new ChessGame(BoardHeight, BoardWidth);
            init();
            chessGame.difficulty             = ChessGame.Difficulty.veryHard;
            difficultyComboBox.SelectedIndex = 3;
            playerVsComputerToolStripMenuItem_Click(null, null);

            //chessGame.startCoPGame_Test(graphics);
            //chessGame.drawGame(graphics);
            //whiteTurnPictureBox.Visible = true;
            //blackTurnPictureBox.Visible = false;
            //difficultyComboBox.Enabled = true;
            //heuristicValueTextBox.Enabled = true;
            //predictedHeuristicValue.Enabled = true;
            //difficultyComboBox.SelectedIndex = 3;
            //chessGame.doComputerMove(graphics);

            difficultyComboBox.Enabled = true;
        }
コード例 #4
0
 //Erase board. Resets board
 private void ClearButton_Click(object sender, EventArgs e)
 {
     board.clear();
     boardInUse             = false;
     Solvebutton.Enabled    = true;
     FollowCheckbox.Enabled = true;
     ClearButton.Enabled    = false;
     GameBoardPanel.Invalidate();
 }
コード例 #5
0
        //When mouse clicked inside panel, get location.
        private void P1_Click(object sender, EventArgs e)
        {
            boardInUse = true;

            int clickedBoxX = (int)Math.Floor((double)(GameBoardPanel.PointToClient(Cursor.Position).X / squareSize));
            int clickedBoxY = (int)Math.Floor((double)(GameBoardPanel.PointToClient(Cursor.Position).Y / squareSize));

            clickedBox = new Point(clickedBoxX, clickedBoxY);

            GameBoardPanel.Invalidate();
        }
コード例 #6
0
ファイル: Game.cs プロジェクト: vroyibg/minimax-ai-chess
 public void restartButtonClicked(object sender, MouseEventArgs e)
 {
     ChessBoard.init();
     GameBoardPanel.Invalidate();
 }
コード例 #7
0
ファイル: Game.cs プロジェクト: vroyibg/minimax-ai-chess
 private void UndoButton_Click(object sender, EventArgs e)
 {
     ChessBoard.undoMove();
     GameBoardPanel.Invalidate();
 }