Example #1
0
    def start_game(self):

        if len(self.players) < self.num_players:
            logging.error(
                "trying to start game %s with only %s players, but expecting %s players"
                % (self.id, len(self.players), self.num_players))
            raise FatalPlyusError("Not all players have joined yet")
        if self.stage != Stage.PRE_GAME:
            raise FatalPlyusError(
                "Can't start game except from stage PRE_GAME  (in stage %s now)"
                % (self.stage, ))

        rand_gen = self.get_random_gen()
        rand_gen.shuffle(self.players)
        rand_gen.shuffle(self.building_card_deck.cards)

        for i, p in enumerate(self.players):
            p.set_position(i)
            #TODO:  replace magic number with actual number of cards in starting hand.
            p.buildings_in_hand.extend(
                util.draw_n(self.building_card_deck.cards, 4))

        self.round = Round(self)
        self.player_with_crown_token = 0  #this player gets to go first when picking a role
        self.stage = Stage.PLAYING
        self.start_new_round()
Example #2
0
    def start_new_round(self):
        logging.info("starting new round")
        self.round = Round(self)
        self.cur_player_index = self.player_with_crown_token
        self.phase = Phase.PICK_ROLES
        self.step = Step.PICK_ROLE
        self.round_num += 1

        for p in self.players:
            p.revealed_roles = []
Example #3
0
    def test_create_round(self):
        players = [fake_player("Peter"), fake_player("Manan")]
        game = GameState(42,
                         players[0],
                         2,
                         deck_template="decks/deck_test_30.csv")
        game.add_player(players[1])
        self.assertIsNotNone(
            game.to_dict_for_public(),
            "to_dict shouldn't crash even if called before game is started and round is created"
        )
        game.start_game()
        r = Round(game)

        self.assertEqual(len(r.face_up_roles), 0)
        self.assertEqual(len(r.face_down_roles), 1)
        self.assertEqual(len(r.role_draw_pile), 7)