Example #1
0
        public PlayerMove RetrieveCard(out Card card)
        {
            card = null;

            while (true)
            {
                try
                {
                    var line = ConsoleHelper.Prompt("Retrieve?");

                    if (line.Equals("pass", StringComparison.OrdinalIgnoreCase))
                        return PlayerMove.Pass;

                    card = Deck.Parse(line);
                    if (!GameState.States[this].Desk.Contains(card, CardEQC.Instance))
                        throw new InvalidOperationException("You don't have this card.");

                    return PlayerMove.Move;
                }
                catch
                {
                    ConsoleHelper.Error("Invalid card.");
                    ConsoleHelper.DumpCards("Your desk:", GameState.States[this].Desk);
                }
            }
        }
Example #2
0
        private PlayerMove DoAskForCardMove(string prompt, bool canDrop, out Card card)
        {
            var response = Client.Ask(prompt);
            var theMove = response.EqualsCI("Pass")
                            ? PlayerMove.Pass
                            : canDrop && response.EqualsCI("Drop")
                                ? PlayerMove.Drop
                                : PlayerMove.Move;
            card = theMove == PlayerMove.Move ? Deck.Parse(response) : null;

            if (log.IsDebugEnabled)
                log.Debug("CardMove {0}: {1} {2}", prompt, theMove, card);

            return theMove;
        }
Example #3
0
        public PlayerMove AskMove(out Card card)
        {
            var hand = GameState.States[this].Hand;
            card = null;

            if (hand.Count == 0 || random.Next(100) > 90)
            {
                ConsoleHelper.MyStatus("Passing. (Cards: " + hand.Count + ")");

                return PlayerMove.Pass;
            }

            card = hand[random.Next(hand.Count)];
            ConsoleHelper.MyStatus("Playing " + card);

            return PlayerMove.Move;
        }
Example #4
0
        public PlayerMove AskMove(out Card card)
        {
            card = null;

            while (true)
            {
                try
                {
                    var line = ConsoleHelper.Prompt("Your move?");

                    if (line.Equals("fail", StringComparison.OrdinalIgnoreCase))
                    {
                        // debug
                        card = new Card((CardType)(-1234));

                        return PlayerMove.Move;
                    }

                    if (line.Equals("pass", StringComparison.OrdinalIgnoreCase))
                        return PlayerMove.Pass;

                    if (line.Equals("drop", StringComparison.OrdinalIgnoreCase))
                        return PlayerMove.Drop;

                    card = Deck.Parse(line);
                    if (!GameState.States[this].Hand.Contains(card, CardEQC.Instance))
                        throw new InvalidOperationException("You don't have this card.");

                    return PlayerMove.Move;
                }
                catch (Exception e)
                {
                    ConsoleHelper.Error(e.Message);
                    ConsoleHelper.DumpCards("Your cards:", GameState.States[this].Hand);
                }
            }
        }
Example #5
0
        public PlayerMove RetrieveCard(out Card card)
        {
            card = null;

            var desk = GameState.States[this].Desk;
            if (desk.Count == 0)
            {
                ConsoleHelper.MyStatus("Desk empty, retrieving nothing.");

                return PlayerMove.Pass;
            }

            if (desk.All(c => c.IsSpecial))
            {
                ConsoleHelper.MyStatus("Desk is all special, retrieving nothing.");

                return PlayerMove.Pass;
            }

            while (true)
            {
                if (random.Next(100) > 90)
                {
                    ConsoleHelper.MyStatus("Retrieving nothing.");

                    return PlayerMove.Pass;
                }

                card = desk[random.Next(desk.Count)];
                if (!card.IsSpecial) break;
            }

            ConsoleHelper.MyStatus("Retrieving " + card);

            return PlayerMove.Move;
        }
Example #6
0
        private bool TryTake(out Card card)
        {
            var retval = content.Count > 0;

            card = retval ? content.Dequeue() : null;

            return retval;
        }
Example #7
0
 public PlayerMove RetrieveCard(out Card card)
 {
     return DoAskForCardMove("?Retrieve", false, out card);
 }
Example #8
0
 public PlayerMove AskMove(out Card card)
 {
     return DoAskForCardMove("?Move", true, out card);
 }
Example #9
0
 public PlayerMove RetrieveCard(out Card card)
 {
     throw new NotImplementedException();
 }
Example #10
0
 public PlayerMove AskMove(out Card card)
 {
     throw new NotImplementedException();
 }
Example #11
0
        internal void CurrentPlayerDeal(Card card)
        {
            var state = States[CurrentPlayer];
            var instance = state.Hand.FirstOrDefault(c => c.Kind == card.Kind);

            // not null if CurrentPlayer is either Me or an Other with a retrieved card
            if (instance != null)
                state.Hand.Remove(instance);

            // some cards go into pool immediately
            if (!cardToPool.Contains(card.Kind))
                state.Desk.Add(card);
        }
Example #12
0
        internal void CurrentPlayerScarecrowed(Card card)
        {
            if (card != null)
            {
                var state = States[CurrentPlayer];

                state.Hand.Add(card);
                state.Desk.Remove(state.Desk.First(c => c.Kind == card.Kind));
            }
        }
Example #13
0
 public void Add(Card card)
 {
     content.Enqueue(card);
 }
Example #14
0
        private bool TryTake(int count, out Card[] cards)
        {
            var retval = content.Count > 0;
            cards = new Card[Math.Min(count, content.Count)];

            for (var i = 0; i < cards.Length; i++)
                cards[i] = content.Dequeue();

            return retval;
        }
Example #15
0
 public void Pool(Card card)
 {
     pool.Add(card);
 }
Example #16
0
        private void FromHandToPool(Player p, Card c)
        {
            var state = states[p];

            deck.Pool(c);
            state.Hand.Remove(c);
        }
Example #17
0
        private void FromHandToDesk(Player p, Card c)
        {
            var state = states[p];

            Debug.Assert(state.Hand.Contains(c));
            Debug.Assert(!state.Desk.Contains(c));

            state.Hand.Remove(c);
            state.Desk.Add(c);
        }
Example #18
0
        /// <summary>
        /// The player can move one card from Desk to Hand.
        /// </summary>
        public void RetrieveCard(Player p, Card card)
        {
            ExpectStep(Steps.RetrieveCard);
            ExpectCurrentPlayer(p);

            // -> selected card goes into hand (from desk)
            // specials cannot be retrieved
            // if card is null the player did not retrieve anything
            if (card != null)
            {
                var instance = ExpectInstanceOnDesk(p, card.Kind);
                if (instance.IsSpecial)
                    throw new InvalidOperationException("Special cards cannot be retrieved. ({0}, {1})".F(p, card));

                FromDeskToHand(p, instance);
            }

            // sc -> pool
            FromHandToPool(p, ExpectInstanceInHand(p, CardType.Scarecrow));

            CurrentStep = Steps.PlayerDone;
        }
Example #19
0
        public void PlayCard(Player p, Card card)
        {
            ExpectStep(Steps.PlayerStart);
            ExpectCurrentPlayer(p);

            if (IsDebugEnabled) log.Debug("{0} played card {1}", p, card);

            card = ExpectInstanceInHand(p, card.Kind);

            // when a card transitions into a different state
            // then its state handler will select the next player
            switch (card.Kind)
            {
                // ask the player to select
                // which card to retrieve from the desk
                case CardType.Scarecrow:
                    CurrentStep = Steps.RetrieveCard;
                    return;

                // ask the player to protect/unprotect a zone
                // remove top non-specials
                case CardType.Bishop:
                    CurrentStep = Steps.ProtectZone;
                    return;

                // end of battle
                case CardType.Key:
                    FromHandToPool(p, card);
                    explicitNext = Steps.Key;
                    return;

                // remove all winters from desk
                case CardType.Spring:
                    FromDeskToPool(CardType.Winter);
                    break;

                // remove all springs from desk
                case CardType.Winter:
                    FromDeskToPool(CardType.Spring);
                    break;
            }

            CurrentStep = Steps.PlayerDone;
            // just place the card on the desk
            FromHandToDesk(p, card);
        }