Exemple #1
0
    def play_roll(self, camel, roll):
        """
        1. Moves the camel
        2. Give points if camel landed on a block or skip tile
        3. Gives a point to the roller
        4. Updates needs roll
        5. Checks for end of game
        6. Checks for end of round

        Parameters
        ----------
        camel : str
            Camel that is rolled
        roll : int
            The number that is rolled
        """
        give_points = gameplay.move(self.camel_dict, self.tiles_dict, camel, roll)
        if give_points:
            tile_owner = self.tiles_dict[give_points]["player"]
            self.player_dict[tile_owner]["coins"] += 1
        self.player_dict[self.state]["coins"] += 1
        self.camel_dict[camel]["need_roll"] = False
        if self.camel_dict[camel]["space"] > 16:
            return self.end_game()
        if any([val["need_roll"] for val in self.camel_dict.values()]) is False:
            return self.end_round()
Exemple #2
0
 def _gen_camel_start(self):
     """Generates the start for the camel
     """
     need_place = [
         key
         for key in self.camel_dict.keys()
         if self.camel_dict[key]["space"] is None
     ]
     while need_place:
         camel = random.choice(need_place)
         roll = random.randint(1, 3)
         self.camel_dict[camel]["space"] = 0
         self.camel_dict[camel]["height"] = 0
         gameplay.move(self.camel_dict, self.tiles_dict, camel, roll)
         need_place = [
             key
             for key in self.camel_dict.keys()
             if self.camel_dict[key]["space"] is None
         ]
Exemple #3
0
def test_move_with_block(camel_dict_copy):
    assert gameplay.move(camel_dict_copy, tiles_dict, "red", 4) == 5
    assert camel_dict_copy["white"]["space"] == 4
    assert camel_dict_copy["yellow"]["space"] == 4
    assert camel_dict_copy["blue"]["space"] == 4
    assert camel_dict_copy["red"]["space"] == 4
    assert camel_dict_copy["white"]["height"] == 4
    assert camel_dict_copy["yellow"]["height"] == 3
    assert camel_dict_copy["blue"]["height"] == 2
    assert camel_dict_copy["red"]["height"] == 1
Exemple #4
0
 def _turn(self, sim_dict, tiles):
     """
     Simulates a single turn
     """
     need_roll = [key for key in sim_dict.keys() if sim_dict[key]["need_roll"]]
     tile_points = dict()
     while need_roll:
         camel = random.choice(need_roll)
         roll = random.randint(1, 3)
         logger.info("The {0} camel rolled {1}".format(camel, roll))
         give_points = gameplay.move(sim_dict, tiles, camel, roll)
         if give_points:
             tile_owner = tiles[give_points]["player"]
             util.add_value_dict(tile_points, tile_owner, 1)
         sim_dict[camel]["need_roll"] = False
         need_roll.remove(camel)
         if sim_dict[camel]["space"] > 16:
             return self._winner(sim_dict), tile_points
     return None, tile_points
Exemple #5
0
def test_move_with_skip(camel_dict_copy):
    assert gameplay.move(camel_dict_copy, tiles_dict, "blue", 1) == 2
    assert camel_dict_copy["blue"]["space"] == 3
    assert camel_dict_copy["blue"]["height"] == 2