Example #1
0
 public Game(Random random, GameConfig gameConfig, IGameLog gameLog)
 {
     this.random     = random;
     this.gameConfig = gameConfig;
     this.gameLog    = gameLog;
     this.gameIndex  = Game.RecycledGameIndices.GetInteger();
 }
Example #2
0
            public void AddGainActivity(IGameLog log, Player player, CardCost upToCost, ICard source)
            {
                var activity = Activities.GainACardCostingUpToX(log, player, upToCost, player.Hand, source);

                activity.Specification.CardTypeRestriction = typeof(ITreasureCard);
                _activities.Add(activity);
            }
Example #3
0
 public Game(Random random, GameConfig gameConfig, IGameLog gameLog)
 {
     this.random = random;
     this.gameConfig = gameConfig;
     this.gameLog = gameLog;
     this.gameIndex = Game.RecycledGameIndices.GetInteger();
 }
Example #4
0
        public static IActivity ChooseYesOrNo(IGameLog log, Player player, string message, ICard source, Action ifYes, Action ifNo)
        {
            var choiceActivity = new ChoiceActivity(log, player,
                                                    message,
                                                    source,
                                                    Choice.Yes, Choice.No);

            choiceActivity.ActOnChoice = c =>
            {
                if (c == Choice.Yes)
                {
                    if (ifYes != null)
                    {
                        ifYes();
                    }
                }
                else
                {
                    if (ifNo != null)
                    {
                        ifNo();
                    }
                }
            };

            return(choiceActivity);
        }
Example #5
0
 public WebJobGame(IGameLog log, int numberOfColumns = 7, int numberOfRows = 6, int numberToWin = 4)
 {
     this.board       = new Board(numberOfColumns, numberOfRows);
     this.rules       = new Rules(numberToWin);
     this.numberToWin = numberToWin;
     this.log         = log;
 }
Example #6
0
        public GameState(             
            IGameLog gameLog,
            IPlayerAction[] players,
            GameConfig gameConfig,
            Random random,
            IEnumerable<CardCountPair>[] startingDeckPerPlayer = null)
        {
            int playerCount = players.Length;
            this.gameLog = gameLog;
            this.cardGameSubset = gameConfig.cardGameSubset;
            this.supplyPiles = gameConfig.GetSupplyPiles(playerCount, random);
            this.nonSupplyPiles = gameConfig.GetNonSupplyPiles();

            this.mapCardToPile = new MapOfCards<PileOfCards>(this.cardGameSubset);
            this.BuildMapOfCardToPile();

            this.players = new PlayerCircle(playerCount, players, this.gameLog, random, this.cardGameSubset);

            this.hasPileEverBeenGained = new MapPileOfCardsToProperty<bool>(this.supplyPiles);
            this.pileEmbargoTokenCount = new MapPileOfCardsToProperty<int>(this.supplyPiles);
            this.trash = new BagOfCards(this.cardGameSubset);

            this.GainStartingCards(gameConfig);

            this.players.AllPlayersDrawInitialCards(gameConfig);

            foreach (PileOfCards cardPile in this.supplyPiles)
            {
                cardPile.ProtoTypeCard.DoSpecializedSetupIfInSupply(this);
            }
        }
Example #7
0
        internal PlayerState(IPlayerAction actions, int playerIndex, IGameLog gameLog, Random random, CardGameSubset gameSubset)
        {
            this.gameLog = gameLog;
            this.actions = new PlayerActionWithSelf(actions, this);
            this.playPhase = PlayPhase.NotMyTurn;
            this.random = random;
            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.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.turnCounters = new PlayerTurnCounters(gameSubset);
        }
Example #8
0
        public SelectFromRevealedCardsActivity(IGameLog log, Player player, RevealZone revealZone, string message, ISelectionSpecification selectionSpecification, ICard source)
            : base(log, player, message, selectionSpecification, source)
        {
            RevealedCards = revealZone;

            // HACK. I'm ignoring the activity type on the selection specification. Not sure what to do here.
            Type = ActivityType.SelectFromRevealed;
        }
        public SelectFromRevealedCardsActivity(IGameLog log, Player player, RevealZone revealZone, string message, ISelectionSpecification selectionSpecification)
            : base(log, player, message, selectionSpecification)
        {
            RevealedCards = revealZone;

            // HACK. I'm ignoring the activity type on the selection specification. Not sure what to do here.
            Type = ActivityType.SelectFromRevealed;
        }
Example #10
0
 public static ISelectCardsActivity PutCardFromHandOnTopOfDeck(IGameLog log, Player player, string message)
 {
     return new SelectCardsActivity
         (log, player, message, SelectionSpecifications.SelectExactlyXCards(1))
     {
         AfterCardsSelected = cards => player.Deck.MoveToTop(cards.Single())
     };
 }
Example #11
0
 public static IActivity SelectARevealedCardToPutOnTopOfDeck(IGameLog log, Player player, RevealZone revealZone, string message)
 {
     return new SelectFromRevealedCardsActivity(log, player, revealZone, message,
                                                SelectionSpecifications.SelectExactlyXCards(1))
     {
         AfterCardsSelected = cards => player.Deck.MoveToTop(cards.Single())
     };
 }
Example #12
0
 public static IEnumerable<IActivity> SelectMultipleRevealedCardsToPutOnTopOfDeck(IGameLog log, Player player, RevealZone revealZone)
 {
     var count = revealZone.Count();
     return count.Items(
         (i) => SelectARevealedCardToPutOnTopOfDeck(log, player, revealZone,
             string.Format("Select the {0} (of {1}) card to put on top of the deck.", i.ToOrderString(), count))
     );               
 }
Example #13
0
 protected ActivityBase(IGameLog log, Player player, string message, ActivityType type)
 {
     Log = log;
     Player = player;
     Message = message;
     Type = type;
     Id = Guid.NewGuid();
 }
Example #14
0
 public void LogReveal(IGameLog log)
 {
     if(this.CardCount > 0)
         log.LogMessage("{0} revealed {1}.", Owner.Name, this);
     else
     {
         log.LogMessage("{0} revealed nothing.", Owner.Name);
     }
 }
Example #15
0
        private PlayerState[] players; // circular list, higher numbers to the left;

        #endregion Fields

        #region Constructors

        public PlayerCircle(int playerCount, IPlayerAction[] players, IGameLog gameLog, Random random, CardGameSubset gameSubset)
        {
            this.players = new PlayerState[playerCount];
            for (int playerIndex = 0; playerIndex < this.players.Length; ++playerIndex)
            {
                this.players[playerIndex] = new PlayerState(players[playerIndex], playerIndex, gameLog, random, gameSubset);
            }

            this.currentPlayerIndex = 0;
        }
Example #16
0
        public Engine(SquareDiagonalMap map, IGameLog log)
        {
            Map = map;

            Turn       = 0;
            Log        = log;
            OnPreTurn  = PreTurnLog;
            OnPostTurn = PostTurnLog;
            OnTurn     = TurnLog;
        }
Example #17
0
        protected ActivityBase(IGameLog log, Player player, string message, ActivityType type, ICard source)
        {
            Log = log;
            Player = player;
            Message = message;
            Type = type;
            Id = Guid.NewGuid();
            Hint = ActivityHint.None;

            Source = source == null ? string.Empty : source.Name;
        }
Example #18
0
 public void LogReveal(IGameLog log)
 {
     if (this.CardCount > 0)
     {
         log.LogMessage("{0} revealed {1}.", Owner.Name, this);
     }
     else
     {
         log.LogMessage("{0} revealed nothing.", Owner.Name);
     }
 }
Example #19
0
        protected ActivityBase(IGameLog log, Player player, string message, ActivityType type, ICard source)
        {
            Log     = log;
            Player  = player;
            Message = message;
            Type    = type;
            Id      = Guid.NewGuid();
            Hint    = ActivityHint.None;

            Source = source == null ? string.Empty : source.Name;
        }
 public Move MakeMove(IPlayer you, IPlayer opponent, GameRules rules, IGameLog log)
 {
   if (GetType().Assembly.Location.Contains("TakeForever"))
   {
     System.Threading.Thread.Sleep(TimeSpan.FromMinutes(10));
   }
   if (_random.NextDouble() > 0.5)
   {
     return Round1Move.Paper;
   }
   return Round1Move.Rock;
 }
Example #21
0
        public Manager(IGameLog managerLog, IGameLog gameLog, TRepository gameTypesRepository)
        {
            _log        = managerLog;
            _gameLog    = gameLog;
            _repository = gameTypesRepository;

            EventInfo[] events = typeof(Tdest).GetEvents();
            foreach (var ev in events)
            {
                _possibleEvents[ev.Name] = ev;
            }
        }
Example #22
0
 public static ISelectCardsActivity PutCardFromHandOnTopOfDeck(IGameLog log, Player player, string message, ICard source)
 {
     return new SelectCardsActivity
         (log, player, message, SelectionSpecifications.SelectExactlyXCards(1), source)
     {
         AfterCardsSelected = cards =>
         {
             player.Deck.MoveToTop(cards.Single());
             log.LogMessage("{0} put a card on top of the deck", player.Name);
         },
         Hint = ActivityHint.RedrawCards
     };
 }
Example #23
0
 public static SelectPileActivity GainACardCostingUpToX(IGameLog log, Player player, CardCost cost, CardZone destination)
 {
     return new SelectPileActivity(log, player, string.Format("Select a card to gain of cost {0} or less", cost),
                                   SelectionSpecifications.SelectPileCostingUpToX(cost))
     {
         AfterPileSelected = pile =>
         {
             var card = pile.TopCard;
             card.MoveTo(destination);
             log.LogGain(player, card);
         }
     };
 }
Example #24
0
 public static ISelectCardsActivity PutCardFromHandOnTopOfDeck(IGameLog log, Player player, string message, ICard source)
 {
     return(new SelectCardsActivity
                (log, player, message, SelectionSpecifications.SelectExactlyXCards(1), source)
     {
         AfterCardsSelected = cards =>
         {
             player.Deck.MoveToTop(cards.Single());
             log.LogMessage("{0} put a card on top of the deck.", player.Name);
         },
         Hint = ActivityHint.RedrawCards
     });
 }
Example #25
0
 public static SelectPileActivity GainACardCostingExactlyX(IGameLog log, Player player, CardCost cost, CardZone destination, ICard source)
 {
     return new SelectPileActivity(log, player, string.Format("Select a card to gain with a cost of exactly {0}", cost),
                                   SelectionSpecifications.SelectPileCostingExactlyX(cost), source)
     {
         AfterPileSelected = pile =>
         {
             var card = pile.TopCard;
             card.MoveTo(destination);
             log.LogGain(player, card);
         },
         Hint = ActivityHint.GainCards
     };
 }
Example #26
0
        public Game(IEnumerable <Player> players, CardBank bank, IGameLog log)
        {
            if (!players.Any())
            {
                throw new ArgumentException("There must be at least one player");
            }

            _players = new List <Player>(players);

            Bank  = bank;
            Log   = log;
            Trash = new TrashPile();

            _gameTurns = GameTurns().GetEnumerator();
            _gameTurns.MoveNext();
        }
Example #27
0
        public Game(IEnumerable<Player> players, CardBank bank, IGameLog log)
        {
            if(!players.Any())
                throw new ArgumentException("There must be at least one player");

            _players = new List<Player>(players);

            Bank = bank;
            Log = log;
            Trash = new TrashPile();

            _gameTurns = GameTurns().GetEnumerator();
            _gameTurns.MoveNext();


        }
Example #28
0
        public static ISelectCardsActivity PutCardOfTypeFromHandOnTopOfDeck(IGameLog log, Player player, string message, Type cardType, ICard source)
        {
            var spec = SelectionSpecifications.SelectExactlyXCards(1);
            spec.CardTypeRestriction = cardType;

            return new SelectCardsActivity
                (log, player, message, spec, source)
            {
                AfterCardsSelected = cards =>
                {
                    var card = cards.Single();
                    player.Deck.MoveToTop(card);
                    log.LogMessage("{0} put a {1} on top of the deck.", player.Name, card.Name);
                },
                Hint = ActivityHint.RedrawCards
            };
        }
Example #29
0
 public static IActivity SelectARevealedCardToPutOnTopOfDeck(IGameLog log, Player player, RevealZone revealZone, string message, ICard source)
 {
     return(new SelectFromRevealedCardsActivity(log, player, revealZone, message,
                                                SelectionSpecifications.SelectExactlyXCards(1), source)
     {
         AfterCardsSelected = cards =>
         {
             player.Deck.MoveToTop(cards.Single());
             if (revealZone.CardCount == 1)
             {
                 var lastCard = revealZone.Single();
                 player.Deck.MoveToTop(lastCard);
                 //log.LogMessage("{0} put a {1} on top.", player.Name, lastCard.Name);
             }
         },
         Hint = ActivityHint.RedrawCards
     });
 }
Example #30
0
        public static ISelectCardsActivity PutCardOfTypeFromHandOnTopOfDeck(IGameLog log, Player player, string message, Type cardType, ICard source)
        {
            var spec = SelectionSpecifications.SelectExactlyXCards(1);

            spec.CardTypeRestriction = cardType;

            return(new SelectCardsActivity
                       (log, player, message, spec, source)
            {
                AfterCardsSelected = cards =>
                {
                    var card = cards.Single();
                    player.Deck.MoveToTop(card);
                    log.LogMessage("{0} put a {1} on top of the deck.", player.Name, card.Name);
                },
                Hint = ActivityHint.RedrawCards
            });
        }
Example #31
0
        public static IActivity GainAnActionCardCostingUpToX(IGameLog log, Player player, int cost, ICard source, bool optional)
        {
            var activity = new SelectPileActivity(log, player, string.Format("Select an action card to gain of cost {0} or less.", cost),
                                                  SelectionSpecifications.SelectPileCostingUpToX(cost), source)
            {
                AfterPileSelected = pile =>
                {
                    var card = pile.TopCard;
                    card.MoveTo(player.Discards);
                    log.LogGain(player, card);
                },
                Hint = ActivityHint.GainCards
            };

            activity.Specification.CardTypeRestriction = typeof(IActionCard);
            activity.IsOptional = optional;

            return(activity);
        }
        public Move MakeMove(IPlayer you, IPlayer opponent, GameRules rules, IGameLog log)
        {
            string youLastMove = you.LastMove == null ? String.Empty : you.LastMove.ToString().Trim();
            string opponentLastMove = opponent.LastMove == null ? String.Empty : opponent.LastMove.ToString().Trim();

            string url = String.Format(template, this.teamUrl, this.roundGuid,
                youLastMove, you.Points, you.TeamName,
                opponentLastMove, opponent.Points, opponent.TeamName,
                rules.MaximumGames, rules.PointsToWin);

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
            using (WebResponse response = request.GetResponse())
            {
                using (Stream stream = response.GetResponseStream())
                {
                    string move = new StreamReader(stream).ReadToEnd();
                    return Round1Move.Moves[move];
                }
            }
        }
 public SelectCardsActivity(IGameLog log, Player player, string message, ISelectionSpecification specification) 
     : base(log, player, message, specification.ActivityType)
 {
     Specification = specification;
 }
Example #34
0
 public void AddGainActivity(IGameLog log, Player player, CardCost upToCost)
 {
     var activity = Activities.GainACardCostingUpToX(log, player, upToCost, player.Hand);
     activity.Specification.CardTypeRestriction = typeof (ITreasureCard);
     _activities.Add(activity);
 }
Example #35
0
 public GainACardActivity(IGameLog log, Player player, string message, ISelectionSpecification specification, CardZone destination, ICard source)
     : base(log, player, message, specification, source)
 {
     _destination = destination;
     Hint         = ActivityHint.GainCards;
 }
Example #36
0
 public static GainACardActivity GainACardCostingUpToX(IGameLog log, Player player, CardCost cost, ICard source)
 {
     return GainACardCostingUpToX(log, player, cost, player.Discards, source);
 }
Example #37
0
 public static IActivity ChooseYesOrNo(IGameLog log, Player player, string message, ICard source, Action ifYes)
 {
     return(ChooseYesOrNo(log, player, message, source, ifYes, null));
 }
Example #38
0
 public ChoiceActivity(IGameLog log, Player player, string message, ICard source, params Choice[] options)
     : base(log, player, message, ActivityType.MakeChoice, source)
 {
     AllowedOptions = options;
 }
Example #39
0
 public static IEnumerable<ISelectCardsActivity> PutMultipleCardsFromHandOnTopOfDeck(IGameLog log, Player player, int count)
 {
     return count.Items(i => PutCardFromHandOnTopOfDeck(log, player, 
                                                        string.Format("Select the {0} (of {1}) card to put on top of the deck.", i.ToOrderString(), count)));
 }
Example #40
0
        public static ISelectCardsActivity SelectActionToPlayMultipleTimes(TurnContext context, Player player, IGameLog log, ICard source, int count)
        {
            var activity = new SelectCardsActivity(
                log, player,
                string.Format("Select an action to play {0} times", count),
                SelectionSpecifications.SelectExactlyXCards(1), source);

            activity.Hint = ActivityHint.PlayCards;
            activity.Specification.CardTypeRestriction = typeof(IActionCard);
            activity.AfterCardsSelected = cards =>
            {
                var actionCard = cards.OfType <IActionCard>().Single();
                log.LogMessage("{0} selected {1} to be played {2} times.", player.Name, actionCard.Name, count);

                actionCard.MoveTo(context.ActivePlayer.PlayArea);

                count.Times(() => context.AddEffect(source, new PlayCardEffect(actionCard)));
            };

            return(activity);
        }
Example #41
0
 public static GainACardActivity GainACardCostingExactlyX(IGameLog log, Player player, CardCost cost, CardZone destination, ICard source)
 {
     return(new GainACardActivity(log, player,
                                  string.Format("Select a card to gain with a cost of exactly {0}.", cost),
                                  SelectionSpecifications.SelectPileCostingExactlyX(cost), destination, source));
 }
Example #42
0
 public ChooseBasedOnRevealedCardsActivity(IGameLog log, Player player, RevealZone revealZone, string message, ICard source, params Choice[] options)
     : base(log, player, message, source, options)
 {
     RevealedCards = revealZone;
 }
Example #43
0
 public ConfigurationLoader(IGameLog log)
 {
     _log = log;
 }
 public Move MakeMove(IPlayer you, IPlayer opponent, GameRules rules, IGameLog log)
 {
   return moves[random.Next(3)];
 }
Example #45
0
 public GainUtility(IGameLog log, CardBank bank, Player player)
 {
     _log    = log;
     _player = player;
     _bank   = bank;
 }
Example #46
0
 public static SelectPileActivity GainACardCostingUpToX(IGameLog log, Player player, CardCost cost)
 {
     return GainACardCostingUpToX(log, player, cost, player.Discards);
 }
Example #47
0
 public static GainACardActivity GainACardCostingUpToX(IGameLog log, Player player, CardCost cost, CardZone destination, ICard source)
 {
     return(new GainACardActivity(log, player, string.Format("Select a card to gain of cost {0} or less.", cost),
                                  SelectionSpecifications.SelectPileCostingUpToX(cost), destination, source));
 }
Example #48
0
        public static IActivity ChooseYesOrNo(IGameLog log, Player player, string message, Action ifYes, Action ifNo)
        {
            var choiceActivity = new ChoiceActivity(log, player,
                  message,
                  Choice.Yes, Choice.No);

            choiceActivity.ActOnChoice = c =>
            {
                if (c == Choice.Yes)
                {
                    if (ifYes != null)
                        ifYes();
                }
                else
                {
                    if(ifNo != null)
                        ifNo();
                }
            };

            return choiceActivity;
        }
Example #49
0
 public SelectPileActivity(IGameLog log, Player player, string message, ISelectionSpecification specification, ICard source)
     : base(log, player, message, specification.ActivityType, source)
 {
     Specification = specification;
 }
Example #50
0
 public static IActivity ChooseYesOrNo(IGameLog log, Player player, string message, Action ifYes)
 {
     return ChooseYesOrNo(log, player, message, ifYes, null);
 }
Example #51
0
        public static ISelectCardsActivity SelectActionToPlayMultipleTimes(TurnContext context, Player player, IGameLog log, ICard source, int count)
        {
            var activity = new SelectCardsActivity(
                log, player,
                string.Format("Select an action to play {0} times", count),
                SelectionSpecifications.SelectExactlyXCards(1), source);

            activity.Hint = ActivityHint.PlayCards;
            activity.Specification.CardTypeRestriction = typeof(IActionCard);
            activity.AfterCardsSelected = cards =>
            {
                var actionCard = cards.OfType<IActionCard>().Single();
                log.LogMessage("{0} selected {1} to be played {2} times.", player.Name, actionCard.Name, count);

                actionCard.MoveTo(context.ActivePlayer.PlayArea);

                count.Times(() => context.AddEffect(source, new PlayCardEffect(actionCard)));
            };

            return activity;
        }
Example #52
0
        public static IEnumerable <IActivity> SelectMultipleRevealedCardsToPutOnTopOfDeck(IGameLog log, Player player, RevealZone revealZone, ICard source)
        {
            var count = revealZone.Count();

            if (count == 1)
            {
                throw new ArgumentException("The reveal zone only contains one card. Cannot select multiples.");
            }

            return(count.Items(
                       (i) => SelectARevealedCardToPutOnTopOfDeck(log, player, revealZone,
                                                                  string.Format("Select the {0} (of {1}) card to put on top of the deck.", i.ToOrderString(), count), source)
                       ).Take(count - 1));
        }
 public ChooseBasedOnRevealedCardsActivity(IGameLog log, Player player, RevealZone revealZone, string message, ICard source, params Choice[] options) 
     : base(log, player, message, source, options)
 {
     RevealedCards = revealZone;
 }
Example #54
0
 public Service4(IGameLog log, TypeRepository rep)
 {
 }
Example #55
0
 public static GainACardActivity GainACardCostingUpToX(IGameLog log, Player player, CardCost cost, ICard source)
 {
     return(GainACardCostingUpToX(log, player, cost, player.Discards, source));
 }
Example #56
0
 public static GainACardActivity GainACardCostingUpToX(IGameLog log, Player player, CardCost cost, CardZone destination, ICard source)
 {
     return new GainACardActivity(log, player, string.Format("Select a card to gain of cost {0} or less.", cost),
                                  SelectionSpecifications.SelectPileCostingUpToX(cost), destination, source);
 }
Example #57
0
 public static IEnumerable <ISelectCardsActivity> PutMultipleCardsFromHandOnTopOfDeck(IGameLog log, Player player, int count, ICard source)
 {
     return(count.Items(i => PutCardFromHandOnTopOfDeck(log, player,
                                                        string.Format("Select the {0} (of {1}) card to put on top of the deck.", i.ToOrderString(), count), source)));
 }
Example #58
0
 public static GainACardActivity GainACardCostingExactlyX(IGameLog log, Player player, CardCost cost, CardZone destination, ICard source)
 {
     return new GainACardActivity(log, player,
                                  string.Format("Select a card to gain with a cost of exactly {0}.", cost),
                                  SelectionSpecifications.SelectPileCostingExactlyX(cost), destination, source);
 }
Example #59
0
 public MatchRepository(IDataContextWrapper context, IGameLog gameLog)
 {
     _context = context;
     _gameLog = gameLog;
 }