def throw_away_card(self, game_id: str, player_name: str, card_idx: int): # check if game exists + status if not self.__does_game_exist(game_id): # todo exception type raise Exception("requested game doesn't exist") if self.__get_game_status(game_id) == "created": # todo exception type raise Exception( "game has not started - waiting for the second player") # assign it to variable curr_game = self.__games[game_id] player = curr_game.get_player_by_name(player_name) card_name = player.hand[card_idx] if curr_game.game_status != player_name: # todo exception type raise Exception("it is not " + player_name + "\'s turn") # save state to database game_status, player_1_status, player_2_status = curr_game.get_state() state = State(game_id, game_status, player_1_status, player_2_status, 1, card_name) self.add_turn(state) # throw away card curr_game.last_played_card = [player.hand[card_idx], 'thrown_away'] player.hand[card_idx] = generate_card() curr_game.change_turn()
def setUp(self): self.db = Database(db_num=15) self.r = self.db.redis self.r.flushall() self.state = State(self.db) self.state.modify_balance(PUB_KEY_X_FOR_KNOWN_SE, 20)
def __init__(self, root: SimpleBlock, db: Database, p2p: Network): self._db = db self._p2p = p2p self.root = root self._state = State(self._db) self._orphans = Orphanage(self._db) self.current_node_hashes = RedisSet(db, 'all_nodes') self._block_index = RedisHashMap(db, 'block_index', int, SimpleBlock) self._block_heights = RedisHashMap(db, 'block_heights', int, int) self._heights = RedisHashMap(db, 'heights', int) self._initialized = RedisFlag(db, 'initialized') self.head = self._get_top_block() self._seeker = Seeker( self, self._p2p ) # format: (total_work, block_hash) - get early blocks first self.currently_seeking = set() # todo: temp till primary chain is done in redis so queries are quick self._primary_chain = PrimaryChain(self._db, 'primary_chain') if not self._initialized.is_true: self._first_initialize() self._initialized.set_true()
def test_api(self): scope = ['https://spreadsheets.google.com/feeds'] credentials = ServiceAccountCredentials.from_json_keyfile_name( 'client-secret.json', scope) sh = gspread.authorize(credentials).open_by_key( '1SjJG2RzITf8qAmYDU9RFnWVaMP9912y8KfbuJe8th-c') work_sheets = sh.worksheets() assert len(work_sheets) == 14 country_id = str(uuid.uuid4().hex) for ws_count, worksheet in enumerate(sh.worksheets()): # TODO write State By Country Here state_name = MockConfig().getStateName(worksheet.title) state_id = str(uuid.uuid4().hex) state = State(id=state_id, object_id=state_id, country_id=str(country_id), name_mm_uni=str(state_name), name_mm_zawgyi=Rabbit.uni2zg(state_name)) cal_day_list = worksheet.col_values(1) hij_day_list = worksheet.col_values(2) sehri_time_list = worksheet.col_values(3) iftari_time_list = worksheet.col_values(4) for i, (cal_day, hij_day, seh_time, iftar_time) in enumerate( zip(cal_day_list, hij_day_list, sehri_time_list, iftari_time_list)): if i is not 0: article_id = str(uuid.uuid4().hex) article = Day( id=article_id, object_id=article_id, country_id=str(country_id), state_id=str(state.object_id), day=i, day_mm=str(MockConfig().get_mm_num(i)), sehri_time=str(seh_time) + " am", sehri_time_desc="Sehri", sehri_time_desc_mm_zawgyi=Rabbit.uni2zg("ဝါချည်ချိန်"), sehri_time_desc_mm_uni="ဝါချည်ချိန်", iftari_time=str(iftar_time) + " pm", dua_mm_uni=MockConfig().daily_dua(i)["dua_mm"], dua_mm_zawgyi=Rabbit.uni2zg( MockConfig().daily_dua(i)["dua_mm"]), dua_ar=MockConfig().daily_dua(i)["dua_ar"], dua_en=MockConfig().daily_dua(i)["dua_en"], iftari_time_desc="Iftari", iftari_time_desc_mm_zawgyi=Rabbit.uni2zg("ဝါဖြေချိန်"), iftari_time_desc_mm_uni="ဝါဖြေချိန်")
def play_card(self, game_id: str, player_name: str, card_idx: int): # check if game exists + status if not self.__does_game_exist(game_id): # todo exception type raise Exception("requested game doesn't exist") if self.__get_game_status(game_id) == "created": # todo exception type raise Exception( "game has not started - waiting for the second player") # assign it to variable curr_game = self.__games[game_id] player = curr_game.get_player_by_name(player_name) card_name = player.hand[card_idx] card = CARD_DEFINITIONS[card_name] # check if its his turn if curr_game.game_status != player_name: # todo exception type raise Exception("it is not " + player_name + "\'s turn") # check if player has material to play the card if not curr_game.can_player_play_card(player_name, card): # todo exception type raise Exception("player cannot afford such card") # save state to database game_status, player_1_status, player_2_status = curr_game.get_state() state = State(game_id, game_status, player_1_status, player_2_status, 0, card_name) self.add_turn(state) # play card curr_game.last_played_card = [player.hand[card_idx], 'played'] if card_name == "zlodej": curr_game.play_zlodej() else: curr_game.play_card(card) curr_game.change_turn() player.hand[card_idx] = generate_card() # checking end of game over = curr_game.is_over() if over: return over else: return False
#Вывод данных data = Session.query(Sight) for row in data: print("\"{}\" год: {} Область: {} Страна: {}".format( row.name, row.year, row.state.name, row.state.country.name)) if __name__ == '__main__': print("Вывод достопримечательностей\n") printSights() #Добавление данных Russia = Session.query(Country).filter(Country.name == "Россия").one() Volgograd = State("Волгоградсткая Область", Russia) Session.add(Volgograd) Session.commit() newSigt = Sight( "Родина-Мать", 1967, "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda velit quis, ex iusto, nam molestias dolore quia asperiores alias obcaecati maiores consequatur qui porro natus totam commodi earum, odio itaque.", Volgograd) Session.add(newSigt) Session.commit() print() print("Добавлены данные\nДостопримечательность: Родина-Мать") printSights() #Каскадное удаление данных USA = Session.query(Country).filter(Country.name == "США").one() Session.delete(USA)