Exemplo n.º 1
0
        private void TryToPlayAsAI()
        {
            IActionGenerator <GameState, GameAction, Player> currentAI = CurrentAI;

            if (currentAI != null)
            {
                if (currentState.IsFinal == false)
                {
                    //Task.Delay(1000).ContinueWith(t =>
                    //{
                    GameAction gameAction = currentAI.GenerateAction(currentState);
                    GameState  nextState  = TicTacToeGame.Instance.Play(currentState, gameAction);

                    //Invoke((MethodInvoker)delegate
                    //{
                    if (nextState == null)
                    {
                        MessageBox.Show($"The {currentState.CurrentPlayer.FieldState} lost by illegal move.");
                    }
                    else
                    {
                        boardControl.BoardState = nextState;
                        currentState            = nextState; MovePlayed();
                    }
                    //});
                    //});
                }
            }
        }
Exemplo n.º 2
0
        private void TryToPlayAsAI()
        {
            IActionGenerator <GameState, GameAction, Player> currentAI = CurrentAI;

            if (currentAI != null)
            {
                if (currentState.IsFinal == false)
                {
                    GameAction gameAction = currentAI.GenerateAction(currentState);
                    GameState  nextState  = TicTacToeGame.Instance.Play(currentState, gameAction);

                    if (nextState == null)
                    {
                        MessageBox.Show($"The {currentState.CurrentPlayer.FieldState} lost by illegal move.");
                    }
                    else
                    {
                        boardControl.BoardState = nextState;
                        currentState            = nextState;
                        MovePlayed();
                    }
                }
            }
        }
Exemplo n.º 3
0
 private void buttonPlay_Click(object sender, EventArgs e)
 {
     Nought = LoadAIEngine(noughtPlayerControl);
     Cross  = LoadAIEngine(crossPlayerControl);
 }
Exemplo n.º 4
0
 public TicTacToeGameForm(IActionGenerator <GameState, GameAction, Player> noughtAI, IActionGenerator <GameState, GameAction, Player> crossAI) : this()
 {
     NoughtAI = noughtAI;
     CrossAI  = crossAI;
 }