예제 #1
0
        private bool PlaceMove(VisualNode move)
        {
            if (_game.GameEnded)
            {
                return false;
            }

            if (move == null)
            {
                MessageBox.Show("Cannot place the move there!");
                return false;
            }

            s_moves.Push(move);

            tslMoveCount.Text = $"Move: {s_moves.Count}";

            Refresh();

            NodeLocation winDirection;
            if (_game.IsWinningMove(move, out winDirection))
            {
                _game.GameEnded = true;
                // Mark the wining nodes.
                _game.MarkWinningNodes(move, winDirection);
                Refresh();

#if !COMPUTER_AGAINST_ITSELF
                MessageBox.Show($"Winner is player {CurrentPlayer}!!!");
#else

                if (CurrentPlayer == TicTacToeValue.x)
                    winX++;
                else
                    winO++;

                if (s_moves.Count > maxMove)
                    maxMove = s_moves.Count;
                if (s_moves.Count < minMove)
                    minMove = s_moves.Count;

                label3.Text = $"X: {winX}, O: {winO}, min:{minMove}, max:{maxMove}";
#endif

                _game = new TicTacToeGame(NeededForWin);
                s_moves.Clear();
                CurrentPlayer = TicTacToeValue.x;
                tslMoveCount.Text = "";
                Refresh();

#if COMPUTER_AGAINST_ITSELF
                PlaceAIMove();
#endif
                return true;
            }
            else
            {
                ChangePlayer();

#if COMPUTER_AGAINST_ITSELF
                PlaceAIMove();
#endif
            }

            Application.DoEvents();
            return false;
        }