def test_cyrillic(self): g = Game('Треугольник') r = GameRelease(game=g) self.assertEqual(["Треугольник"], r.aliases) g = Game('3угольник') r = GameRelease(game=g) self.assertEqual(["3угольник"], r.aliases) g = Game('Минидрайвер дисковых операций') r = GameRelease(game=g) aliases = r.getAllAliases() self.assertEqual(aliases, ['Минидрайвер дисковых операций'])
def train(self): self.student.graph.updateGraph() id_node, number, instruction, question, correct, wrong = self.student.graph.selectExercise( ) game = Game(self, instruction, question, correct, wrong, number, id_node) game.askExercises()
def load_from_database(): db_rooms = [] try: with db_session: db_rooms += db.DB_Room.select() except Exception as e: print(e) rooms = [] for room in db_rooms: new_room = Room(room.name, room.max_players, room.owner) new_room.users = room.users["users"] new_room.emails = room.emails["emails"] if room.status == RoomStatus.PREGAME.value: new_room.set_status(RoomStatus.PREGAME) elif room.status == RoomStatus.IN_GAME.value: new_room.set_status(RoomStatus.IN_GAME) else: new_room.set_status(RoomStatus.FINISHED) if (new_room.get_status() != RoomStatus.PREGAME and room.game is not {}): new_room.game = Game(new_room.get_user_list()) new_room.game.build_from_json(room.game) rooms.append(new_room) return rooms
def gameFromRow(self, row): game = Game(row['name'], int(row['wos_id'])) game.setPublisher(row['publisher']) if 'author' in row.keys(): game.setAuthor(row['author']) game.setYear(row['year']) game.setGenre(row['genre']) game.setNumberOfPlayers(row['number_of_players']) game.setMachineType(row['machine_type']) game.setLanguage(row['language']) game.setAvailability(row['availability']) game.x_rated = row['x_rated'] game.addRelease(self.releaseFromRow(row, game)) if 'multiplayer_type' in row.keys(): game.setMultiplayerType(row['multiplayer_type']) if 'tipshop_page' in row.keys(): game.tipshop_page = row['tipshop_page'] game.tipshop_multiface_pokes_section = row[ 'tipshop_multiface_pokes_section'] if game.tipshop_page or row['pok_file_contents']: game.importPokFile(text=str(row['pok_file_contents'])) if row['md5']: file = self.fileFromRow(row) game.addFile(file) if file.part > game.parts: game.parts = file.part return game
def choose_town_job(self): print("=========================================================================") print("Which job would you like to perform?\n\t<1> Help the guards clean up town\n\t<2> Gamble in the casino" "\n\t<3> Beg for money \n\t<h> Help \n\t<t> Go back to town \n\t<q> Quit ") job_choice = input("Input: ") if job_choice == "1": pass elif job_choice == "2": Job.gamble(self) elif job_choice == "3": Job.beg_for_money(self) elif job_choice.lower() == "h": print("=========================================================================") print("\t-Helping the guards involves doing smaller jobs for money.\n\t-Gambling in the casino" " takes a random luck roll and rewards you \n\twell or hurts you\n\t-Begging for money takes a " "random charisma roll and can cause \n\tsome odd effects...") print("=========================================================================") time.sleep(3) Job.choose_town_job(self) elif job_choice.lower() == "t": game = Game() game.town_actions() elif job_choice.lower() == "q": exit() else: Job.choose_town_job(self)
def test_set_score(self): player_one = Player(PLAYER_NAME_ONE) player_two = Player(PLAYER_NAME_TWO) game = Game(player_one, player_two, False) game.score = PLAYER_NAME_ONE self.assertIsInstance(game.score, str)
def test_desc_in_brackets_and_multiline_cheat(self): game = Game('Myth', 3354) self.ts.scrapePokes(game) self.assertEqual(game.cheats[0].description, 'Credits') self.assertEqual(game.cheats[1].description, 'Number of lives') self.assertEqual(game.cheats[2].description, 'Level 1') self.assertEqual(len(game.cheats), 6)
def test_multipoke_cheats_scraping(self): game = Game(name="Apulija-13", zxdb_id=27997) self.ts.scrapePokes(game) pp.pprint(game.cheats) self.assertEquals(len(game.cheats), 7) multipoke_cheat = game.cheats[-1] self.assertEquals(len(multipoke_cheat.pokes), 9)
def test_desc_in_brackets_and_broken_brackets(self): game = Game('Flynn' 's Adventure In Bombland', 26114) self.ts.scrapePokes(game) self.assertEqual(game.cheats[0].description, 'Infinite lives') self.assertEqual(game.cheats[1].description, 'Infinite time') #Bug on website: need manual fixing self.assertEqual(game.cheats[2].description, '(number of lives')
def __init__(self, player_one: Player, player_two: Player): self.player_one = player_one self.player_two = player_two self.is_tie_breaker = self.tie_breaker() self.game = Game(self.player_one, self.player_two, self.is_tie_breaker) self.score = '0 - 0, 0 - 0' self.winner = None
def scrapeGameData(self, game=Game()): url = game.getWosUrl() selector = self.loadUrl(url) tables = selector.xpath('//table').extract_all() desc_table = Selector(text=tables[5]) desc_rows = desc_table.xpath('//tr').extract_all() for row in desc_rows: row_text = self.getTextFromDescriptionRow(row) if not row_text: continue caption = row_text[0] value = row_text[1] if caption == 'Full title': if value.startswith('[MOD]'): value = row_text[2] game.setTitle(value) elif caption == 'Year of release': game.setYear(value) elif caption == 'Publisher': game.setPublisher(value) elif caption == 'Machine type': game.setMachineType(value) elif caption == 'Number of players': game.setNumberOfPlayers(value) elif caption == 'Type': game.setGenre(value) elif caption == 'Availability': game.setAvailability(value) has_tipshop_pokes = selector.xpath( '//img[@title="Search The Tipshop"]/@title').extract_first() if has_tipshop_pokes == 'Search The Tipshop': game.has_tipshop_pokes = True game_files, additional_materials = self.getFilesLists(tables[4:]) self.scrapeGameFiles(game, game_files) self.scrapeAdditionalMaterials(game, additional_materials)
def test_complex_pokes_scraping(self): game = Game(name="Ghost Hunters", zxdb_id=9350) self.ts.scrapePokes(game) pp.pprint(game.cheats) self.assertEquals(game.cheats[2].description, 'You don\'t need blood goblet (Platform "A")') self.assertEquals(game.cheats[2].pokes[0].address, 41530) self.assertEquals(game.cheats[2].pokes[0].value, 130)
def test_medium_pokes_scraping(self): game = Game(name="Gimme Bright", zxdb_id=25640) self.ts.scrapePokes(game) pp.pprint(game.cheats) self.assertEquals(game.cheats[0].description, "Lives") self.assertEquals(game.cheats[1].description, "Time") self.assertEquals(game.cheats[2].description, "Lives") self.assertEquals(game.cheats[3].description, "Time")
def test_franknstein(self): game = Game(zxdb_id=3316) self.ts.scrapePokes(game) print(game.cheats) self.assertEqual(game.cheats[0].description, 'Infinite lives (One player mode)') self.assertTrue(self.game_has_cheat_named(game, 'immunity')) self.assertTrue(self.game_has_cheat_named(game, 'silent game'))
def single_game(self, blue_starts: bool = True): pygame.init() pygame.display.set_caption("Hex") game = Game(board_size=self.BOARD_SIZE, itermax=self.ITERMAX, mode=self.MODE, blue_starts=blue_starts) game.get_game_info([self.BOARD_SIZE, self.ITERMAX, self.MODE, self.GAME_COUNT]) while not game.winner: game.play()
def test_get_score(self): player_one = Player(PLAYER_NAME_ONE) player_two = Player(PLAYER_NAME_TWO) game = Game(player_one, player_two, False) game.score = PLAYER_NAME_ONE self.assertEqual(game.score, '15 - 0')
def test_cowboy(self): #THIS SHOULD BE FIXED MANUALLY game = Game(name='Cowboy', zxdb_id=15419, db=self.db) game = self.db.getGameByWosID(game.zxdb_id) print(game.cheats) self.assertEqual(len(game.cheats), 2) self.ts.scrapePokes(game) self.assertEqual(len(game.cheats), 3)
def test_score_tie_breaker(self): player_one = Player(PLAYER_NAME_ONE) player_two = Player(PLAYER_NAME_TWO) game = Game(player_one, player_two, True) game.score = PLAYER_NAME_ONE self.assertEqual(game.score, '1 - 0')
def main(): pygame.init() game = Game() game.main_loop() pygame.quit() print('Goodbye.')
def test_variable_poke(self): game = Game(name="Pinball", zxdb_id=3718) self.ts.scrapePokes(game) cheat = game.cheats[1] pp.pprint(game.cheats) self.assertEqual(cheat.description, 'Lives') self.assertEqual(len(cheat.pokes), 1) self.assertEqual(cheat.pokes[0].address, 28950) self.assertEqual(cheat.pokes[0].value, 256)
def startGame(): if config.conn["server"]: threading.Thread(target=startServer).start() host = config.conn["host"] port = config.conn["port"] game = Game(host, port) game.run()
def test_hashsums(self): print(os.getcwd()) game = Game(zxdb_id=1660) game_file = GameFile('\pub\sinclair\games\e\E.T.X..tap.zip', game=game) expected_md5 = 'b04c5d9bf88eb5a008696d83eeee69ac' self.assertEqual(expected_md5, game_file.getMD5()) expected_sha1 = 'a879037fd3ba64170e83d4d44652681b1eb097e3' self.assertEqual(expected_sha1, game_file.getSHA1()) expected_crc32 = '3699934d' self.assertEqual(expected_crc32, game_file.getCRC32())
def test_simple_pokes_scraping(self): game = Game(name='Tujad', zxdb_id=5448) self.ts.scrapePokes(game) self.assertEqual(len(game.cheats), 8) self.assertEqual(game.cheats[0].description, "Infinite lives") self.assertEqual(len(game.cheats[0].pokes), 1) self.assertEqual(game.cheats[0].pokes[0].value, 58) self.assertEqual(game.cheats[1].description, "Infinite energy") self.assertEqual(len(game.cheats[1].pokes), 1) self.assertEqual(game.cheats[1].pokes[0].address, 31443)
def test_set_publisher(self): g = Game() g.setPublisher('Apogee Software [1]') self.assertEqual('Apogee', g.publisher) g.setPublisher('Ariolasoft UK Ltd') self.assertEqual('Ariolasoft UK', g.publisher) g.setPublisher('Incentive Software Ltd') self.assertEqual('Incentive', g.publisher) g.setPublisher('16/48 Tape Magazine') self.assertEqual(g.publisher, '16-48 Tape Magazine')
def test_double_tr_ru(self): game = Game('Saboteur II') file = GameFile('Saboteur II (19xx)(-)[h Crudesoft ru][t][tr ru].tap') file.getParamsFromTOSECPath('Saboteur II (19xx)(-)[tr ru Rybkin].tap') self.assertEqual(file.mod_flags, '[h Crudesoft ru][t][tr ru Rybkin]') file = GameFile( 'Saboteur II (19xx)(-)[h Crudesoft ru][t][tr ru Rybkin].tap') file.getParamsFromTOSECPath('Saboteur II (19xx)(-)[tr ru].tap') file.sortModFlags() self.assertEqual(file.mod_flags, '[h Crudesoft ru][t][tr ru Rybkin]')
def test_game_jsonable(self): player1 = Player("Marto") player2 = Player("Pesho") player3 = Player("Nasko") player4 = Player("Petko") team1 = Team("Wolf") team2 = Team("Lion") team1.add_team_members([player1, player2]) team2.add_team_members([player3, player4]) round1 = Round("All trumps", 1) round1.add_round_members([team1, team2]) game = Game([team1, team2], 1) game.rounds.append(round1) self.assertEqual( game.to_json(), json.dumps( { "game 1": [{ "round 1": [{ "Wolf": [{ "Marto": { "points": 0, "announcements": [], "cards": [] } }, { "Pesho": { "points": 0, "announcements": [], "cards": [] } }] }, { "Lion": [{ "Nasko": { "points": 0, "announcements": [], "cards": [] } }, { "Petko": { "points": 0, "announcements": [], "cards": [] } }] }] }] }, cls=OurEncoder))
def test_get_score_deuce(self): player_one = Player(PLAYER_NAME_ONE) player_two = Player(PLAYER_NAME_TWO) game = Game(player_one, player_two, False) for index in range(4): game.score = PLAYER_NAME_ONE game.score = PLAYER_NAME_TWO # Check the Deuce game self.assertEqual(game.score, 'Deuce')
def main(): while True: print("YGO-FM REMAKE") choice = int(input("Enter (1) to play, any number to exit game: ")) if choice == 1: from classes.game import Game game_instance = Game() Game.game_over = False #game_instance.gameLoop() else: break print("Thanks for playing!")
def gameFromRow(self, row): # print(row['name']) # print('game_name=', row.get('tosec_compliant_name', row['name'])) game_name = row.get('tosec_compliant_name', '').strip() if not game_name: game_name = row['name'] game_name = self.sanitizeAlias(game_name) game = Game(game_name, int(row['zxdb_id'])) publisher = self.publisherNameFromRow(row) game.setPublisher(publisher) try: author = self.authorNameFromRow(row) except: print(traceback.format_exc()) print("author=", row['author']) game.setAuthor(author) game.setYear(row['year']) pok_file_path = self.pok_file_paths.get(game.zxdb_id) if pok_file_path: game.importPokFile(file_path=pok_file_path) #TEMPORARY if not row['genre']: if game.zxdb_id in (32168, 32169, 32170, 32171, 32172, 32173, 32174, 32180, 30349, 32176, 32201, 32175, 34322, 35847, 35826, 34775, 35829, 35782, 35783, 36477, 36372, 35874, 35883, 35827): game.setGenre('Various Games') elif game.zxdb_id in (32176, ): game.setGenre('Utilities - Screen') elif game.zxdb_id in (32257, 32258, 32259): game.setGenre('Utilities') elif game.zxdb_id in (27590, 1000246): game.setGenre('Firmware') elif game.zxdb_id in (36062, ): game.setGenre('Emulator') elif game.zxdb_id in (8100, ): game.setGenre('Compilation - Educational') else: game.setGenre(row['genre']) game.x_rated = row['x_rated'] game.setNumberOfPlayers(row['number_of_players']) game.setMachineType(row['machine_type']) if row['language']: if row['language'] in IDIOM_IDS_TO_TOSEC_LANGS: game.setLanguage(IDIOM_IDS_TO_TOSEC_LANGS[row['language']]) else: game.setLanguage(row['language']) game.setAvailability(row['availability']) game.tipshop_page = row['tipshop_page'] game.raw_publisher, game.raw_author = [row['publisher'] ], [row['author']] return game
def test_players(players, total_games, verbose=False, turn_limit=100): num_wins = [0] * len(players) for i in range(total_games): if i % 10 == 0: print("Episodes:", i) game = Game(random.sample(players, len(players)), verbose=verbose) game.turn_limit = turn_limit winner = game.play() num_wins[players.index(winner)] += 1 for i in range(len(players)): wins_array[i] = num_wins[i] / total_games print(players[i].name, ": ", num_wins[i] / total_games)