示例#1
0
    def setUp(self):
        # Traits (Trait, Food-value)
        self.carnivore = TraitCard(CARNIVORE, 3)
        self.burrowing = TraitCard(BURROWING, 2)
        self.fattissue = TraitCard(FATTISSUE, 4)
        self.foraging = TraitCard(FORAGING, 2)
        self.horns = TraitCard(HORNS, 6)
        self.cooperation = TraitCard(COOPERATION, 1)
        self.scavenger = TraitCard(SCAVENGER, 2)

        # Species (Population, Food, Body, Traits, Fat-Storage)
        self.species1 = Species(1, 0, 2, [self.cooperation])
        self.species2 = Species(6, 2, 1, [self.carnivore])
        self.species3 = Species(3, 3, 3, [self.fattissue], 0)
        self.species4 = Species(5, 5, 5, [self.burrowing])
        self.species5 = Species(5, 3, 4, [self.foraging])
        self.species6 = Species(
            2, 1, 7, [self.carnivore, self.fattissue, self.scavenger], 0)
        self.species7 = Species(7, 1, 6, [self.horns])

        self.player1_species = [self.species1, self.species2]
        self.player2_species = [self.species3, self.species4, self.species5]
        self.player3_species = [self.species6, self.species7]

        # Players (Name, Bag, Hand, Species)
        self.player1 = PlayerState(1, 0, [self.fattissue],
                                   self.player1_species)
        self.player2 = PlayerState(2, 3, [self.fattissue, self.carnivore],
                                   self.player2_species)
        self.player3 = PlayerState(3, 6, [self.burrowing],
                                   self.player3_species)

        self.public_player1 = PlayerState(1, False, False,
                                          self.player1_species)
        self.public_player2 = PlayerState(2, False, False,
                                          self.player2_species)
        self.public_player3 = PlayerState(3, False, False,
                                          self.player3_species)

        self.list_of_players = [self.player1, self.player2, self.player3]

        # Dealer (List of Players, Watering Hole, Deck)
        self.dealer1 = Dealer(self.list_of_players, 10, [])

        # Actions
        self.food_card_action1 = FoodCardAction(0)
        self.food_card_action2 = FoodCardAction(1)
        self.grow_action_pop = GrowAction(POPULATION, 0, 0)
        self.grow_action_body = GrowAction(BODY, 1, 1)
        self.add_species_action1 = AddSpeciesAction(0, [1])
        self.add_species_action2 = AddSpeciesAction(0, [])
        self.replace_trait_action1 = ReplaceTraitAction(0, 0, 0)
        self.replace_trait_action2 = ReplaceTraitAction(2, 0, 1)
        self.replace_trait_action3 = ReplaceTraitAction(0, 2, 0)

        # Action4
        self.action4_1 = Action4(self.player1, [self.food_card_action1])
        self.action4_2 = Action4(
            self.player2, [self.food_card_action2, self.grow_action_pop])
    def setUp(self):
        # Traits (Trait, Food-value)
        self.carnivore = TraitCard(CARNIVORE, 3)
        self.burrowing = TraitCard(BURROWING, 2)
        self.fattissue = TraitCard(FATTISSUE, 2)
        self.foraging = TraitCard(FORAGING, 2)
        self.horns = TraitCard(HORNS, 0)
        self.cooperation = TraitCard(COOPERATION, 1)
        self.scavenger = TraitCard(SCAVENGER, 2)

        # Species (Population, Food, Body, Traits, Fat-Storage)
        self.species1 = Species(1, 0, 2, [self.cooperation])
        self.species2 = Species(6, 2, 1, [self.carnivore])
        self.species3 = Species(3, 3, 3, [self.fattissue], 0)
        self.species4 = Species(5, 5, 5, [self.burrowing])
        self.species5 = Species(5, 3, 4, [self.foraging])
        self.species6 = Species(
            2, 1, 7, [self.carnivore, self.fattissue, self.scavenger], 0)
        self.species7 = Species(7, 1, 6, [self.horns])

        self.player1_species = [self.species1, self.species2]
        self.player2_species = [self.species3, self.species4, self.species5]
        self.player3_species = [self.species6, self.species7]

        # Players (Name, Bag, Hand, Species)
        self.player1 = PlayerState(1,
                                   0, [self.horns, self.foraging],
                                   self.player1_species,
                                   ext_player=Player())
        self.player2 = PlayerState(2,
                                   3, [self.carnivore, self.fattissue],
                                   self.player2_species,
                                   ext_player=Player())
        self.player3 = PlayerState(3,
                                   6, [self.burrowing],
                                   self.player3_species,
                                   ext_player=Player())

        self.public_player1 = PlayerState(1, False, False,
                                          self.player1_species)
        self.public_player2 = PlayerState(2, False, False,
                                          self.player2_species)
        self.public_player3 = PlayerState(3, False, False,
                                          self.player3_species)

        self.list_of_players = [self.player1, self.player2, self.player3]

        # Dealer (List of Players, Watering Hole, Deck)
        self.dealer1 = Dealer(self.list_of_players, 10, [])

        # Action
        self.action4_1 = Action4(FoodCardAction(1),
                                 [GrowAction(POPULATION, 0, 0)], [], [], [])
        self.action4_2 = Action4(FoodCardAction(0), [], [], [],
                                 [ReplaceTraitAction(1, 0, 1)])
        self.action4_3 = Action4(FoodCardAction(0), [], [], [], [])
        self.action4_list = [self.action4_1, self.action4_2, self.action4_3]
示例#3
0
    def choose(self, befores, afters):
        cheat = (random.random() > 0.5)
        cardsWIdx = [(i, self.state.hand[i])
                     for i in range(len(self.state.hand))]
        cards = sorted(cardsWIdx, key=lambda x: x[1], cmp=TraitCard.compare)
        maxCardIdx = len(cards) - 1
        newSpecIdx = len(self.state.species)
        curCardIdx = 3

        if cheat:
            print "cheating with double-spending and card replacement!"
            gp = [GainPopulation(newSpecIdx, maxCardIdx)]
            gb = [GainBodySize(newSpecIdx, maxCardIdx)]  # double-spend
            rt = [
                ReplaceTrait(newSpecIdx, 1, curCardIdx)
            ]  # try to place on a non-placed trait card with a legal card
        else:
            gp = [GainPopulation(newSpecIdx, cards[curCardIdx][0])
                  ] if curCardIdx <= maxCardIdx else []
            curCardIdx += 1
            gb = [GainBodySize(newSpecIdx, cards[curCardIdx][0])
                  ] if curCardIdx <= maxCardIdx else []
            curCardIdx += 1
            rt = [ReplaceTrait(newSpecIdx, 0, cards[curCardIdx][0])
                  ] if curCardIdx <= maxCardIdx else []

        return Action4(cards[0][0], gp, gb,
                       [BuySpeciesBoard(cards[1][0], [cards[2][0]])], rt)
    def choose(self, left_players, right_players):
        """
        Determines the actions the this player wants to perform for this turn.
        :param left_players: the players to the left of this player.
        :param right_players: the players to the right of this player.
        :return: Action4 for the actions they want to perform
        """
        hand = self.player_state.hand
        cards_in_order = sorted(hand,
                                key=lambda card:
                                (card.trait, card.food_points))
        food_action = FoodCardAction(hand.index(cards_in_order[0]))
        add_species_actions = [
            AddSpeciesAction(hand.index(cards_in_order[1]),
                             [hand.index(cards_in_order[2])])
        ]
        grow_pop_actions = []
        grow_body_actions = []
        replace_trait_actions = []
        new_spec_index = len(self.player_state.species)
        if len(hand) > 3:
            grow_pop_actions.append(
                GrowAction(POPULATION, new_spec_index,
                           hand.index(cards_in_order[3])))
        if len(hand) > 4:
            grow_body_actions.append(
                GrowAction(BODY, new_spec_index,
                           hand.index(cards_in_order[4])))
        if len(hand) > 5:
            replace_trait_actions.append(
                ReplaceTraitAction(new_spec_index, 0,
                                   hand.index(cards_in_order[5])))

        return Action4(food_action, grow_pop_actions, grow_body_actions,
                       add_species_actions, replace_trait_actions)
示例#5
0
	def choose(self, befores, afters):
		befores = [[Species.speciesToJson(spec) for spec in player] for player in befores]
		afters = [[Species.speciesToJson(spec) for spec in player] for player in afters]
		time.sleep(.01)
		self.sock.sendall(json.dumps([befores, afters]))
		resp = self.getResponse()
		if resp != constants.KICK_ME:
			return Action4.actionFromJson(resp)
		else:
			return False
示例#6
0
	def choose(self, befores, afters):
		cardsWIdx = [(i, self.state.hand[i]) for i in range(len(self.state.hand))]
		cards = sorted(cardsWIdx, key=lambda x: x[1], cmp=TraitCard.compare) 
		maxCardIdx = len(cards) - 1
		newSpecIdx = len(self.state.species)
		curCardIdx = 3
		
		gp = [GainPopulation(newSpecIdx, cards[curCardIdx][0])] if curCardIdx <= maxCardIdx else []
		curCardIdx += 1
		gb = [GainBodySize(newSpecIdx, cards[curCardIdx][0])] if curCardIdx <= maxCardIdx else []
		curCardIdx += 1
		rt = [ReplaceTrait(newSpecIdx, 0, cards[curCardIdx][0])] if curCardIdx <= maxCardIdx else []

		return Action4(cards[0][0], gp, gb, [BuySpeciesBoard(cards[1][0], [cards[2][0]])], rt) 
示例#7
0
    def setUp(self):
        self.t1 = TraitCard("horns", 3)
        self.t2 = TraitCard("ambush", 1)
        self.t3 = TraitCard("carnivore", 2)
        self.t4 = TraitCard("fat-tissue", 0)
        self.t5 = TraitCard("foraging", 3)
        self.vegHorns = Species(1, 2, 3, [TraitCard("horns")], 0)
        self.vegCoop = Species(1, 2, 3, [TraitCard("cooperation")], 0)
        self.fat = Species(4, 3, 4, [TraitCard("fat-tissue")], 3)
        self.fatScav = Species(
            2, 3, 4, [TraitCard("fat-tissue"),
                      TraitCard("scavenger")], 1)
        self.fatFor = Species(4, 3, 4,
                              [TraitCard("fat-tissue"),
                               TraitCard("foraging")], 1)
        self.carnCoop = Species(
            3, 4, 5, [TraitCard("carnivore"),
                      TraitCard("cooperation")], 0)
        self.carnForage = Species(
            3, 4, 5, [TraitCard("carnivore"),
                      TraitCard("foraging")], 0)
        self.carnForage1 = Species(
            3, 4, 5, [TraitCard("carnivore"),
                      TraitCard("foraging")], 0)
        self.extinct = Species(0, 0, 0, [], 0)
        self.p1 = PlayerState(1, 0, [self.vegCoop, self.fat, self.carnForage],
                              [])
        self.p2 = PlayerState(2, 0,
                              [self.vegHorns, self.fatScav, self.carnCoop], [])
        self.p3 = PlayerState(3, 0,
                              [self.vegCoop, self.carnCoop, self.carnForage1],
                              [])
        self.p4 = PlayerState(4, 0, [self.vegCoop], [])
        self.p5 = PlayerState(5, 0, [self.vegHorns], [])
        self.p6 = PlayerState(6, 0, [self.carnCoop], [])
        self.p7 = PlayerState(7, 0, [self.fatScav], [])
        self.p8 = PlayerState(8, 0, [self.fatFor, self.extinct], [])
        self.dealer = Dealer([self.p1, self.p2, self.p3], 3,
                             [self.t1, self.t2, self.t3, self.t4, self.t5])
        self.p2dealer = Dealer([self.p6, self.p5], 3, [])
        self.p3dealer = Dealer([self.p8], 3,
                               [self.t1, self.t2, self.t3, self.t4, self.t5])

        self.xstep3spec = Species(0, 5, 2, [TraitCard("foraging")], 0)
        self.xstep3p = PlayerState(1, 0, [self.xstep3spec], [])
        self.xstep3deal = Dealer([self.xstep3p], 5, [])

        # 8949-0357-4
        self.pCFS1 = PlayerState(1, 3, [
            Species(4, 2, 5,
                    [TraitCard("carnivore"),
                     TraitCard("cooperation")], 0),
            Species(1, 3, 4, [
                TraitCard("foraging"),
                TraitCard("carnivore"),
                TraitCard("scavenger")
            ], 0)
        ], [])
        self.pCFS2 = PlayerState(
            2, 4, [Species(2, 3, 3, [TraitCard("burrowing")], 0)], [])
        self.pCFS3 = PlayerState(3, 5, [], [])
        self.dCFS = Dealer([self.pCFS1, self.pCFS2, self.pCFS3], 10, [])

        # for step4
        self.t6 = TraitCard("herding", 0)
        self.defSpec = Species(0, 0, 1, [], 0)
        self.specWGrownBody = Species(0, 1, 1, [], 0)
        self.specW3t = Species(0, 0, 1, [self.t3, self.t4, self.t5], 0)
        self.specWAll = Species(2, 1, 2, [self.t4], 1)
        self.playerWithManyCards = PlayerState(
            1, 0, [], [self.t1, self.t2, self.t3, self.t4, self.t5, self.t6])
        self.playerForAll = PlayerState(1, 0, [self.specWAll], [])
        self.playerFor3t = PlayerState(1, 0, [self.specW3t], [self.t6])
        self.playerForDefSpec = PlayerState(1, 0, [self.defSpec],
                                            [self.t5, self.t6])
        self.playerForBodyNewSpec = PlayerState(
            1, 0, [self.specWGrownBody], [self.t3, self.t4, self.t5, self.t6])
        self.noAct = Action4(0, [], [], [], [])
        self.actGP = Action4(0, [GainPopulation(0, 0)], [], [], [])
        self.actGB = Action4(0, [], [GainBodySize(0, 1)], [], [])
        self.actRT = Action4(0, [], [], [], [ReplaceTrait(0, 1, 1)])
        self.actBT0t = Action4(0, [], [], [BuySpeciesBoard(1, [])], [])
        self.actBT1t = Action4(0, [], [], [BuySpeciesBoard(1, [2])], [])
        self.actBT2t = Action4(0, [], [], [BuySpeciesBoard(1, [2, 3])], [])
        self.actBT3t = Action4(0, [], [], [BuySpeciesBoard(1, [2, 3, 4])], [])
        self.actBT4t = Action4(0, [], [], [BuySpeciesBoard(1, [2, 3, 4, 5])],
                               [])
        self.addBodyToNewSpec = Action4(0, [GainPopulation(1, 1)], [],
                                        [BuySpeciesBoard(2, [3])], [])
        self.actAll = Action4(0, [GainPopulation(0, 1)], [GainBodySize(0, 2)],
                              [BuySpeciesBoard(4, [5])],
                              [ReplaceTrait(0, 0, 3)])
        self.simpleDealerForStep4 = Dealer([self.playerWithManyCards], 0, [])
        self.dealerForRevokingCards = Dealer([
            PlayerState(1, 0, [], [self.t1, self.t2]),
            PlayerState(2, 0, [], [self.t3, self.t4, self.t5]),
            PlayerState(3, 0, [], [self.t6])
        ], 0, [])

        self.dealerManyActions = Dealer([
            PlayerState(1, 0, [self.defSpec], [self.t1, self.t2]),
            PlayerState(2, 0, [self.vegHorns, self.fatScav, self.carnCoop],
                        [self.t3, self.t4, self.t5, self.t6, self.t1]),
            PlayerState(3, 0, [self.vegCoop, self.carnCoop, self.carnForage1],
                        [self.t6])
        ], 0, [])
示例#8
0
 def setUp(self):
     self.t1 = TraitCard("horns", 3)
     self.t2 = TraitCard("ambush", 1)
     self.t3 = TraitCard("carnivore", 2)
     self.t4 = TraitCard("fat-tissue", 0)
     self.t5 = TraitCard("foraging", 3)
     self.t6 = TraitCard("herding", 0)
     self.defSpec = Species(0, 0, 1, [], 0)
     self.specWGrownBody = Species(0, 1, 1, [], 0)
     self.specW3t = Species(0, 0, 1, [self.t3, self.t4, self.t5], 0)
     self.specWAll = Species(0, 1, 2, [self.t4], 0)
     self.playerWithManyCards = PlayerState(
         1, 0, [], [self.t1, self.t2, self.t3, self.t4, self.t5, self.t6])
     self.playerForAll = PlayerState(1, 0, [self.specWAll], [])
     self.playerFor3t = PlayerState(1, 0, [self.specW3t], [self.t6])
     self.playerForDefSpec = PlayerState(1, 0, [self.defSpec],
                                         [self.t5, self.t6])
     self.playerForBodyNewspec = PlayerState(
         1, 0, [self.specWGrownBody], [self.t3, self.t4, self.t5, self.t6])
     self.noAct = Action4(0, [], [], [], [])
     self.actGP = Action4(0, [GainPopulation(0, 1)], [], [], [])
     self.actGB = Action4(0, [], [GainBodySize(0, 1)], [], [])
     self.actRT = Action4(0, [], [], [ReplaceTrait(0, 1, 1)], [])
     self.actBT0t = Action4(0, [], [], [], [BuySpeciesBoard(1, [])])
     self.actBT1t = Action4(0, [], [], [], [BuySpeciesBoard(1, [2])])
     self.actBT2t = Action4(0, [], [], [], [BuySpeciesBoard(1, [2, 3])])
     self.actBT3t = Action4(0, [], [], [], [BuySpeciesBoard(1, [2, 3, 4])])
     self.actBT4t = Action4(0, [], [], [],
                            [BuySpeciesBoard(1, [2, 3, 4, 5])])
     self.addBodyToNewSpec = Action4(0, [GainPopulation(1, 1)], [], [],
                                     [BuySpeciesBoard(2, [3])])
     self.actAll = Action4(0, [GainPopulation(0, 1)], [GainBodySize(0, 2)],
                           [ReplaceTrait(0, 0, 3)],
                           [BuySpeciesBoard(4, [5])])