Example #1
0
 public Player(int id)
 {
     this.gain = false;
     this.currencyForGain = 0;
     this.currencyForGainBonus = 0;
     this.gainsLeft = 0;
     this.playMultipleTimes = false;
     this.timesToPlayLeft = 1;
     this.timesToPlayNextCard = 1;
     this.id = id;
     myDeck = new Deck();
     myDeck.reshuffle();
     myHand = new Hand();
     for (int i = 0; i < 5; i++)
     {
         myHand.draw(myDeck);
     }
     timesPlayed = new List<int>();
     played = new List<Card>();
     victoryPts = 3;
     this.buysLeft = 1;
     this.currencyAvailable = 0;
     this.actionsLeft = 1;
     this.name = null;
     this.game = null;
     this.lastPlayedCard = null;
     this.trashesNeeded = 0;
     this.trashCurrencyBonus = 0;
     this.bonusCurrencyForBuy = 0;
     this.possibleTrashes = 0;
     this.otherPlayers = new List<Player>();
     this.functionsToCall = new Queue<DelayedFunction>();
     this.thiefList = new List<List<Card>>();
 }
Example #2
0
 public void setUp()
 {
     this.gameOnePlayer = new Game(1);
     this.gameTwoPlayer = new Game(2);
     this.gameThreePlayer = new Game(3);
     this.gameFourPlayer = new Game(4);
 }
Example #3
0
 public MainWindow(Game game,String lang)
 {
     InitializeComponent();
     myGame = game;
     this.language = lang;
     Initialize();
 }
Example #4
0
 public void setUp()
 {
     this.p = new Player(0);
     p1 = new Player(1);
     p2 = new Player(2);
     this.game = new Game(4);
 }
Example #5
0
        internal PlayerState(IPlayerAction actions, int playerIndex, Game game)
        {
            this.game = game;

            CardGameSubset gameSubset = game.CardGameSubset;
            this.actions = new PlayerActionWithSelf(actions, this);
            this.EnterPhase(PlayPhase.NotMyTurn);
            this.playerIndex = playerIndex;

            // duplicates
            this.allOwnedCards = new BagOfCards(gameSubset);
            this.cardsInPlay = new BagOfCards(gameSubset, this.allOwnedCards);
            this.cardsInPlayAtBeginningOfCleanupPhase = new BagOfCards(gameSubset);

            // partition
            this.islandMat = new BagOfCards(gameSubset, this.allOwnedCards);
            this.nativeVillageMat = new BagOfCards(gameSubset, this.allOwnedCards);
            this.tavernMat = new BagOfCards(gameSubset, this.allOwnedCards);
            this.deck = new ListOfCards(gameSubset, this.allOwnedCards);
            this.discard = new BagOfCards(gameSubset, this.allOwnedCards);
            this.cardsBeingPlayed = new ListOfCards(gameSubset, this.allOwnedCards);  // a stack for recursion
            this.cardsBeingRevealed = new BagOfCards(gameSubset, this.allOwnedCards);
            this.hand = new BagOfCards(gameSubset, this.allOwnedCards);
            this.cardsPlayed = new BagOfCards(gameSubset, this.cardsInPlay);
            this.durationCards = new BagOfCards(gameSubset, this.cardsInPlay);
            this.cardsToReturnToHandAtStartOfTurn = new BagOfCards(gameSubset, this.allOwnedCards);
            this.cardToPass = new SingletonCardHolder(this.allOwnedCards);
            this.cardBeingDiscarded = new ListOfCards(gameSubset, this.allOwnedCards);
            this.cardsSetAside = new BagOfCards(gameSubset, this.allOwnedCards);

            this.turnCounters = new PlayerTurnCounters(gameSubset);
        }
Example #6
0
 public void testBureaucratActionNoVictoryInOtherPlayer()
 {
     Game g = new Game(2);
     g.getPlayers()[1].getDeck().addCardToFront(CardMother.Feast());
     CardFunctions.bureaucratAction(g.getPlayers()[0]);
     Assert.AreEqual(CardMother.Feast(), g.getPlayers()[1].getDeck().draw());
     Assert.AreEqual(CardMother.Silver(), g.getPlayers()[0].getDeck().draw());
 }
Example #7
0
 public void testBureaucratAction()
 {
     Game g = new Game(2);
     g.getPlayers()[1].getHand().getHand().Add(CardMother.Estate());
     CardFunctions.bureaucratAction(g.getPlayers()[0]);
     Assert.AreEqual(CardMother.Estate(), g.getPlayers()[1].getDeck().draw());
     Assert.AreEqual(CardMother.Silver(), g.getPlayers()[0].getDeck().draw());
 }
Example #8
0
 private void ConfirmNames(object sender, RoutedEventArgs e)
 {
     Game mygame = new Game(numValue);
     List<Player> players = mygame.getPlayers();
     for (int i = 0; i < numValue; i++) {
         players[i].setName(nameBox[i].Text);
     }
     main = new MainWindow(mygame,language);
     PrepScreen Prep = new PrepScreen(players[0].getName(), main);
     Prep.Show();
     Close();
 }
        private PlayerState[] players; // circular list, higher numbers to the left;

        #endregion Fields

        #region Constructors

        // we use a playerposition array instead of just using the order in the playerActions array so that
        // we can gather stats about a player using it's player index - which will be constant from game to game
        public PlayerCircle(int playerCount, IPlayerAction[] playerActions, int[] playerPosition, Game game)
        {
            this.players = new PlayerState[playerCount];
            for (int playerIndex = 0; playerIndex < this.players.Length; ++playerIndex)
            {
                int playPosition = playerPosition[playerIndex];
                IPlayerAction playerAction = playerActions[playerIndex];
                this.players[playPosition] = new PlayerState(playerAction, playerIndex, game);
            }

            this.currentPlayerIndex = 0;
        }
Example #10
0
 public void testPlayMoatAndWitch()
 {
     Game g = new Game(3);
     Player p = g.getCurrentPlayer();
     Player p2 = g.getPlayers()[1];
     Player p3 = g.getPlayers()[2];
     p2.getHand().getHand().Add(CardMother.Moat());
     p.getHand().getHand().Add(CardMother.Witch());
     p.play(CardMother.Witch());
     p2.setVictoryPts();
     p3.setVictoryPts();
     Assert.AreEqual(2, p3.getVictoryPts());
     Assert.AreEqual(3, p2.getVictoryPts());
 }
Example #11
0
 public void testPlayMoatAndThief()
 {
     Game g = new Game(3);
     Player p = g.getCurrentPlayer();
     Player p2 = g.getPlayers()[1];
     Player p3 = g.getPlayers()[2];
     p2.getHand().getHand().Add(CardMother.Moat());
     p.getHand().getHand().Add(CardMother.Thief());
     p.play(CardMother.Thief());
     List<List<Card>> thiefed = p.getThiefList();
     Assert.AreEqual(0, thiefed[0].Count);
     Assert.AreEqual(2, thiefed[1].Count);
 }
Example #12
0
 public void testPlayMoatAndSpy()
 {
     Game g = new Game(3);
     Player p = g.getCurrentPlayer();
     Player p2 = g.getPlayers()[1];
     Player p3 = g.getPlayers()[2];
     p2.getHand().getHand().Add(CardMother.Moat());
     p.getHand().getHand().Add(CardMother.Spy());
     p.play(CardMother.Spy());
     List<Card> cards = p.spyOnDecks();
     p.keepOrDiscardSpiedCards(cards);
     Assert.AreEqual(0, p2.getDeck().getInDiscard().Count);
     Assert.AreEqual(1, p3.getDeck().getInDiscard().Count);
     Assert.AreEqual(1, p.getDeck().getInDiscard().Count);
 }
Example #13
0
 public void testPlayMoatAndMilitia()
 {
     Game g = new Game(3);
     Player p = g.getCurrentPlayer();
     Player p2 = g.getPlayers()[1];
     Player p3 = g.getPlayers()[2];
     p2.getHand().getHand().Add(CardMother.Moat());
     p.getHand().getHand().Add(CardMother.Militia());
     p.play(CardMother.Militia());
     Assert.AreEqual(0, p2.functionsToCall.Count);
     Assert.AreEqual(1, p3.functionsToCall.Count);
 }
Example #14
0
 public void testPlayThiefSuccess()
 {
     Game g = new Game(4);
     Player p = g.getCurrentPlayer();
     g.getPlayers()[1].getDeck().addCardToFront(CardMother.Gold());
     g.getPlayers()[1].getDeck().addCardToFront(CardMother.Silver());
     g.getPlayers()[2].getDeck().addCardToFront(CardMother.Feast());
     g.getPlayers()[3].getDeck().addCardToFront(CardMother.Feast());
     g.getPlayers()[3].getDeck().addCardToFront(CardMother.Feast());
     p.getHand().getHand().Add(CardMother.Thief());
     StatusObject o = p.play(CardMother.Thief());
     Assert.IsTrue(o.selectTrashFromThief());
     List<List<Card>> cards = p.getThiefList();
     Assert.AreEqual(2, cards[0].Count);
     Assert.AreEqual(1, cards[1].Count);
     Assert.AreEqual(0, cards[2].Count);
     List<Card> steal = new List<Card>();
     steal.Add(CardMother.Gold());
     steal.Add(CardMother.Copper());
     steal.Add(null);
     o = p.validateThiefStolenCards(steal);
     Assert.IsTrue(o.needToKeepThief());
     Assert.AreEqual(CardMother.Silver(), g.getPlayers()[1].getDeck().getInDiscard()[0]);
     List<Card> keep = new List<Card>();
     keep.Add(CardMother.Gold());
     o = p.keepCardsFromThief(keep);
     Assert.AreEqual(1, p.getDeck().getInDiscard().Count);
     Assert.AreEqual(CardMother.Gold(), p.getDeck().getInDiscard()[0]);
 }
Example #15
0
        public void testLoadAndSave()
        {
            Internationalizer.setLocale(new Locale("de", "DE"));
            Game g = new Game(2);
            Player p = g.getPlayers()[0];
            p.getHand().getHand().Add(CardMother.Feast());
            p.getDeck().getInDiscard().Add(CardMother.Estate());
            p = g.nextTurnPlayer();
            p.getHand().getHand().Add(CardMother.Village());

            //Setup Done
            string direc = Directory.GetCurrentDirectory();
            direc += "\\testSave.dom";
            FileStream stream = new FileStream(direc, FileMode.OpenOrCreate,FileAccess.ReadWrite);
            g.SaveFile(stream);

            Internationalizer.setLocale(new Locale("en", "US"));

            stream = new FileStream(direc, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            Game g2 = Game.LoadFile(stream);
            Assert.AreEqual(1, g2.getCurrentPlayerNumber());
            Assert.IsTrue(g2.getCurrentPlayer().getHand().contains(CardMother.Village()));
            Assert.IsFalse(g2.isGameOver());
            Assert.AreEqual(4, g2.getPlayers()[0].getVictoryPts());
            Assert.AreEqual(3, g2.getPlayers()[1].getVictoryPts());
            Assert.AreEqual(12, g2.getPlayers()[0].getDeck().size() + g2.getPlayers()[0].getHand().size());
            Assert.AreEqual(11, g2.getPlayers()[1].getDeck().size() + g2.getPlayers()[1].getHand().size());
            Assert.AreEqual("Aktionen", Internationalizer.getMessage("Actions"));

            Internationalizer.setLocale(new Locale("en", "US"));
        }
Example #16
0
 public void testThiefActionWithNull()
 {
     Game g = new Game(3);
     g.getPlayers()[1].setDeck(new Deck(new List<Card>()));
     Player p = g.getCurrentPlayer();
     StatusObject o = new StatusObject(false);
     CardFunctions.thiefAction(p, o);
     List<List<Card>> thiefed = p.getThiefList();
     Assert.AreEqual(0, thiefed[0].Count);
 }
Example #17
0
 public void testPlayCouncilRoom()
 {
     Game g = new Game(2);
     Player p = g.getCurrentPlayer();
     p.getHand().getHand().Add(CardMother.CouncilRoom());
     p.play(CardMother.CouncilRoom());
     Assert.AreEqual(9, p.getHand().size());
     Assert.AreEqual(2, p.getBuysLeft());
     p = g.nextTurnPlayer();
     p.callDelayedFunctions();
     Assert.AreEqual(6, p.getHand().size());
 }
        /*
         *  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),
                }
            });

            builder.SetKingdomCards(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);
        }
Example #19
0
 public void testFunctionSeven()
 {
     Game g = new Game(2);
     Player p = g.getCurrentPlayer();
     Player p2 = g.getPlayers()[1];
     p.getHand().getHand().Add(CardMother.Witch());
     Assert.IsTrue(p.play(CardMother.Witch()).wasPlayedProperly());
     Assert.AreEqual(7,p.getHand().size());
     p.setVictoryPts();
     p2.setVictoryPts();
     Assert.AreEqual(3, p.getVictoryPts());
     Assert.AreEqual(2, p2.getVictoryPts());
 }
Example #20
0
 public void testEqualFailNonPlayer()
 {
     Game g = new Game(0);
     Assert.IsFalse(p.Equals(g));
 }
Example #21
0
 public void testPlayThroneRoomAndMilitia()
 {
     Game g = new Game(2);
     Player p = g.getCurrentPlayer();
     p.getHand().getHand().Add(CardMother.Militia());
     p.getHand().getHand().Add(CardMother.ThroneRoom());
     StatusObject o = p.play(CardMother.ThroneRoom());
     o = p.play(CardMother.Militia());
     Assert.AreEqual(9, p.getCurrency());
     p = g.nextTurnPlayer();
     Assert.AreEqual(1, p.functionsToCall.Count);
 }
Example #22
0
 public void testPlayThiefValidateCardNotStolen()
 {
     Game g = new Game(4);
     Player p = g.getCurrentPlayer();
     g.getPlayers()[1].getDeck().addCardToFront(CardMother.Gold());
     g.getPlayers()[1].getDeck().addCardToFront(CardMother.Silver());
     g.getPlayers()[2].getDeck().addCardToFront(CardMother.Feast());
     g.getPlayers()[3].getDeck().addCardToFront(CardMother.Feast());
     g.getPlayers()[3].getDeck().addCardToFront(CardMother.Feast());
     p.getHand().getHand().Add(CardMother.Thief());
     StatusObject o = p.play(CardMother.Thief());
     Assert.IsTrue(o.selectTrashFromThief());
     List<List<Card>> cards = p.getThiefList();
     Assert.AreEqual(2, cards[0].Count);
     Assert.AreEqual(1, cards[1].Count);
     Assert.AreEqual(0, cards[2].Count);
     List<Card> steal = new List<Card>();
     steal.Add(CardMother.Gold());
     steal.Add(CardMother.Silver());
     steal.Add(null);
     o = p.validateThiefStolenCards(steal);
     Assert.IsTrue(o.selectTrashFromThief());
     Assert.AreEqual(0, p.getPossibleCardsToKeepFromThief().Count);
 }
Example #23
0
 public void testGetPlayers()
 {
     Game g = new Game(4);
     List<Player> players = g.getPlayers();
     for (int i = 0; i < players.Count; i++)
     {
         Assert.AreEqual(i, players[i].getID());
     }
 }
Example #24
0
 public void testPlayMilitiaSetup()
 {
     Game g = new Game(2);
     Player p = g.getCurrentPlayer();
     p.getHand().getHand().Add(CardMother.Militia());
     StatusObject o = p.play(CardMother.Militia());
     Assert.IsTrue(o.wasPlayedProperly());
     Assert.AreEqual(7, p.getCurrency());
     p = g.nextTurnPlayer();
     Assert.AreEqual(1, p.functionsToCall.Count);
     o = p.callDelayedFunctions();
     Assert.IsTrue(o.wasMilitiaPlayed());
     Assert.IsTrue(o.needToContinueWithDelayedFunctions());
     List<Card> cards = new List<Card>();
     o = p.militiaDiscardEffect(cards);
     Assert.IsTrue(o.wasMilitiaPlayed());
     cards.Add(CardMother.Copper());
     cards.Add(CardMother.Copper());
     o = p.militiaDiscardEffect(cards);
     Assert.IsFalse(o.wasMilitiaPlayed());
     Assert.IsTrue(o.needToContinueWithDelayedFunctions());
     o = p.callDelayedFunctions();
     Assert.IsFalse(o.needToContinueWithDelayedFunctions());
 }
Example #25
0
 public void testLoad()
 {
     gameThreePlayer = Game.Load();
     Assert.AreEqual(4, gameThreePlayer.getPlayers().Count);
 }
Example #26
0
 public void testPlayMoat()
 {
     Game g = new Game(3);
     Player p = g.getCurrentPlayer();
     p.getHand().getHand().Add(CardMother.Moat());
     p.play(CardMother.Moat());
     Assert.AreEqual(7, p.getHand().size());
 }
Example #27
0
        public void testGainCurses()
        {
            Game mini = new Game(1);
            Player p = mini.getCurrentPlayer();
            CardFunctions.gainCurses(p);
            p.setVictoryPts();
            Assert.AreEqual(3, p.getVictoryPts());

            Game big = new Game(4);
            p = big.getCurrentPlayer();
            CardFunctions.gainCurses(p);
            p.setVictoryPts();
            Assert.AreEqual(3, p.getVictoryPts());
            for (int i = 0; i < 3; i++)
            {
                p = big.nextTurnPlayer();
                p.setVictoryPts();
                Assert.AreEqual(2, p.getVictoryPts());
            }
        }
Example #28
0
 public void testPlayMoatAndBureaucrat()
 {
     Game g = new Game(3);
     Player p = g.getCurrentPlayer();
     Player p2 = g.getPlayers()[1];
     Player p3 = g.getPlayers()[2];
     p2.getHand().getHand().Add(CardMother.Moat());
     p.getHand().getHand().Add(CardMother.Bureaucrat());
     p2.getHand().getHand().Add(CardMother.Estate());
     p3.getHand().getHand().Add(CardMother.Estate());
     p.play(CardMother.Bureaucrat());
     Assert.AreEqual(CardMother.Copper(), p2.getDeck().peekAtTopCard());
     Assert.AreEqual(CardMother.Estate(), p3.getDeck().peekAtTopCard());
 }
Example #29
0
 public void testPlayBureaucrat()
 {
     Game g = new Game(3);
     Player p = g.getCurrentPlayer();
     p.getHand().getHand().Add(CardMother.Bureaucrat());
     g.getPlayers()[1].getHand().getHand().Add(CardMother.Duchy());
     p.play(CardMother.Bureaucrat());
     Assert.AreEqual(CardMother.Silver(), p.getDeck().getInDeck()[0]);
     p = g.nextTurnPlayer();
     Assert.AreEqual(CardMother.Duchy(), p.getDeck().getInDeck()[0]);
     p = g.nextTurnPlayer();
     Assert.AreEqual(CardMother.Copper(), p.getDeck().getInDeck()[0]);
     Console.Write(g.getGameStatus());
 }
Example #30
0
 public void testPlaySpyWithNull()
 {
     Game g = new Game(4);
     Player p = g.getCurrentPlayer();
     g.getPlayers()[0].getDeck().addCardToFront(CardMother.Feast());
     g.getPlayers()[0].getDeck().addCardToFront(CardMother.Feast());
     g.getPlayers()[1].getDeck().addCardToFront(CardMother.Duchy());
     g.getPlayers()[2].getDeck().addCardToFront(CardMother.ThroneRoom());
     g.getPlayers()[3].getDeck().addCardToFront(CardMother.Militia());
     p.getHand().getHand().Add(CardMother.Spy());
     StatusObject o = p.play(CardMother.Spy());
     Assert.IsTrue(o.canSpyOnDeck());
     List<Card> cards = p.spyOnDecks();
     cards[1] = null;
     o = p.keepOrDiscardSpiedCards(cards);
     Assert.IsTrue(o.playerSpiedSuccessfully());
     Assert.AreEqual(CardMother.Feast(), g.getPlayers()[0].getDeck().getInDiscard()[0]);
     Assert.AreEqual(CardMother.Duchy(), g.getPlayers()[1].getDeck().peekAtTopCard());
     Assert.AreEqual(CardMother.ThroneRoom(), g.getPlayers()[2].getDeck().getInDiscard()[0]);
     Assert.AreEqual(CardMother.Militia(), g.getPlayers()[3].getDeck().getInDiscard()[0]);
 }