コード例 #1
0
ファイル: Program.cs プロジェクト: vfridell/HiveLib
        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);
        }
コード例 #2
0
ファイル: JohnnyHive.cs プロジェクト: vfridell/HiveLib
 public JohnnyHive(BoardAnalysisWeights weights, string name)
     : this(weights)
 {
     _name = name;
 }
コード例 #3
0
ファイル: JohnnyHive.cs プロジェクト: vfridell/HiveLib
 public JohnnyHive(BoardAnalysisWeights weights)
 {
     _weights = weights;
 }
コード例 #4
0
ファイル: JohnnyDeep.cs プロジェクト: vfridell/HiveLib
 public JohnnyDeep(BoardAnalysisWeights weights, int depth, string name)
     : this(weights, depth)
 {
     _name = name;
 }
コード例 #5
0
ファイル: JohnnyDeep.cs プロジェクト: vfridell/HiveLib
 public JohnnyDeep(BoardAnalysisWeights weights, int depth)
 {
     _weights = weights;
     _depth   = depth;
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: vfridell/HiveLib
        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);
        }