Example #1
0
 def test_status(self):
     """ Testing status functions
     status.get_round_from_db
     """
     clear_tables(self.db)
     assert(status.get_round_from_db(GAME_ID1, self.db) == -1)
     status.initialize_status(GAME_ID1, self.db, 3)
     assert(status.get_round_from_db(GAME_ID1, self.db) == 0)
     status.set_round_in_db(5, GAME_ID1, self.db)
     assert(status.get_round_from_db(GAME_ID1, self.db) == 5)
     status.initialize_status(GAME_ID1, self.db, 3)
     assert(status.get_round_from_db(GAME_ID1, self.db) == 0)
     table_str = status.create_player_rel_table(5)
     assert (len(table_str) == 74)
     table = status.get_table_from_rel_table(table_str)
     assert (len(table) == 5)
     assert (len(table[0]) == 5)
     tmp_table_str = status.get_rel_table_from_table(table)
     assert (tmp_table_str == table_str)
     tmp_table = status.get_table_from_rel_table(table_str)
     assert (tmp_table == table)
     new_table = status.update_player_rel_table(table_str, 1,2,5)
     status.set_player_rel_table_in_db(GAME_ID1, new_table, self.db)
     new_status = status.get_status_from_db(GAME_ID1, self.db)
     assert(status.get_table_from_rel_table(new_status.player_rel_table)[1][2] == '5')
Example #2
0
def initialize_game(game_id, db):
    """ input: game_id String, db Database
    """
    # initialize players
    players = player.get_players_from_db(game_id, db)
    random.seed(2)
    random.shuffle(players)
    for i, p in enumerate(players):
        p.id_num = i
        p.p_left_name = _get_left_item(players,i).name
        p.p_right_name = _get_right_item(players,i).name
        player.update_player_by_name(p, db)
    # initialize dice
    dice.insert_dice_into_db(dice.initialize_dice(len(players), game_id), db)
    status.set_round_in_db(0, game_id, db)