Beispiel #1
0
        private static BoardAnalysisWeights AdjustWeights(BoardAnalysisWeights oldWeights, BoardAnalysisWeightAdjustment weightsAdjustment)
        {
            BoardAnalysisWeights newWeights = oldWeights;

            newWeights.articulationPointDiffWeight   += weightsAdjustment.articulationPointAdj;
            newWeights.hivailableSpaceDiffWeight     += weightsAdjustment.hivailableSpaceAdj;
            newWeights.possibleMovesDiffWeight       += weightsAdjustment.possibleMovesAdj;
            newWeights.queenBreathingSpaceDiffWeight += weightsAdjustment.queenBreathingAdj;
            newWeights.unplayedPiecesDiffWeight      += weightsAdjustment.unplayedPiecesAdj;
            newWeights.ownedBeetleStacksWeight       += weightsAdjustment.ownedBeetleAdj;
            return(newWeights);
        }
Beispiel #2
0
 public JohnnyHive(BoardAnalysisWeights weights, string name)
     : this(weights)
 {
     _name = name;
 }
Beispiel #3
0
 public JohnnyHive(BoardAnalysisWeights weights)
 {
     _weights = weights;
 }
Beispiel #4
0
 public JohnnyDeep(BoardAnalysisWeights weights, int depth, string name)
     : this(weights, depth)
 {
     _name = name;
 }
Beispiel #5
0
 public JohnnyDeep(BoardAnalysisWeights weights, int depth)
 {
     _weights = weights;
     _depth   = depth;
 }
Beispiel #6
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);
        }