private static void ComparePlayers(int gameCount, CardCountPair[] startingCards)
        {
            var gameLogFactory = new GameLogFactory();

            var player1 = Strategies.BigMoneyWithCard.Player(Cards.Witch, cardCount: 2);
            var player2 = Strategies.BigMoneyWithCard.Player(Cards.Witch, cardCount: 2);

            var builder = new GameConfigBuilder();

            PlayerAction.SetKingdomCards(builder, player1, player2);
            if (startingCards != null)
            {
                builder.SetStartingDeck(startingCards);
            }

            var gameConfig = builder.ToGameConfig();

            Program.ComparePlayers(
                Strategies.BigMoneyWithCard.Player(Cards.Witch, cardCount: 2),
                Strategies.BigMoneyWithCard.Player(Cards.Witch, cardCount: 2),
                gameConfig,
                firstPlayerAdvantage: true,
                numberOfGames: gameCount,
                createGameLog: new CreateGameLog(gameLogFactory.CreateGameLog));

            System.Console.WriteLine("Curses Split was Uneven {0}%", gameLogFactory.UnEvenSplitPercent);
            System.Console.WriteLine();
            System.Console.WriteLine("When the curses were not split, Player 1 won the curse split {0}/{1}", gameLogFactory.Player1WinPercent, gameLogFactory.Player2WinPercent);
        }
Exemple #2
0
        static void Main()
        {
            using (var testOutput = new TestOutput())
            {
                StrategyDescription descr1 = StrategyDescription.GetDefaultStrategyDescription().AddCardToPurchaseOrder(Cards.YoungWitch).AddCardToPurchaseOrder(Cards.Sage);
                StrategyDescription descr2 = StrategyDescription.GetDefaultStrategyDescription().AddCardToPurchaseOrder(Cards.SeaHag).AddCardToPurchaseOrder(Cards.Sage);

                //var player1 = Strategies.BigMoneyWithCard.Player(Cards.TreasureTrove, cardCount:10);
                //var player2 = Strategies.BigMoneyWithCard.Player(Cards.Gold);

                var player1 = descr1.ToPlayerAction("young witch");
                var player2 = descr2.ToPlayerAction("sea hag");

                var builder = new GameConfigBuilder();
                builder.SetBaneCard(Cards.Sage);
                builder.CardSplit = StartingCardSplit.Split43;
                builder.SetKingdomCards(player1, player2);

                testOutput.ComparePlayers(
                    player1,
                    player2,
                    builder.ToGameConfig(),
                    rotateWhoStartsFirst: true,
                    createHtmlReport: true,
                    numberOfGames: 1000,
                    shouldParallel: false);
            }
        }
Exemple #3
0
        static void FindOptimalPlayForEachCardWithBigMoney()
        {
            var bigMoneyPlayer = "BigMoney";

            foreach (var member in typeof(Cards).GetMembers(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public))
            {
                if (member.MemberType == System.Reflection.MemberTypes.Field)
                {
                    Card card = (Card)(typeof(Cards).GetField(member.Name).GetValue(null));
                    if (!GameConfigBuilder.IsKingdomCard(card))
                    {
                        continue;
                    }

                    if (notImplementedCards.Contains(card))
                    {
                        continue;
                    }

                    var playerAction = StrategyOptimizer.FindBestBigMoneyWithCardVsStrategy("BigMoney", card); // Strategies.BigMoneyWithCard.Player(card, "BigMoney<" + card.name + ">");

                    ComparePlayers(playerAction, bigMoneyPlayer, numberOfGames: 1000, shouldParallel: true, createHtmlReport: true, logGameCount: 0);
                }
            }
        }
Exemple #4
0
        public double Compare(PickByPriorityDescription leftPurchaseOrder, PickByPriorityDescription rightPurchaseOrder)
        {
            //System.Console.WriteLine("Comparing: ");
            //left.Write(System.Console.Out);
            //System.Console.WriteLine("");
            //right.Write(System.Console.Out);
            //System.Console.WriteLine("");
            PlayerAction leftPlayer    = new PlayerAction("Player1", leftPurchaseOrder.ToCardPicker());
            PlayerAction rightPlayer   = new PlayerAction("Player2", rightPurchaseOrder.ToCardPicker());
            int          numberOfGames = 33;

            GameConfigBuilder builder = new GameConfigBuilder();

            PlayerAction.SetKingdomCards(builder, leftPlayer, rightPlayer);

            var gameConfig           = builder.ToGameConfig();
            var rotateWhoStartsFirst = true;

            var strategyComparison = new Dominion.Data.StrategyComparison(leftPlayer, rightPlayer, gameConfig, rotateWhoStartsFirst, numberOfGames);

            var results = strategyComparison.ComparePlayers(
                gameIndex => null,
                gameIndex => null,
                shouldParallel: false,
                gatherStats: false,
                createGameLog: null);

            return(results.WinDifference);
        }
Exemple #5
0
        static PlayerAction[] AllBigMoneyWithCard()
        {
            var result = new List <PlayerAction>();

            foreach (var member in typeof(Cards).GetMembers(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public))
            {
                if (member.MemberType == System.Reflection.MemberTypes.Field)
                {
                    Card card = (Card)(typeof(Cards).GetField(member.Name).GetValue(null));
                    if (!GameConfigBuilder.IsKingdomCard(card))
                    {
                        continue;
                    }

                    if (notImplementedCards.Contains(card))
                    {
                        continue;
                    }

                    var playerAction = Strategies.BigMoneyWithCard.Player(card);
                    result.Add(playerAction);
                }
            }

            return(result.ToArray());
        }
Exemple #6
0
        internal StrategyComparisonResults GetResultsFor(ComparisonDescription descr)
        {
            StrategyComparisonResults result = null;

            if (!this.resultsCache.TryGetValue(descr, out result))
            {
                GameConfigBuilder builder       = new GameConfigBuilder();
                PlayerAction      playerAction1 = descr.Player1Action;
                PlayerAction      playerAction2 = descr.Player2Action;

                if (playerAction1 != null && playerAction2 != null)
                {
                    System.Console.WriteLine("Playing {0} vs {1}", playerAction1.PlayerName, playerAction2.PlayerName);
                    PlayerAction.SetKingdomCards(builder, new PlayerAction[] { playerAction1, playerAction2 });

                    var gameConfig = builder.ToGameConfig();

                    var strategyComparison = new StrategyComparison(playerAction1, playerAction2, gameConfig, rotateWhoStartsFirst: true, numberOfGames: 1000);
                    result = strategyComparison.ComparePlayers(
                        gameIndex => null,
                        gameIndex => null,
                        shouldParallel: true,
                        gatherStats: true);

                    this.resultsCache.Add(descr, result);
                }
                else
                {
                    this.resultsCache.Add(descr, null);
                }
            }

            return(result);
        }
        public static void SetKingdomCards(this GameConfigBuilder builder, params PlayerAction[] players)
        {
            var allCards = new HashSet <Card>();

            foreach (PlayerAction player in players)
            {
                PlayerAction.AddAllCards(allCards, player);
            }

            builder.SetKingdomPiles(allCards);
        }
Exemple #8
0
        public static void SetKingdomCards(GameConfigBuilder builder, params PlayerAction[] players)
        {
            var allCards = new List <Card>();

            foreach (PlayerAction player in players)
            {
                AddCards(allCards, player.actionOrder);
                AddCards(allCards, player.purchaseOrder);
                AddCards(allCards, player.gainOrder);
            }

            builder.SetKingdomPiles(allCards);
        }
Exemple #9
0
        public static double ComparePlayers(
            object player1OrString,
            object player2OrString,
            bool useShelters          = false,
            bool useColonyAndPlatinum = false,
            StartingCardSplit split   = StartingCardSplit.Random,
            bool firstPlayerAdvantage = false,
            IEnumerable <CardCountPair>[] startingDeckPerPlayer = null,
            bool shouldParallel         = true,
            bool showVerboseScore       = true,
            bool showCompactScore       = false,
            bool showDistribution       = false,
            bool createHtmlReport       = true,
            int numberOfGames           = 1000,
            int logGameCount            = 10,
            bool debugLogs              = false,
            CreateGameLog createGameLog = null)
        {
            PlayerAction player1 = strategyLoader.GetPlayerAction(player1OrString);
            PlayerAction player2 = strategyLoader.GetPlayerAction(player2OrString);

            GameConfigBuilder builder = new GameConfigBuilder();

            PlayerAction.SetKingdomCards(builder, player1, player2);

            builder.useColonyAndPlatinum = useColonyAndPlatinum;
            builder.useShelters          = useShelters;
            builder.CardSplit            = split;

            if (startingDeckPerPlayer != null)
            {
                builder.SetStartingDeckPerPlayer(startingDeckPerPlayer);
            }

            var gameConfig = builder.ToGameConfig();

            return(ComparePlayers(
                       player1,
                       player2,
                       gameConfig,
                       firstPlayerAdvantage: firstPlayerAdvantage,
                       shouldParallel: shouldParallel,
                       showVerboseScore: showVerboseScore,
                       showCompactScore: showCompactScore,
                       showDistribution: showDistribution,
                       createHtmlReport: createHtmlReport,
                       logGameCount: logGameCount,
                       debugLogs: debugLogs,
                       numberOfGames: numberOfGames,
                       createGameLog: createGameLog));
        }
Exemple #10
0
        public static Game CreateGame(UserInfo player1, UserInfo player2, GameConfigInfo gameConfigInfo)
        {
            var gameConfig = GameConfigBuilder.Create()
                             .SetPlayer1(player1.AccountName, player1.DeckData)
                             .SetPlayer2(player2.AccountName, player2.DeckData)
                             .SkipMulligan(gameConfigInfo.SkipMulligan)
                             .Shuffle(gameConfigInfo.Shuffle)
                             .FillDecks(gameConfigInfo.FillDecks)
                             .Logging(gameConfigInfo.Logging)
                             .History(gameConfigInfo.History)
                             .RandomSeed(gameConfigInfo.RandomSeed)
                             .Build();

            return(new Game(gameConfig));
        }
Exemple #11
0
        private void GetKeysFromGameConfig(SortedDictionary <string, LocalizationRecord> storage)
        {
            ConfigsLoader.LoadForEditorToolsIfNeeded();
            var config = GameConfig.Instance;
            Action <string, string> action = (key, value) => AddToStorage(storage, key, value,
                                                                          "From confluence or google tables, modify Ru there", Source.Config, PairStatus.New, "GameConfig");

            GameConfigBuilder.FillConfigWithLocalization(config, ConfigsLoader.GetConfigsSourcePath(ConfigsSourcePathType.Dev), action);
            // Hack since max edited all text in crowdin
            GameConfigBuilder.FillHackedTutorLevelLocalizations(config, ConfigsLoader.GetConfigsSourcePath(ConfigsSourcePathType.Dev),
                                                                (key, value) =>
            {
                AddToStorage(storage, key, value, "Modifiable from crowdin", Source.Code, PairStatus.New,
                             "GameConfig");
            });
        }
Exemple #12
0
        public static void Run()
        {
            GameConfig gameConfig = GameConfigBuilder.Create(
                StartingCardSplit.Split43,
                Cards.Bishop,
                Cards.FarmingVillage,
                Cards.GrandMarket,
                Cards.Hamlet,
                Cards.Hoard,
                Cards.Monument,
                Cards.Mountebank,
                Cards.PhilosophersStone,
                Cards.ScryingPool,
                Cards.Vineyard
                );

            Program.ComparePlayers("MountebankMonumentHamletVineyard", "BigMoney", gameConfig);
            Program.ComparePlayers("MountebankHoard", "BigMoney", gameConfig);
            Program.ComparePlayers("MountebankMonumentHamletVineyard", "MountebankHoard", gameConfig);
        }
Exemple #13
0
        public static void Run(TestOutput testOutput)
        {
            GameConfig gameConfig = GameConfigBuilder.Create(
                StartingCardSplit.Split43,
                Cards.Bishop,
                Cards.FarmingVillage,
                Cards.GrandMarket,
                Cards.Hamlet,
                Cards.Hoard,
                Cards.Monument,
                Cards.Mountebank,
                Cards.PhilosophersStone,
                Cards.ScryingPool,
                Cards.Vineyard
                );

            testOutput.ComparePlayers(Strategies.MountebankMonumentHamletVineyard.Player(), Strategies.BigMoney.Player(), gameConfig);
            testOutput.ComparePlayers(Strategies.MountebankHoard.Player(), Strategies.BigMoney.Player(), gameConfig);
            testOutput.ComparePlayers(Strategies.MountebankMonumentHamletVineyard.Player(), Strategies.MountebankHoard.Player(), gameConfig);
        }
Exemple #14
0
        static void Main()
        {
            using (var testOutput = new TestOutput())
            {
                var player1 = Strategies.GardensCounterPlay.Player(Cards.Monument);
                var player2 = Strategies.GardensWorkshop.Player();

                var builder = new GameConfigBuilder();
                builder.CardSplit = StartingCardSplit.Split43;
                builder.SetKingdomCards(player1, player2);

                testOutput.ComparePlayers(
                    new PlayerAction[] { player1, player2 },
                    builder.ToGameConfig(),
                    rotateWhoStartsFirst: true,
                    createHtmlReport: true,
                    numberOfGames: 1000,
                    shouldParallel: false);
            }
        }
        public object GetResponse(WebService service)
        {
            var playerActions = new List <PlayerAction>();
            var player1       = this.Player1Action;

            if (player1 != null)
            {
                playerActions.Add(player1);
            }
            var player2 = this.Player2Action;

            if (player2 != null)
            {
                playerActions.Add(player2);
            }

            var builder = new GameConfigBuilder();

            builder.SetKingdomCards(playerActions.ToArray());
            return(builder.ToGameConfig().kingdomPiles.OrderBy(card => card.DefaultCoinCost).Select(card => GetCardImageName(card)).ToArray());
        }
Exemple #16
0
        // forum post:  http://forum.dominionstrategy.com/index.php?topic=9602.0

        /*  any attempt to get more than one remake, or more than 2 sooth sayers results in a loss ....  (but in real game, the plan was 3 remakes and 3 soothsayers ...)
         *
         *
         * */

        public static void Run()
        {
            GameConfig gameConfig = GameConfigBuilder.Create(
                StartingCardSplit.Split43,
                Cards.Butcher,
                Cards.GreatHall,
                Cards.HornOfPlenty,
                Cards.HorseTraders,
                Cards.Minion,
                Cards.Pawn,
                Cards.Remake,
                Cards.Soothsayer,
                Cards.StoneMason,
                Cards.Swindler
                );

            //Program.ComparePlayers(Strategies.HorseTraderSoothsayerMinionGreatHall.Player(1), Strategies.HorseTraderSoothsayerMinionGreatHall.Player(2, false), gameConfig);
            Program.ComparePlayers("HorseTraderSoothsayerMinionGreatHall", "BigMoney", gameConfig);
            Program.ComparePlayers("RemakeSoothsayer", "BigMoney", gameConfig);
            Program.ComparePlayers("RemakeSoothsayer", "HorseTraderSoothsayerMinionGreatHall", gameConfig);
        }
Exemple #17
0
        static void Main()
        {
            using (var testOutput = new TestOutput())
            {
                var player1 = Strategies.BigMoneyWithCard.Player(Cards.Amulet, cardCount: 1);
                var player2 = Strategies.BigMoneyWithCard.Player(Cards.Gold);

                var builder = new GameConfigBuilder();
                builder.CardSplit = StartingCardSplit.Split43;

                PlayerAction.SetKingdomCards(builder, player1, player2);
                testOutput.ComparePlayers(
                    player1,
                    player2,
                    builder.ToGameConfig(),
                    rotateWhoStartsFirst: true,
                    createHtmlReport: true,
                    numberOfGames: 1000,
                    shouldParallel: false);
            }
        }
        private static void AddAI(GameServer Server)
        {
            string   name = null;
            GameRoom room = RoomManager.CreateOrGetGame(GameConfigBuilder.Build(""));

            if (room == null && room.Config != null)
            {
                name = RoomManager.RandomRoomName();
            }
            else
            {
                name = room.Config.Name;
            }
            if (AddAI(Server.Config, "" + name))
            {
                Console.WriteLine(">>add ai to " + name);
            }
            else
            {
                Console.WriteLine(">>add ai fail");
            }
        }
Exemple #19
0
        static PlayerAction[] AllBigMoneyWithCard()
        {
            var result = new List <PlayerAction>();

            foreach (var member in typeof(Cards).GetMembers(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public))
            {
                if (member.MemberType == System.Reflection.MemberTypes.Field)
                {
                    object potentialCard = typeof(Cards).GetField(member.Name).GetValue(null);
                    Card   card          = potentialCard as Card;
                    if (card == null)
                    {
                        continue;
                    }

                    if (!GameConfigBuilder.IsKingdomCard(card))
                    {
                        continue;
                    }

                    if (Dominion.Cards.UnimplementedCards.Contains(card))
                    {
                        continue;
                    }

                    if (Dominion.Strategy.MissingDefaults.CardsWithoutDefaultBehaviors.Contains(card))
                    {
                        continue;
                    }

                    var playerAction = Strategies.BigMoneyWithCard.Player(card);
                    result.Add(playerAction);
                }
            }

            return(result.ToArray());
        }
Exemple #20
0
        public double GetScoreVs(PlayerAction action, bool showReport = false)
        {
            var player1Action = this.ToPlayerAction();
            var player2Action = action;

            GameConfigBuilder builder = new GameConfigBuilder();

            PlayerAction.SetKingdomCards(builder, player1Action, player1Action);

            var gameConfig           = builder.ToGameConfig();
            var rotateWhoStartsFirst = true;
            var numberOfGames        = 100;

            var strategyComparison = new Dominion.Data.StrategyComparison(player1Action, player2Action, gameConfig, rotateWhoStartsFirst, numberOfGames);

            var results = strategyComparison.ComparePlayers(
                gameIndex => null,
                gameIndex => null,
                shouldParallel: true,
                gatherStats: false,
                createGameLog: null);

            return(results.WinDifference);
        }
Exemple #21
0
        public static StrategyComparisonResults Compare(
            PlayerAction player1,
            PlayerAction player2,
            int numberOfGames         = 100,
            bool rotateWhoStartsFirst = false,
            bool shouldParalell       = false,
            bool gatherStats          = true)
        {
            GameConfigBuilder builder = new GameConfigBuilder();

            builder.SetKingdomCards(player1, player2);

            var gameConfig         = builder.ToGameConfig();
            var strategyComparison = new Dominion.Data.StrategyComparison(player1, player2, gameConfig, rotateWhoStartsFirst, numberOfGames);

            var results = strategyComparison.ComparePlayers(
                gameIndex => null,
                gameIndex => null,
                shouldParallel: shouldParalell,
                gatherStats: gatherStats,
                createGameLog: null);

            return(results);
        }
Exemple #22
0
        /*
         *  This code answers the following question.   It's player 1's turn.   No provinces have been bought yet - but he's down
         *  scrying pools (lost the split 4/6) and has a more non actions in his deck than the opponent.   Opponenent can
         *  also double province on his turn.  If player1 starts a double province buy war, he will probably Not chain first and lose.
         *  So intead, though he can afford 2 provinces, opts for 1 province, 2 estates and 2 crossroads.
         *  This leaves the deck composition as described below, with scrying pool and festival pile already empty.
         *  There are remaining 6 estates ending, the plan is on the next turn to chain enough of the deck to buy all 6 estates
         *  and 3 pile out the game.   What is the probability of this happening?  (need to draw all 5 festivals and 2 additional coin)
         * */
        public static void Run()
        {
            var player1 = ScryingPoolAndCrossroads.Player();
            var player2 = Strategies.BigMoney.Player();

            var builder = new GameConfigBuilder();

            builder.CardSplit = StartingCardSplit.Random;

            builder.SetStartingDeckPerPlayer(
                new Dominion.CardCountPair[][]
            {
                new Dominion.CardCountPair[]        // Player1
                {
                    new Dominion.CardCountPair(Cards.Estate, 5),
                    new Dominion.CardCountPair(Cards.Province, 1),
                    new Dominion.CardCountPair(Cards.Festival, 5),
                    new Dominion.CardCountPair(Cards.Silver, 2),
                    new Dominion.CardCountPair(Cards.Copper, 2),
                    new Dominion.CardCountPair(Cards.CrossRoads, 3),
                    new Dominion.CardCountPair(Cards.ScryingPool, 4),
                    new Dominion.CardCountPair(Cards.WanderingMinstrel, 1),
                    new Dominion.CardCountPair(Cards.Remake, 1),
                },
                new Dominion.CardCountPair[]        // Player2
                {
                    new Dominion.CardCountPair(Cards.Estate, 3),
                    new Dominion.CardCountPair(Cards.Copper, 7),
                }
            });

            PlayerAction.SetKingdomCards(builder, player1, player2);
            GameConfig gameConfig = builder.ToGameConfig();

            var playerActions = new PlayerAction[] { player1, player2 };

            int countWin  = 0;
            int countGame = 1000;

            for (int i = 0; i < countGame; ++i)
            {
                using (var indentedTextOutput = TestOutput.GetGameLogWriterForIteration(playerActions, i))
                {
                    var gameLog = new HumanReadableGameLog(indentedTextOutput);
                    using (Game game = new Game(new Random(i), gameConfig, gameLog))
                    {
                        GameState gameState = new GameState(playerActions, new int[] { 0, 1 }, game);

                        PlayerState currentPlayer = gameState.players[0];

                        gameLog.BeginRound(currentPlayer);
                        gameState.PlayTurn(currentPlayer);
                        // 11 = 3 starting estates plus all 8 estates in the pile
                        if (currentPlayer.AllOwnedCards.CountOf(Cards.Estate) == 11)
                        {
                            countWin++;
                            System.Console.WriteLine("Won Game {0}", i);
                        }
                    }
                }
            }

            System.Console.WriteLine("{1}% win for {0}", player1.PlayerName, (double)countWin / countGame * 100);
        }
        public static void OnJoinGame(GameSession client, GameClientPacket packet)
        {
            if (string.IsNullOrEmpty(client.Name) || client.Type != (int)PlayerType.Undefined)
            {
                Logger.Debug("join room fail:" + client.Name);
                return;
            }
            int version = packet.ReadInt16();

            if (version < Program.Config.ClientVersion)
            {
                client.LobbyError(Messages.ERR_LOW_VERSION);
                return;
            }
            else if (version > Program.Config.ClientVersion)
            {
                client.ServerMessage(Messages.MSG_HIGH_VERSION);
            }
            int gameid = packet.ReadInt32();            //gameid

            packet.ReadInt16();

            string joinCommand = packet.ReadUnicode(60);

            GameRoom room = null;

            //IsAuthentified = CheckAuth();
            if (!client.IsAuthentified)
            {
                client.LobbyError(Messages.ERR_AUTH_FAIL);
                return;
            }
            if (!RoomManager.CheckRoomPassword(joinCommand))
            {
                client.LobbyError(Messages.ERR_PASSWORD);
                return;
            }
            GameConfig config = GameConfigBuilder.Build(joinCommand);

            room = RoomManager.CreateOrGetGame(config);
            if (room == null)
            {
                client.LobbyError(Messages.MSG_FULL);
                return;
            }
            if (!room.IsOpen)
            {
                client.LobbyError(Messages.MSG_GAMEOVER);
                return;
            }
            if (room != null && room.Config != null)
            {
                if (room.Config.NoCheckDeck)
                {
                    client.ServerMessage(Messages.MSG_NOCHECKDECK);
                }
                if (room.Config.NoShuffleDeck)
                {
                    client.ServerMessage(Messages.MSG_NOSHUFFLEDECK);
                }
                if (room.Config.EnablePriority)
                {
                    client.ServerMessage(Messages.MSG_ENABLE_PROIORITY);
                }
            }
            client.Game = room;
            lock (room.AsyncRoot)
            {
                room.AddPlayer(client);
            }
        }