Esempio n. 1
0
 public override Task GameStart(IHiveAI AI, Game game)
 {
     return(Task.Run(() =>
     {
         Move move = AI.PickBestMove(game.GetCurrentBoard());
         game.TryMakeMove(move);
     }));
 }
Esempio n. 2
0
 private void ClearDisplay()
 {
     MovesListBox.Items.Clear();
     _currentBoard = null;
     _game         = null;
     MainCanvas.Children.Clear();
     _imageToPieceMap.Clear();
     _unplayedImageToPieceMap.Clear();
     _tempUIElements.Clear();
     _player1AI = null;
     _player2AI = null;
 }
Esempio n. 3
0
        private void NewGameExecute(object sender, ExecutedRoutedEventArgs e)
        {
            var newGameWindow = new NewGameWindow();

            newGameWindow.ShowDialog();
            if (newGameWindow.DialogResult.HasValue && newGameWindow.DialogResult.Value)
            {
                ClearDisplay();
                if (newGameWindow.Parameters.player1 != null)
                {
                    _player1AI = newGameWindow.Parameters.player1;
                    _player1AI.BeginNewGame(true);
                }
                else
                {
                    _player1AI = null;
                }

                if (newGameWindow.Parameters.player2 != null)
                {
                    _player2AI = newGameWindow.Parameters.player2;
                    _player2AI.BeginNewGame(false);
                }
                else
                {
                    _player2AI = null;
                }

                _game = Game.GetNewGame(_player1AI == null ? newGameWindow.Parameters.player1Name : _player1AI.Name,
                                        _player2AI == null ? newGameWindow.Parameters.player2Name : _player2AI.Name);
                _currentBoard = _game.GetCurrentBoard();
                DrawBoard(_currentBoard);

                if (_player1AI != null && _player2AI != null)
                {
                    RunAIOnlyGame();
                }
                else
                {
                    MakeAIMoveIfNecessary();
                }
            }
        }
Esempio n. 4
0
 internal bool TryGetAIForTurn(out IHiveAI ai)
 {
     ai = null;
     if (_game.GetCurrentBoard().gameResult == GameResult.Incomplete && !_game.ThreeFoldRepetition())
     {
         if (_currentBoard.whiteToPlay)
         {
             if (_player1AI != null && _player1AI.playingWhite)
             {
                 ai = _player1AI; return(true);
             }
             else if (_player2AI != null && _player2AI.playingWhite)
             {
                 ai = _player2AI; return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             if (_player1AI != null && !_player1AI.playingWhite)
             {
                 ai = _player1AI; return(true);
             }
             else if (_player2AI != null && !_player2AI.playingWhite)
             {
                 ai = _player2AI; return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     else
     {
         return(false);
     }
 }
Esempio n. 5
0
        private static Game PlayGame(IHiveAI AI, IHiveAI AI2)
        {
            Game game;

            if ((AI.playingWhite && AI2.playingWhite) || (!AI.playingWhite && !AI2.playingWhite))
            {
                throw new Exception("Please decide who will be what color!");
            }

            if (AI.playingWhite)
            {
                game = Game.GetNewGame(AI.Name, AI2.Name);
            }
            else
            {
                game = Game.GetNewGame(AI2.Name, AI.Name);
            }

            do
            {
                Board   currentBoard = game.GetCurrentBoard();
                Move    move;
                IHiveAI currentAI;
                if (game.whiteToPlay == AI.playingWhite)
                {
                    currentAI = AI;
                }
                else
                {
                    currentAI = AI2;
                }
                //DateTime beginTimestamp = DateTime.Now;
                move = currentAI.MakeBestMove(game);
                //TimeSpan timespan = DateTime.Now.Subtract(beginTimestamp);
                //Console.WriteLine(string.Format("{0} seconds {1} Moved: {2}", timespan.TotalSeconds, currentAI.Name, Move.GetMoveWithNotation(move, currentBoard).notation));
            } while (game.gameResult == GameResult.Incomplete && !game.ThreeFoldRepetition());
            return(game);
        }
Esempio n. 6
0
 public override void GameEnd(IHiveAI AI, Game game)
 {
     throw new NotImplementedException();
 }
Esempio n. 7
0
 public override void ReadyForMove(IHiveAI AI, Game game)
 {
     //
 }
Esempio n. 8
0
 public override void GameEnd(IHiveAI AI, Game game)
 {
     // do nothing
 }
Esempio n. 9
0
 public override Task GameStart(IHiveAI AI, Game game)
 {
     // do nothing
     return(Task.FromResult <object>(null));
 }
Esempio n. 10
0
 public abstract void GameEnd(IHiveAI AI, Game game);
Esempio n. 11
0
 public abstract Task GameStart(IHiveAI AI, Game game);
Esempio n. 12
0
 public abstract void ReadyForMove(IHiveAI AI, Game game);