Ejemplo n.º 1
0
 def noCards(self):
     """ Test that if the source has no cards, the condition returns false """
     event = CardsEvent([], None, BuildPlayerContext())
     result = HasCards(EVENT).evaluate(event.context)
     self.assertFalse(
         result,
         "The Condition should be false, if the source has no cards")
Ejemplo n.º 2
0
 def perform(self, context):
     """ Perform the Game Effect """
     allCardsToPass = []
     zones = []
     for foe in context.foes:
         playerContext = context.getPlayerContext(foe)
         zone = playerContext.loadZone(self.zoneType)
         
         for toDescription, target in zip(["pass to the previous player", "pass to the next player"], [playerContext.previousPlayer, playerContext.nextPlayer]):
             cards = yield PickCardRequest(zone, foe, 1, toDescription)
             
             event = CardsEvent(cards, zone, playerContext)
             placeholderZone = ListZone([])
             MoveCard(EVENT, HAND).moveCards(event.context.loadZone(EVENT), placeholderZone)
             
             cardsToPass = CardsToPass(placeholderZone, target)
             allCardsToPass.append(cardsToPass)
             
     for cardsToPass in allCardsToPass:
         coroutine = cardsToPass.passCards(context)
         try:
             response = yield coroutine.next()
             while True:
                 response = yield coroutine.send(response)
         except StopIteration:
             pass
Ejemplo n.º 3
0
 def criteriaUsed(self):
     """ Test that the condition is false, if the criteria limits the matches below the required number """
     name = "Test Name"
     cards = [BuildCard(name=name) for i in range(10)]
     event = CardsEvent(cards, None, BuildPlayerContext())
     result = Matching(EVENT, criteria=FixedCriteria("name", name, "!=")).evaluate(event.context)
     self.assertFalse(result, "The Condition should be false, if the criteria limits the matching cards")
Ejemplo n.º 4
0
    def perform(self, context):
        """ Perform the Game Effect """
        typeToFunction = {TOP: self.getTopCards, PICK: self.pickCards}
        function = typeToFunction[self.pickType]

        self.cardsForFoes = []
        zones = []
        for foe in context.foes:
            playerContext = context.getPlayerContext(foe)
            zone = playerContext.loadZone(self.zoneType)
            coroutine = RunCoroutineOrFunction(
                function, [playerContext, zone, self.number])
            try:
                response = yield coroutine.next()
                while True:
                    response = yield coroutine.send(response)
            except StopIteration:
                pass
            event = CardsEvent(self.cardsForFoes, zone, playerContext)
            zones.append(EventZone(event))

        event = MultiZoneEvent(zones, context)
        coroutine = PerformEffects(self.thenEffects, event.context)
        response = yield coroutine.next()
        while True:
            response = yield coroutine.send(response)
Ejemplo n.º 5
0
 def emptyFilter(self):
     """ Test that if the filter returns no cards, the condition returns false """
     event = CardsEvent([], None, BuildPlayerContext())
     result = HasCards(EVENT, filter=DummyFilter()).evaluate(event.context)
     self.assertFalse(
         result,
         "The Condition should be false, if the filter returns no cards")
Ejemplo n.º 6
0
 def filterHasCards(self):
     """ Test that if the filter returns cards, the condition returns true """
     event = CardsEvent([1, 2, 3], None, BuildPlayerContext())
     result = HasCards(EVENT,
                       filter=DummyFilter(results=[1, 2, 3])).evaluate(
                           event.context)
     self.assertTrue(
         result,
         "The Condition should be true, if the filter returns cards")
Ejemplo n.º 7
0
    def performEffects(self, context):
        """ Perform the Game Effect """
        zone = context.loadZone(self.zoneType)
        cards = zone[:self.number]
        event = CardsEvent(cards, zone, context)

        coroutine = ConditionalEffect.performEffects(self, event.context)
        response = yield coroutine.next()
        while True:
            response = yield coroutine.send(response)
Ejemplo n.º 8
0
 def gainCard(self, card, fromZone, toZone=None, game=None):
     """ Gain the provided card """
     fromZone.remove(card)
     toZone.add(card)
     event = CardsEvent([card], toZone,
                        PlayerContext(game, card, player=self))
     coroutine = PerformEffects(card.onGainEffects, event.context)
     response = yield coroutine.next()
     while True:
         response = yield coroutine.send(response)
Ejemplo n.º 9
0
    def perform(self, context):
        """ Perform the Game Effect """
        zone = context.loadZone(self.zoneType)
        possibleCards = self.filter.evaluate(context)

        event = CardsEvent(possibleCards, zone, context)
        coroutine = PerformEffects(self.thenEffects, event.context)
        response = yield coroutine.next()
        while True:
            response = yield coroutine.send(response)
Ejemplo n.º 10
0
 def perform(self, context):
     """ Perform the Game Effect """
     zone, cards = self.findPossibleCards(context)
     for card in cards:
         event = CardsEvent([card], zone, context)
         coroutine = PerformEffects(self.effects, event.context)
         try:
             response = yield coroutine.next()
             while True:
                 response = yield coroutine.send(response)
         except StopIteration:
             pass
Ejemplo n.º 11
0
    def buildEvent(self, cards, possibleCardsPerZone, context):
        """ Build the proper event for the chosen cards """
        cardsPerZone = {}
        for card in cards:
            for zone in possibleCardsPerZone:
                if card in zone:
                    if zone in cardsPerZone:
                        cardsPerZone[zone].append(card)
                    else:
                        cardsPerZone[zone] = [card]
                    break

        zones = [
            EventZone(CardsEvent(cardsPerZone[zone], zone, context))
            for zone in cardsPerZone
        ]
        return MultiZoneEvent(zones, context)
Ejemplo n.º 12
0
 def setUp(self):
     """ Build the Event for the test """
     self.name = "Test Name"
     self.cardType = "A Type"
     self.event = CardsEvent([BuildCard(self.name, cardType=self.cardType)],
                             None, BuildPlayerContext())
Ejemplo n.º 13
0
 def setUp(self):
     """ Build the Filter for the test """
     self.cardName = "Blah Blah"
     self.cards = [BuildCard(name=self.cardName) for i in range(10)]
     cardsEvent = CardsEvent(self.cards, None, BuildPlayerContext())
     self.context = cardsEvent.context
Ejemplo n.º 14
0
 def notEnoughMatches(self):
     """ Test that the condition is false, if there are not enough matching cards """
     cards = [1,2,3]
     event = CardsEvent(cards, None, BuildPlayerContext())
     result = Matching(EVENT, number=len(cards)+1).evaluate(event.context)
     self.assertFalse(result, "The Condition should be false, if there are not enough matching cards")
Ejemplo n.º 15
0
 def passCards(self, context):
     """ Pass the cards to the target player """
     event = CardsEvent(self.cardsZone.cards, self.cardsZone, context.getPlayerContext(self.targetPlayer))
     return PerformEffect(MoveCard(EVENT, HAND), event.context)
Ejemplo n.º 16
0
 def matching(self):
     """ Test that the condition is true, if there are enough matching cards """
     event = CardsEvent([1], None, BuildPlayerContext())
     result = Matching(EVENT).evaluate(event.context)
     self.assertTrue(result, "The Condition should be true, if there are enough matching cards")
Ejemplo n.º 17
0
 def  setUp(self):
     """ Build the Zone and Criteria for the test """
     self.cardName = "Blah Blah"
     cardsEvent = CardsEvent([BuildCard(name=self.cardName)], None, BuildPlayerContext())
     self.context = cardsEvent.context
     self.criteria = ZoneCriteria("name", EVENT)
Ejemplo n.º 18
0
 def setUp(self):
     """ Build the Context for the test """
     self.name = "Test Name"
     self.event = CardsEvent([BuildCard(self.name)], None,
                             BuildPlayerContext())
Ejemplo n.º 19
0
 def hasCards(self):
     """ Test that if the source has cards, the condition returns true """
     event = CardsEvent([1, 2, 3], None, BuildPlayerContext())
     result = HasCards(EVENT).evaluate(event.context)
     self.assertTrue(
         result, "The Condition should be true, if the source has cards")
Ejemplo n.º 20
0
 def getRandomCards(self, context):
     """ Get Random Cards and return the proper event """
     zone = context.loadzone(self.zoneType)
     cards = random.sample(zone, self.getNumberOfCards(zone))
     return CardsEvent(cards, zone, context)