Ejemplo n.º 1
0
 public void QuitGame()
 {
     if (_game != null)
     {
         _game = null;
         _jd   = null;
     }
 }
Ejemplo n.º 2
0
 public void BeginNewGame(bool aiPlayingWhite, string otherPlayerName)
 {
     _jd = new JohnnyDeep(BoardAnalysisWeights.winningWeights, 3);
     _jd.BeginNewGame(aiPlayingWhite);
     if (aiPlayingWhite)
     {
         _game = Game.GetNewGame(_jd.Name, otherPlayerName);
     }
     else
     {
         _game = Game.GetNewGame(otherPlayerName, _jd.Name);
     }
 }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            do
            {
                IHiveAI AI  = new JohnnyDeep(BoardAnalysisWeights.winningWeights, 3);
                IHiveAI AI2 = new JohnnyDeep(BoardAnalysisWeights.foundWeights1, 3, "foundWeights1");

                YesNo yn = PromptYesOrNo(string.Format("Is {0} playing white? ", AI.Name));

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

                AI.BeginNewGame(yn == YesNo.Yes);
                AI2.BeginNewGame(yn == YesNo.No);

                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());

                Console.WriteLine(GetWinnerString(game));
                if (PromptYesOrNo("Write out game transcript?") == YesNo.Yes)
                {
                    string filename = Game.WriteGameTranscript(game);
                    Console.WriteLine("Written to " + filename);
                }
            } while (PromptYesOrNo("Play again?") == YesNo.Yes);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            do
            {
                IHiveAI AI = new JohnnyDeep(BoardAnalysisWeights.winningWeights, 3);

                YesNo  yn           = PromptYesOrNo("Is this AI playing white? ");
                string opponentName = PromptForString("Enter the other player's name: ");

                Game game;
                if (yn == YesNo.Yes)
                {
                    game = Game.GetNewGame(AI.Name, opponentName);
                }
                else
                {
                    game = Game.GetNewGame(opponentName, AI.Name);
                }

                AI.BeginNewGame(yn == YesNo.Yes);

                do
                {
                    Board currentBoard = game.GetCurrentBoard();
                    Move  move;
                    if (game.whiteToPlay == AI.playingWhite)
                    {
                        DateTime beginTimestamp = DateTime.Now;
                        move = AI.MakeBestMove(game);
                        TimeSpan timespan = DateTime.Now.Subtract(beginTimestamp);
                        Console.WriteLine(string.Format("{0} seconds {1} Moved: {2}", timespan.TotalSeconds, AI.Name, Move.GetMoveWithNotation(move, currentBoard).notation));
                    }
                    else
                    {
                        move = PromptForMove("Enter your move: ", game);
                        Console.WriteLine(string.Format("{0} Moved: {1}", opponentName, Move.GetMoveWithNotation(move, currentBoard).notation));
                    }
                } while (game.gameResult == GameResult.Incomplete);

                Console.WriteLine(GetWinnerString(game));
                if (PromptYesOrNo("Write out game transcript?") == YesNo.Yes)
                {
                    string filename = Game.WriteGameTranscript(game);
                    Console.WriteLine("Written to " + filename);
                }
            } while (PromptYesOrNo("Play again?") == YesNo.Yes);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            BoardAnalysisWeights bestWeights = BoardAnalysisWeights.winningWeights;
            bool testPlayingWhite            = true;
            var  adjustments = GetAllAdjustments(new BoardAnalysisWeightAdjustment());

            // tuple is <#of moves in game, adjustments win, weights>
            var  gameResultsList    = new List <Tuple <int, bool, BoardAnalysisWeightAdjustment, BoardAnalysisWeights> >();
            var  winningResultsList = new List <Tuple <int, bool, BoardAnalysisWeightAdjustment, BoardAnalysisWeights> >();
            bool keepGoing          = true;

            do
            {
                BoardAnalysisWeights testWeights = bestWeights;
                foreach (BoardAnalysisWeightAdjustment adj in adjustments)
                {
                    var     adjustedWeights = AdjustWeights(testWeights, adj);
                    IHiveAI AI  = new JohnnyDeep(BoardAnalysisWeights.winningWeights, 1);
                    IHiveAI AI2 = new JohnnyDeep(adjustedWeights, 1, "TestWeights");

                    AI.BeginNewGame(!testPlayingWhite);
                    AI2.BeginNewGame(testPlayingWhite);

                    Game game = PlayGame(AI, AI2);

                    bool testWon = TestWon(game.gameResult, testPlayingWhite);
                    gameResultsList.Add(new Tuple <int, bool, BoardAnalysisWeightAdjustment, BoardAnalysisWeights>(game.turnNumber, testWon, adj, adjustedWeights));
                    if (testWon)
                    {
                        winningResultsList.Add(new Tuple <int, bool, BoardAnalysisWeightAdjustment, BoardAnalysisWeights>(game.turnNumber, testWon, adj, adjustedWeights));
                        Console.WriteLine(string.Format("We have a contender!"));
                        Console.WriteLine(adjustedWeights.ToString());
                        Console.WriteLine(string.Format("---===PLAY OFF===---"));
                        Game playoffGame;
                        int  wins             = 0;
                        int  draws            = 0;
                        bool playoffTestWhite = !testPlayingWhite;
                        for (int i = 0; i < 10; i++)
                        {
                            AI.BeginNewGame(!playoffTestWhite);
                            AI2.BeginNewGame(playoffTestWhite);

                            playoffGame = PlayGame(AI, AI2);
                            if (TestWon(playoffGame.gameResult, playoffTestWhite))
                            {
                                wins++;
                            }
                            if (playoffGame.gameResult == GameResult.Draw || playoffGame.gameResult == GameResult.Incomplete)
                            {
                                draws++;
                            }
                        }
                        Console.WriteLine("Wins: {0}, Losses: {1}, Draws: {2}", wins, 10 - wins - draws, draws);
                        if (wins + draws >= 5)
                        {
                            Console.WriteLine("*_*_*_*_*_*_**CHECK IT OUT!!!");
                        }
                        else
                        {
                            Console.WriteLine("Nothing special, moving on");
                        }
                    }
                    Console.WriteLine(string.Format("Finished Game: {0}", testWon ? "Win" : "Loss"));
                }

                var bestResults = gameResultsList.OrderByDescending(t => (t.Item2 ? 10000 - t.Item1 : 1000 + t.Item1)).First();
                if (bestWeights.Equals(bestResults.Item4))
                {
                    keepGoing = false;
                }
                bestWeights = bestResults.Item4;
                adjustments = GetAllAdjustments(bestResults.Item3);
            } while (keepGoing);
        }