コード例 #1
0
            public PlayerZones(int playerIndex, Style.IStyleContainer parent, XElement styleDefinition)
            {
                var layout = new Style.LayoutGizmo<UI.TransformNode>(parent, styleDefinition);
                layout.Initialize();
                layout.Target.Dispatcher = parent.Target;
                layout.BindingProvider = this;
                UIStyle = layout;
                PlayerIndex = playerIndex;

                m_manaTextEvaluator = GameApp.Service<GameManager>().CreateGameEvaluator(game =>
                {
                    var player = game.Players[PlayerIndex];
                    return player.Mana != 0 || player.MaxMana != 0
                           ? player.Mana.ToString() + "/" + player.MaxMana.ToString()
                           : "0";
                }, "-");

                Library = new CardZone(UIStyle.ChildIds["Library"]);
                Hand = new CardZone(UIStyle.ChildIds["Hand"]);
                Sacrifice = new CardZone(UIStyle.ChildIds["Sacrifice"]);
                Battlefield = new CardZone(UIStyle.ChildIds["Battlefield"]);
                Hero = new CardZone(UIStyle.ChildIds["Hero"]);
                Assists = new CardZone(UIStyle.ChildIds["Assists"]);
                Graveyard = new CardZone(UIStyle.ChildIds["Graveyard"]);
            }
コード例 #2
0
ファイル: GameUI.Piles.cs プロジェクト: galaxyyao/TouhouGrave
        private void InitializePilesOnGameCreated(Game game)
        {
            var numPlayers = game.Players.Count;
            m_playerLibraryPiles = new UI.CardControl[numPlayers];
            m_playerLibraryPileCountEvaluators = new GameEvaluator<int>[numPlayers];
            for (int i = 0; i < numPlayers; ++i)
            {
                var ccStyle = new Style.CardControlStyle(GameApp.Service<Styler>().GetCardStyle("PileBack"), -1);
                ccStyle.Initialize();
                m_playerLibraryPiles[i] = ccStyle.TypedTarget;
                m_playerLibraryPiles[i].CardData = GameApp.Service<CardDataManager>().CreateDummyCardData(i);
                m_playerLibraryPiles[i].EnableDepth = true;

                int pid = i; // to force creating new lambdas based on the current value of i
                m_playerLibraryPileCountEvaluators[i] = GameApp.Service<GameManager>().CreateGameEvaluator(g => g.Players[pid].Library.Count, 0);
                m_playerLibraryPiles[i].Addins.Add(new UI.CardControlAddins.InstantRotation(m_playerLibraryPiles[i]));
                m_playerLibraryPiles[i].Addins.Add(new UI.CardControlAddins.Pile(m_playerLibraryPiles[i],
                    () => m_playerLibraryPileCountEvaluators[pid].Value));
                m_playerLibraryPiles[i].Dispatcher = m_playerZones[i].Library.Container;
            }

            // graveyard piles are created only when there are more than 1 cards in the graveyard
            // the last card entering graveyard will be displayed on the top
            m_playerGraveyardPiles = new UI.CardControl[numPlayers];
            m_graveyardCounters = new GraveyardCounters[numPlayers];
        }
コード例 #3
0
        public static PlayoutResult CalculateFitness(GameInstance game, DNA initialDna, DNA dna)
        {
            Constants.ResetLogBuffer();
            GameSetup.OverrideGameDna(game, initialDna, dna);

            var result = new GameEvaluator(game, Console.Out).Evaluate();

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Runs a small benchmark on MCTS whcih keeps playing the same game in a loop.
        /// This is used mostly for profiling the internals of MCTS.
        /// </summary>
        public void RunMctsProfiling()
        {
            var s = Stopwatch.StartNew();

            CoordRadiusCache.Instance.PrecomputeUpto(50);
            Console.WriteLine($"Cache precomputed in {s.Elapsed.TotalMilliseconds}ms");

            var game = GameSetup.GenerateForDnaSettings(2, 2);
            var c    = new MctsController(game, 500);

            {
                var       totalStopwatch  = Stopwatch.StartNew();
                var       stopwatch       = new Stopwatch();
                var       iterations      = 0;
                const int dumpIterations  = 1;
                const int totalIterations = 500000;

                while (iterations < totalIterations)
                {
                    iterations++;

                    stopwatch.Start();
                    GameEvaluator.Playout(game, c, c);
                    stopwatch.Stop();

                    if (iterations % dumpIterations == 0)
                    {
                        double perThousandMs = Math.Round(stopwatch.Elapsed.TotalMilliseconds, 2);
                        double perGame       = Math.Round(perThousandMs / dumpIterations, 2);

                        Console.WriteLine(
                            $"TOTAL: {UctAlgorithm.TotalIterationCount}, " +
                            $"Actions: {ActionEvaluator.Actions}, " +
                            $"IterAVG: {UctAlgorithm.MillisecondsPerIterationAverage.Average:0.000000}ms\t" +
                            $"IPS: {1 / UctAlgorithm.MillisecondsPerIterationAverage.Average * 1000}\t" +
                            $"per game: {perGame:00.00}ms");

                        stopwatch.Reset();
                    }

                    game.Reset();
                }

                Console.WriteLine("Took {0}ms", totalStopwatch.ElapsedMilliseconds);
            }
        }
コード例 #5
0
        /// <summary>
        /// Runs a benchmark comparing two different AIs against each other on a fixed map.
        /// </summary>
        public static void CompareAi()
        {
            var dna = new DNA(2, 2);

            dna.Randomize();

            var map = Map.Load(@"data/map.json");

            var game = GameSetup.GenerateFromDna(dna, dna, map);

            game.PrepareEverything();

            GameInvariants.AssertMobsNotStandingOnEachother(game);

            IMobController c1, c2;

            switch (Constants.MctsBenchType)
            {
            case 0:
                c1 = new MctsController(game, Constants.MctsBenchIterations);
                c2 = new AiRandomController(game);
                break;

            case 1:
                c1 = new MctsController(game, Constants.MctsBenchIterations);
                c2 = new AiRuleBasedController(game);
                break;

            case 2:
                c1 = new AiRuleBasedController(game);
                c2 = new AiRandomController(game);
                break;

            default:
                throw new ArgumentException($"Invalid value of {Constants.MctsBenchType} for --MctsBenchType");
            }

            var iterationStopwatch = new Stopwatch();

            int c1Wins = 0;
            int c2Wins = 0;

            for (int i = 0; i < 1000; i++)
            {
                dna.Randomize();
                iterationStopwatch.Restart();

                GameSetup.OverrideGameDna(game, dna, dna);
                var r1 = GameEvaluator.Playout(game, c1, c2);

                GameSetup.OverrideGameDna(game, dna, dna);
                var r2 = GameEvaluator.Playout(game, c2, c1);

                iterationStopwatch.Stop();

                Console.WriteLine(Accounting.GetStats());

                c1Wins += r1.RedWins + r2.BlueWins;
                c2Wins += r1.BlueWins + r2.RedWins;

                Console.WriteLine($"{i.ToString("0000")} STATS: M2: {c1Wins}, M5: {c2Wins}, winrate: {((double)c1Wins/(c1Wins+c2Wins)).ToString("0.000")}");
            }
        }
コード例 #6
0
ファイル: MiniMaxStrategy.cs プロジェクト: mathjeff/SCGSim
 public MiniMaxStrategy(GameEvaluator evaluationHeuristic, int numTimeSteps)
 {
     this.GameEvaluator = evaluationHeuristic;
     this.NumTimeSteps  = numTimeSteps;
 }
コード例 #7
0
 public override void Startup()
 {
     m_evaluator = GameApp.Service<GameManager>().CreateGameEvaluator(game => OnGameEvaluate(game));
 }
コード例 #8
0
ファイル: GameManager.cs プロジェクト: galaxyyao/TouhouGrave
 public override void Startup()
 {
     m_actingPlayerIndexEvaluator = CreateGameEvaluator(game => game.ActingPlayer != null ? game.ActingPlayer.Index : -1, -1);
 }