Ejemplo n.º 1
0
        public override bool Equals(object obj)
        {
            if (!(obj is PendingPlay))
            {
                return(false);
            }
            PendingPlay other = (PendingPlay)obj;

            return(this == other);
        }
Ejemplo n.º 2
0
    public void NotifyAction(int currentPlayer, Action action, ActionResult result)
    {
        if (action.Type == ActionType.Discard || action.Type == ActionType.Play)
        {
            hand_knowledge_[currentPlayer].RemoveAt(action.Card);


            public_cards_.Add(result.Card);
            if (result.NewCard)
            {
                hand_knowledge_[currentPlayer].Add(new PossibleCard());
                MakeDeductionsFromKnowledge();
            }
            else
            {
                int i = 0;
            }


            if (action.Type == ActionType.Play && result.Accepted)
            {
                if (view_.ActualPlayerId == 2)
                {
                    view_.Log("Play action noticed: P{0}->{1} pending_plays={2}", currentPlayer, action.Card, string.Join(", ", pending_plays_));
                }
                for (int i = 0; i < pending_plays_.Count; i++)
                {
                    if (pending_plays_[i].Player == currentPlayer && pending_plays_[i].Index == action.Card)
                    {
                        pending_plays_.RemoveAt(i);
                        break;
                    }
                }
                //XXX shouldn't do this sort of shuffling
                for (int i = 0; i < pending_plays_.Count; i++)
                {
                    if (pending_plays_[i].Player == currentPlayer && pending_plays_[i].Index > action.Card)
                    {
                        pending_plays_[i] = new PendingPlay(currentPlayer, pending_plays_[i].Index - 1);
                    }
                }
                if (view_.ActualPlayerId == 2)
                {
                    view_.Log("pending_plays={0}", string.Join(", ", pending_plays_));
                }

                playable_cards_.Remove(result.Card);
                useless_cards_.Add(result.Card);
                unsafe_cards_.Remove(result.Card);
                if (result.Card.Number != 5)
                {
                    playable_cards_.Add(new Card(result.Card.Colour, result.Card.Number + 1));
                }
            }
            else
            {
                if (unsafe_cards_.Contains(result.Card))
                {
                    // Ooops!
                    // System.Console.WriteLine("Ooops! Discarded last {0}", result.Card);
                    unsafe_cards_.Remove(result.Card);
                }
                else if (!useless_cards_.Contains(result.Card))
                {
                    if (public_cards_.Count(c => c == result.Card) == value_counts_[result.Card.Number - 1] - 1)
                    {
                        unsafe_cards_.Add(result.Card);
                    }
                }
            }
        }

        if (action.Type == ActionType.Clue)
        {
            ApplyClueToKnowledge(hand_knowledge_[action.TargetPlayer], action, result);
            MakeDeductionsFromKnowledge();
            HandleClueLogic(currentPlayer, action, result);
            MakeDeductionsFromKnowledge();
        }
    }