Beispiel #1
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])])
Beispiel #2
0
    def testStep4(self):
        # successfully adding three traits to a new species
        self.playerWithManyCards = PlayerState(
            1, 0, [], [self.t1, self.t2, self.t3, self.t4, self.t5, self.t6])
        self.simpleDealerForStep4 = Dealer([self.playerWithManyCards], 0, [])
        self.simpleDealerForStep4.step4([self.actBT3t])
        self.assertEqual(len(self.playerFor3t.hand), 1)
        self.assertEqual(len(self.playerFor3t.species), 1)
        self.assertEqual(len(self.playerFor3t.species[0].traits), 3)
        self.assertEqual(self.simpleDealerForStep4.players[0],
                         self.playerFor3t)
        for card in [self.t1, self.t2, self.t3, self.t4, self.t5]:
            self.assertTrue(card in self.simpleDealerForStep4.discard)

        # test adding a species, then growing its population and body and giving it a new trait
        self.playerWithManyCards = PlayerState(
            1, 0, [], [self.t1, self.t2, self.t3, self.t4, self.t5, self.t6])
        self.simpleDealerForStep4 = Dealer([self.playerWithManyCards], 0, [])
        self.simpleDealerForStep4.step4([self.actAll])
        self.assertEqual(len(self.playerForAll.hand), 0)
        self.assertEqual(len(self.playerForAll.species), 1)
        self.assertEqual(len(self.playerForAll.species[0].traits), 1)
        self.assertEqual(self.simpleDealerForStep4.players[0],
                         self.playerForAll)
        self.assertEqual(self.simpleDealerForStep4.players[0].species,
                         [self.specWAll])
        for card in [self.t1, self.t2, self.t3, self.t4, self.t5, self.t6]:
            self.assertTrue(card in self.simpleDealerForStep4.discard)
        self.assertEqual(self.simpleDealerForStep4.wateringHole, 0)
Beispiel #3
0
	def setUp(self):
		self.big = Species(food=5, body=1, population=6, traits=[TraitCard("fat-tissue"), TraitCard("carnivore")], fatFood=0)
		self.aCarnivore = Species(food=1, body=2, population=4, traits=[TraitCard("carnivore")], fatFood=0)
		self.fedVeg = Species(food=3, body=4, population=3, traits=[], fatFood=0)
		self.smallerVeg = Species(food=1, body=4, population=2, traits=[], fatFood=0)
		self.smallerFatTissue = Species(food=0, body=4, population=2, traits=[TraitCard("fat-tissue")], fatFood=0)
		# TODO: should food = 2 here, or 0?
		self.fedFatTissue = Species(food=0, body=3, population=2, traits=[TraitCard("fat-tissue")], fatFood=3)
		self.ourSpecies = [self.big, self.aCarnivore, self.fedVeg, self.smallerVeg, self.smallerFatTissue]
		self.ourIndexedSpecies = [(0, self.big), (1, self.aCarnivore), (2, self.fedVeg), (3, self.smallerVeg), (4, self.smallerFatTissue)]
		self.noFatTissue = [self.aCarnivore, self.fedVeg, self.smallerVeg]
		self.noFatTissueIndexed = [(0, self.aCarnivore), (1, self.fedVeg), (2, self.smallerVeg)]
		self.noVeg = [self.big, self.aCarnivore]
		self.noVegIndexed = [(0, self.big), (1, self.aCarnivore)]
		self.aPlayerState = PlayerState(1, 0, self.ourSpecies, [])
		self.big_json = self.big.speciesToJson()
		self.aCarnivore_json = self.aCarnivore.speciesToJson()
		self.fedVeg_json = self.fedVeg.speciesToJson()
		self.smallerVeg_json = self.smallerVeg.speciesToJson()        
		self.bPlayerState = PlayerState.playerStateFromJson([["id", 2],
						 ["species", [self.aCarnivore_json, self.fedVeg_json, self.smallerVeg_json]],
						 ["bag", 0]])
		self.cPlayerState = PlayerState.playerStateFromJson([["id", 3],
						 ["species", [self.big_json, self.aCarnivore_json]],
						 ["bag", 0]])
Beispiel #4
0
 def testFeed(self):
     self.assertEqual(
         SillyPlayer.feed(self.aPlayerState, 5,
                          [self.bPlayerState, self.cPlayerState]), [4, 4])
     self.assertEqual(
         SillyPlayer.feed(self.aPlayerState, 1,
                          [self.bPlayerState, self.cPlayerState]), [4, 1])
     self.assertEqual(
         SillyPlayer.feed(PlayerState(1, 0, [Species(0, 1, 2, [], 0)], []),
                          5, [self.bPlayerState, self.cPlayerState]), 0)
     self.assertEqual(
         SillyPlayer.feed(
             PlayerState(1, 0, [
                 Species(0, 1, 2,
                         [TraitCard("fat-tissue"),
                          TraitCard("carnivore")], 1),
                 Species(0, 1, 2, [], 0)
             ], []), 5, [self.bPlayerState, self.cPlayerState]), 1)
     # TODO: should the vegetarian fat-tissue haver be fed?
     self.assertEqual(
         SillyPlayer.feed(
             PlayerState(1, 0, [
                 Species(0, 1, 2, [TraitCard("fat-tissue")], 1),
                 Species(0, 1, 2, [], 0)
             ], []), 5, [self.bPlayerState, self.cPlayerState]), 0)
     self.assertEqual(
         SillyPlayer.feed(PlayerState(1, 0, [self.aCarnivore], []), 5,
                          [self.bPlayerState, self.cPlayerState]),
         [0, 1, 0])
     self.assertEqual(
         SillyPlayer.feed(
             PlayerState(1, 0, [self.fedVeg, self.aCarnivore], []), 5,
             [self.bPlayerState]), [1, 0, 0])
Beispiel #5
0
 def test0067_6(self):
     p1 = PlayerState(1, 0, [
         Species(0, 1, 1, ["carnivore"], 0),
         Species(1, 1, 1, ["horns", "cooperation"], 0),
         Species(1, 1, 1, [], 0)
     ], [])
     p2 = PlayerState(2, 0, [Species(0, 1, 1, [], 0)], [])
     p3 = PlayerState(3, 0, [
         Species(0, 1, 1, ["cooperation", "scavenger", "climbing"], 0),
         Species(0, 1, 2, ["scavenger", "cooperation", "climbing"], 0),
         Species(0, 1, 4, ["foraging", "climbing"], 0)
     ], [])
     self.assertEqual(SillyPlayer.feed(p1, 10, [p1, p2, p3]), [0, 1, 0])
Beispiel #6
0
    def __init__(self, players, verbose=True, requested_cards=[]):
        self.verbose = verbose
        self.turn_counter = 0
        self.winning_player = ''
        self.all_cards = copy.deepcopy(cards.base_cards)
        self.active_player = ''

        assert (len(requested_cards) <= 10)
        random_cards = []
        if len(requested_cards) < 10:
            random_cards = random.sample(list(cards.optional_cards.keys()),
                                         10 - len(requested_cards))
        for card_name in random_cards + requested_cards:
            self.all_cards[card_name] = copy.deepcopy(
                cards.optional_cards[card_name])

        if len(players) <= 2:
            for card_name in ('Estate', 'Duchy', 'Province'):
                self.all_cards[card_name].count = 8

        shuffle(players)
        draw_stack = ['Copper'] * 7 + ['Estate'] * 3

        self.player_states = {}
        for player in players:
            player_name, Interface = player
            shuffle(draw_stack)
            h = Interface(player_name, self)
            self.player_states[player_name] = PlayerState(
                self, [], draw_stack[:], [], player_name, h)
            h.set_player_state = self.player_states[player_name]
            self.player_states[player_name].draw_cards(5)
Beispiel #7
0
	def feed(self, curState, wateringHole, players):
		jsonState = PlayerState.stateToJson(curState)
		jsonState.append(wateringHole)
		jsonState.append([[Species.speciesToJson(spec) for spec in player.species] for player in players])
		time.sleep(.01) 
		self.sock.sendall(json.dumps(jsonState))
		return self.getResponse()
Beispiel #8
0
	def playerStateFromJson(state):
		id = 0
		bag = -1
		speciesList = []
		cards = []

		try:
			if state[0][0] == "id":
				id = state[0][1]

			if state[1][0] == "species":
				for species in state[1][1]:
					speciesList.append(JsonParsing.speciesFromJson(species))

			if state[2][0] == "bag":
				bag = state[2][1]

			if len(state) == 4 and state[3][0] == "cards":
				for card in state[3][1]:
					cards.append(JsonParsing.traitCardFromJson(card))

			if id > 0 and bag >= 0:
				return PlayerState(id, bag, speciesList, cards)

		except Exception as e:
			raise e
Beispiel #9
0
 def start(self, msg):
     """
     Effect: Parses the json message and call start on the Player
     :param msg: JSON playerState message
     :return: Void
     """
     watering_hole = msg[0]
     ps = PlayerState.from_json_state(msg[1:])
     self.player.start(ps, watering_hole)
Beispiel #10
0
 def feedNext(self, msg):
     """
     Effect: Parses the json message and calls feed on the Player. Sends json result of feed
     :param msg: JSON state of the game.
     :return: Void
     """
     feed_info = PlayerState.from_json_gamestate(msg)
     food_action = self.player.feedNext(feed_info[0], feed_info[1], feed_info[2])
     json_feeding = json.dumps(food_action.to_json())
     self.sock.send(json_feeding)
Beispiel #11
0
    def parse_choice(choice):
        """
        Parse a choice into a [PlayerState, listOf(Species), listOf(Species]
        :param choice: json list representing [playerstate, listof species, listof species]
        :return: [PlayerState, listOf(Species), listOf(Species)]
        """
        ps = PlayerState.convertPlayerState(choice[0])
        prev_species = [Species.convertSpecies(species) for species in [prev for prev in choice[1]]]
        later_species = [Species.convertSpecies(species) for species in [late for late in choice[2]]]

        return [ps, prev_species, later_species]
    def setUp(self):
        self.species1J = [["food", 3], ["body", 4], ["population", 5],
                          ["traits", ["carnivore"]]]
        self.species1 = Species(3, 4, 5, ["carnivore"], 0)
        self.species2J = [["food", 1], ["body", 3], ["population", 4],
                          ["traits", ["warning-call", "fat-tissue"]],
                          ["fat-food", 1]]
        self.species2 = Species(1, 3, 4, ["warning-call", "fat-tissue"], 1)

        self.avgSpeciesJ = [["food", 3], ["body", 4], ["population", 5],
                            ["traits", ["carnivore"]]]
        self.avgSpecies = Species(3, 4, 5, ["carnivore"], 0)

        self.fatTissueSpeciesJ = [["food", 1], ["body", 3], ["population", 4],
                                  ["traits", ["warning-call", "fat-tissue"]],
                                  ["fat-food", 1]]
        self.fatTissueSpecies = Species(1, 3, 4,
                                        ["warning-call", "fat-tissue"], 1)

        self.fatTraitNoFoodJ = [["food", 1], ["body", 3], ["population", 4],
                                ["traits", ["warning-call", "fat-tissue"]]]
        self.fatTraitNoFood = Species(1, 3, 4, ["warning-call", "fat-tissue"],
                                      0)

        self.onePlayerJ = [["id", 1],
                           ["species", [self.species1J, self.species2J]],
                           ["bag", 0]]
        self.onePlayer = PlayerState(1, 0, [self.species1, self.species2], [])

        self.twoPlayerJ = [["id", 2],
                           [
                               "species",
                               [self.avgSpeciesJ, self.fatTissueSpeciesJ]
                           ], ["bag", 0]]
        self.twoPlayer = PlayerState(2, 0,
                                     [self.avgSpecies, self.fatTissueSpecies],
                                     [])

        self.threePlayerJ = [["id", 3], ["species", [self.fatTraitNoFoodJ]],
                             ["bag", 0]]
        self.threePlayer = PlayerState(3, 0, [self.fatTraitNoFood], [])
Beispiel #13
0
    def testStep1(self):
        dealEarlyOn = Dealer([
            PlayerState(1, 0, [], []),
            PlayerState(2, 0, [], []),
            PlayerState(2, 0, [], [])
        ], 0)
        dealEarlyOn.step1()
        for player in dealEarlyOn.players:
            self.assertEqual(len(player.species), 1)
            self.assertEqual(len(player.hand), 4)
        del dealEarlyOn

        dealLaterOn = Dealer([
            PlayerState(1, 0, [self.vegHorns, self.vegCoop], []),
            PlayerState(2, 0, [self.carnForage], []),
            PlayerState(2, 0, [], [])
        ], 0)
        dealLaterOn.step1()
        self.assertEqual(len(dealLaterOn.players[0].species), 2)
        self.assertEqual(len(dealLaterOn.players[0].hand), 5)
        self.assertEqual(len(dealLaterOn.players[1].species), 1)
        self.assertEqual(len(dealLaterOn.players[1].hand), 4)
        self.assertEqual(len(dealLaterOn.players[2].species), 1)
        self.assertEqual(len(dealLaterOn.players[2].hand), 4)
        del dealLaterOn
Beispiel #14
0
    def new(players):
        """
        Create a new Dealer with the given list of player references
        :param players: List of external Player references
        :return: Dealer object with the starting default values for each playerState, wateringHole, hand
        """
        playerStates = []

        for i in range(len(players)):
            playerStates.append(PlayerState.new(i + 1, players[i]))

        hand = Dealer.create_hand()
        return Dealer(playerStates, 0, hand)
Beispiel #15
0
	def testGetCarnivoreAttack(self):
		carn, play, prey = SillyPlayer.getCarnivoreAttack(self.ourIndexedSpecies, otherPlayers=[self.bPlayerState, self.cPlayerState])
		self.assertEqual(carn, 0)
		self.assertEqual(play, 1)
		self.assertEqual(prey, 0)
		carn, play, prey = SillyPlayer.getCarnivoreAttack(self.ourIndexedSpecies, otherPlayers=[self.bPlayerState])
		self.assertEqual(carn, 0)
		self.assertEqual(play, 0)
		self.assertEqual(prey, 0)
		carn, play, prey = SillyPlayer.getCarnivoreAttack(self.ourIndexedSpecies, 
			otherPlayers=[PlayerState(4, 0, [Species(1, 1, 1, [TraitCard("warning-call")], 0), Species(1, 1, 1, [TraitCard("warning-call")], 0)], [])])
		self.assertFalse(carn)
		self.assertFalse(play)
		self.assertFalse(prey)
Beispiel #16
0
 def testReplaceTraits(self):
     playerForReplacingTraits = PlayerState(1, 0, [
         Species(0, 0, 1, [TraitCard("foraging"),
                           TraitCard("herding")], 0)
     ], [TraitCard("carnivore"), TraitCard("horns")])
     dealerForReplacingTraits = Dealer([playerForReplacingTraits], 0, [])
     dealerForReplacingTraits.replaceTraits(0, self.actRT)
     # the card is still in hand -- it will be removed in the step4 method, not here
     self.assertEqual(dealerForReplacingTraits.players[0].hand,
                      [TraitCard("carnivore"),
                       TraitCard("horns")])
     self.assertEqual(
         dealerForReplacingTraits.players[0].species[0].traits,
         [TraitCard("foraging"), TraitCard("horns")])
Beispiel #17
0
 def testGetCarnivoreAttack(self):
     carn, play, prey = Player.getCarnivoreAttack(
         self.ourIndexedSpecies,
         otherPlayers=[self.bPlayerState, self.cPlayerState])
     self.assertEqual(carn, 0)
     self.assertEqual(play, 1)
     self.assertEqual(prey, 0)
     carn, play, prey = Player.getCarnivoreAttack(
         self.ourIndexedSpecies, otherPlayers=[self.bPlayerState])
     self.assertEqual(carn, 0)
     self.assertEqual(play, 0)
     self.assertEqual(prey, 0)
     carn, play, prey = Player.getCarnivoreAttack(
         self.ourIndexedSpecies,
         otherPlayers=[
             PlayerState(4, 0, [
                 Species(1, 1, 1, ["warning-call"], 0),
                 Species(1, 1, 1, ["warning-call"], 0)
             ], [])
         ])
     self.assertEqual(carn, -1)
     self.assertEqual(play, -1)
     self.assertEqual(prey, -1)
Beispiel #18
0
    def create_dealer_from_configuration(json_configuration):
        """
        Takes in a configuration from stdin as a JSON object
        :param json_configuration: the JSON configuration
        :return: Dealer - the dealer created from the configuration
        """
        try:
            list_of_player_states = []
            for player_state in json_configuration[0]:
                ps = PlayerState.convertPlayerState(player_state)
                ps.player_reference = Player(ps.id)
                list_of_player_states.append(ps)

            wh = json_configuration[1]

            if isinstance(wh, int) and not isinstance(wh, bool) and wh >= 0:
                watering_hole = json_configuration[1]
                hand = Dealer.get_hand(json_configuration[2])

                return Dealer(list_of_player_states, watering_hole, hand)
            else:
                raise Exception("Invalid JSON Watering Hole")
        except:
            raise Exception("Ill formed json configuration")
Beispiel #19
0
	def setUp(self):
		self.vegHorns = Species(1, 2, 3, ["horns"], 0)
		self.vegCoop = Species(1, 2, 3, ["cooperation"], 0)
		self.fat = Species(4, 3, 4, ["fat-tissue"], 3)
		self.fatScav = Species(2, 3, 4, ["fat-tissue", "scavenger"], 1)
		self.fatFor = Species(4, 3, 4, ["fat-tissue", "foraging"], 1)
		self.carnCoop = Species(3, 4, 5, ["carnivore", "cooperation"], 0)
		self.carnForage = Species(3, 4, 5, ["carnivore", "foraging"], 0)
		self.carnForage1 = Species(3, 4, 5, ["carnivore", "foraging"], 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.dealer = Dealer([self.p1, self.p2, self.p3], 3, [])
		self.p2dealer = Dealer([self.p6, self.p5], 3, [])
		self.p3dealer = Dealer([self.p8], 3, [])


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

		self.x41 = Species(0, 5, 2, ["carnivore", "cooperation"], 0)
		self.x42 = Species(0, 5, 2, ["carnivore"], 0)
		self.x4p1 = PlayerState(1, 0, [self.x41, self.x42], [])

		self.x43 = Species(0, 2, 2, ["scavenger", "foraging", "cooperation"], 0)
		self.x44 = Species(0, 5, 1, ["carnivore", "cooperation"], 0)
		self.x4p2 = PlayerState(2, 0, [self.x43, self.x44], [])

		self.x45 = Species(0, 4, 1, [], 0)
		self.x4p3 = PlayerState(3, 0, [self.x45], [])

		self.x4d = Dealer([self.x4p1, self.x4p2, self.x4p3], 10, [])

		self.x61 = Species(0, 5, 3, ["carnivore", "cooperation", "foraging"], 0)
		self.x62 = Species(0, 5, 2, ["foraging", "carnivore"], 0)
		self.x6p1 = PlayerState(1, 0, [self.x61, self.x62], [])

		self.x63 = Species(0, 2, 1, ["scavenger", "foraging", "cooperation"], 0)
		self.x64 = Species(0, 5, 2, ["carnivore", "cooperation"], 0)
		self.x6p2 = PlayerState(2, 0, [self.x63, self.x64], [])

		self.x65 = Species(0, 4, 2, ["scavenger"], 0)
		self.x6p3 = PlayerState(3, 0, [self.x65], [])

		self.x6deal = Dealer([self.x6p1, self.x6p2, self.x6p3], 8, [])
Beispiel #20
0
    def testFeed1(self):
        self.assertEqual(self.vegCoop.food, 1)
        self.dealer.feed1()
        self.assertEqual(self.vegCoop.food, 2)
        self.assertEqual(self.dealer.wateringHole, 2)

        self.assertEqual(self.carnCoop.population, 5)
        self.assertEqual(self.carnCoop.food, 3)
        self.assertEqual(self.vegHorns.population, 3)
        self.p2dealer.feed1()
        self.assertEqual(self.carnCoop.population, 4)
        self.assertEqual(self.carnCoop.food, 4)
        self.assertEqual(self.vegHorns.population, 2)

        self.assertEqual(self.fatFor.fatFood, 1)
        self.assertEqual(self.fatFor.food, 4)
        self.p3dealer.feed1()
        self.assertEqual(self.fatFor.fatFood, 3)
        self.assertEqual(self.fatFor.food, 4)
        self.assertEqual(self.p3dealer.wateringHole, 1)

        # a user without any species should not be deleted from players
        # but should be deleted from currentlyFeeding
        # 0067-2657-1
        pNoSpecies1 = PlayerState(1, 0, [], [])
        pNoSpecies2 = PlayerState(2, 0, [], [])
        pNoSpecies3 = PlayerState(3, 0, [], [])
        dNoSpecies = Dealer([pNoSpecies1, pNoSpecies2, pNoSpecies3], 5, [])
        self.assertEqual(len(dNoSpecies.players), 3)
        self.assertEqual(len(dNoSpecies.currentlyFeeding), 3)
        dNoSpecies.feed1()
        self.assertEqual(len(dNoSpecies.players), 3)
        self.assertEqual(len(dNoSpecies.currentlyFeeding), 2)
        self.assertFalse(pNoSpecies1 in dNoSpecies.currentlyFeeding)

        # a user who can no longer attack/feed should not be deleted from players
        # but should be deleted from currentlyFeeding
        # 0067-2657-7
        pNoAtkSpecies1 = PlayerState(1, 0, [
            Species(0, 1, 1, [TraitCard("carnivore")], 0),
            Species(1, 1, 1, [TraitCard("horns"),
                              TraitCard("cooperation")], 0),
            Species(1, 1, 1, [], 0)
        ], [])
        pNoAtkSpecies2 = PlayerState(
            2, 0, [Species(0, 1, 1, [TraitCard("hard-shell")], 0)], [])
        pNoAtkSpecies3 = PlayerState(3, 0, [
            Species(0, 1, 1, [
                TraitCard("cooperation"),
                TraitCard("scavenger"),
                TraitCard("climbing")
            ], 0),
            Species(0, 1, 2, [
                TraitCard("cooperation"),
                TraitCard("scavenger"),
                TraitCard("climbing")
            ], 0),
            Species(0, 1, 4, [TraitCard("foraging"),
                              TraitCard("hard-shell")], 0)
        ], [])
        dNoAtkSpecies = Dealer(
            [pNoAtkSpecies1, pNoAtkSpecies2, pNoAtkSpecies3], 5, [])
        self.assertEqual(len(dNoAtkSpecies.players), 3)
        self.assertEqual(len(dNoAtkSpecies.currentlyFeeding), 3)
        dNoAtkSpecies.feed1()
        self.assertEqual(len(dNoAtkSpecies.players), 3)
        self.assertEqual(len(dNoAtkSpecies.currentlyFeeding), 2)
        self.assertFalse(pNoAtkSpecies1 in dNoAtkSpecies.currentlyFeeding)

        # successfully extincting someone else's species should give two cards to loser
        # 2598-3830-8
        pExtinction1 = PlayerState(
            3, 2, [Species(3, 4, 4, [TraitCard("carnivore")], 0)],
            [TraitCard("burrowing", -3)])
        pExtinction2 = PlayerState(2, 42, [
            Species(0, 3, 4, [TraitCard("climbing")], 0),
            Species(4, 2, 4, [TraitCard("climbing")], 0),
            Species(4, 1, 4, [TraitCard("climbing")], 0)
        ], [TraitCard("climbing", 3)])
        pExtinction3 = PlayerState(4, 100, [Species(0, 7, 1, [], 0)], [])
        dExtinction = Dealer([pExtinction1, pExtinction2, pExtinction3], 9, [
            TraitCard("burrowing", 3),
            TraitCard("horns", 3),
            TraitCard("climbing", 1)
        ])

        self.assertEqual(len(dExtinction.deck), 3)
        dExtinction.feed1()
        self.assertEqual(len(dExtinction.deck), 1)
        self.assertEqual(pExtinction3.hand,
                         [TraitCard("burrowing", 3),
                          TraitCard("horns", 3)])
        self.assertEqual(len(pExtinction3.species), 0)
        self.assertEqual(pExtinction1.species[0].food, 4)
        self.assertEqual(dExtinction.wateringHole, 8)
Beispiel #21
0
    def testPrelimAutoFeedings(self):
        self.dealerForAutoFeeds = Dealer([
            PlayerState(1, 0, [
                Species(0, 2, 3,
                        [TraitCard("fertile"),
                         TraitCard("fat-tissue")], 2)
            ], []),
            PlayerState(1, 0, [Species(0, 2, 3, [TraitCard("fat-tissue")], 0)],
                        []),
            PlayerState(3, 0, [
                Species(0, 2, 3,
                        [TraitCard("fertile"),
                         TraitCard("long-neck")], 0)
            ], [])
        ], 10, [])
        self.assertEqual(len(self.dealerForAutoFeeds.discard), 0)
        self.assertEqual(self.dealerForAutoFeeds.wateringHole, 10)
        self.assertEqual(
            self.dealerForAutoFeeds.players[0].species[0].population, 3)
        self.assertEqual(self.dealerForAutoFeeds.players[0].species[0].fatFood,
                         2)
        self.assertEqual(self.dealerForAutoFeeds.players[0].species[0].food, 0)
        self.assertEqual(self.dealerForAutoFeeds.players[0].species[0].body, 2)

        self.assertEqual(
            self.dealerForAutoFeeds.players[1].species[0].population, 3)
        self.assertEqual(self.dealerForAutoFeeds.players[1].species[0].fatFood,
                         0)
        self.assertEqual(self.dealerForAutoFeeds.players[1].species[0].food, 0)
        self.assertEqual(self.dealerForAutoFeeds.players[1].species[0].body, 2)

        self.assertEqual(
            self.dealerForAutoFeeds.players[2].species[0].population, 3)
        self.assertEqual(self.dealerForAutoFeeds.players[2].species[0].fatFood,
                         0)
        self.assertEqual(self.dealerForAutoFeeds.players[2].species[0].food, 0)
        self.assertEqual(self.dealerForAutoFeeds.players[2].species[0].body, 2)

        self.dealerForAutoFeeds.prelimAutoFeedings()

        self.assertEqual(len(self.dealerForAutoFeeds.discard), 0)
        self.assertEqual(self.dealerForAutoFeeds.wateringHole, 9)
        self.assertEqual(
            self.dealerForAutoFeeds.players[0].species[0].population, 4)
        self.assertEqual(self.dealerForAutoFeeds.players[0].species[0].fatFood,
                         0)
        self.assertEqual(self.dealerForAutoFeeds.players[0].species[0].food, 2)
        self.assertEqual(self.dealerForAutoFeeds.players[0].species[0].body, 2)

        self.assertEqual(
            self.dealerForAutoFeeds.players[1].species[0].population, 3)
        self.assertEqual(self.dealerForAutoFeeds.players[1].species[0].fatFood,
                         0)
        self.assertEqual(self.dealerForAutoFeeds.players[1].species[0].food, 0)
        self.assertEqual(self.dealerForAutoFeeds.players[1].species[0].body, 2)

        self.assertEqual(
            self.dealerForAutoFeeds.players[2].species[0].population, 4)
        self.assertEqual(self.dealerForAutoFeeds.players[2].species[0].fatFood,
                         0)
        self.assertEqual(self.dealerForAutoFeeds.players[2].species[0].food, 1)
        self.assertEqual(self.dealerForAutoFeeds.players[2].species[0].body, 2)
Beispiel #22
0
	def start(self, curState, wateringHole):
		self.state = curState
		gameState = [wateringHole]
		gameState += PlayerState.stateToJson(self.state)
		self.sock.sendall(json.dumps(gameState))
Beispiel #23
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, ["horns"], 0)
        self.vegCoop = Species(1, 2, 3, ["cooperation"], 0)
        self.fat = Species(4, 3, 4, ["fat-tissue"], 3)
        self.fatScav = Species(2, 3, 4, ["fat-tissue", "scavenger"], 1)
        self.fatFor = Species(4, 3, 4, ["fat-tissue", "foraging"], 1)
        self.carnCoop = Species(3, 4, 5, ["carnivore", "cooperation"], 0)
        self.carnForage = Species(3, 4, 5, ["carnivore", "foraging"], 0)
        self.carnForage1 = Species(3, 4, 5, ["carnivore", "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, ["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, ["carnivore", "cooperation"], 0),
            Species(1, 3, 4, ["foraging", "carnivore", "scavenger"], 0)
        ], [])
        self.pCFS2 = PlayerState(2, 4, [Species(2, 3, 3, ["burrowing"], 0)],
                                 [])
        self.pCFS3 = PlayerState(3, 5, [], [])
        self.dCFS = Dealer([self.pCFS1, self.pCFS2, self.pCFS3], 10, [])
Beispiel #24
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, [])