def main(): eg = engine.GameEngine() try: # check language if not lmgr.GLOBAL_LANGUAGE: print('Warning : Failed to language package \r') save = ask_for_save() s = eg.run_game(save) except (KeyboardInterrupt, EOFError): pass if eg.save: print(lmgr.GLOBAL_LANGUAGE.Global.auto_save) signal = SaveManager.write_save(eg.save) if signal: print(lmgr.GLOBAL_LANGUAGE.Global.save_succeed) else: print(lmgr.GLOBAL_LANGUAGE.Global.save_failed) print(lmgr.GLOBAL_LANGUAGE.Global.show_score % eg.save.now_score) print(lmgr.GLOBAL_LANGUAGE.Global.highest_score % eg.save.high_score) print(lmgr.GLOBAL_LANGUAGE.Global.exit_game)
def main(): """ Prepare our environment, create a display, and start the program. """ os.environ['SDL_VIDEO_CENTERED'] = '1' pygame.mixer.pre_init(44100) pygame.init() pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT)) pygame.display.set_icon(pygame.image.load(ICONPATH).convert_alpha()) pygame.display.set_caption(TITLE) game = engine.GameEngine() game.on_enter() game.main_loop() # game.on_exit() pygame.quit() sys.exit()
def main(): pygame.init() screen = pygame.display.set_mode((640, 480)) pygame.display.set_caption('Tetris, Bitch!') pygame.mouse.set_visible(1) # TODO move this to a specific gamestate class clock = pygame.time.Clock() game = engine.GameEngine(screen) menu = state.MainMenuState(game) game.change_state(menu) while game.is_running: delta = clock.tick(60) game.draw(delta) game.update(delta)
def main(): parser = argparse.ArgumentParser( description='Play the CodeNames game.', formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('-c', '--config', type=str, default='CHCH', help='Config <spy1><team1><spy2><team2> using C,H.') parser.add_argument( '-x', '--expert', action='store_true', help='Expert clues. For now implements \'unlimited\' only.') parser.add_argument('--seed', type=int, default=None, help='Random seed for reproducible games.') parser.add_argument('--init', type=str, default=None, help='Initialize words ASSASSIN;TEAM1;TEAM2;NEUTRAL') args = parser.parse_args() if not re.match('^[CH]{4}$', args.config): print('Invalid configuration. Try HHHH or CHCH.') return -1 d = dict(H='human', C='computer') spy1 = d[args.config[0]] team1 = d[args.config[1]] spy2 = d[args.config[2]] team2 = d[args.config[3]] e = engine.GameEngine(seed=args.seed, expert=args.expert) e.play_game(spy1, team1, spy2, team2, init=args.init)
game_id = data['game_id'] users.validate(username, password) if game_id in game_engine.get_player_games(username): role = game_engine.get_player_role(game_id, username) join_room(str(game_id) + role) update_clients_for_game(game_id) except AuthException as ex: return (ex.msg, 401) @socketio.on('leave_game') def on_leave_game(data): try: username = data['username'] password = data['password'] game_id = data['game_id'] users.validate(username, password) if game_id in game_engine.get_player_games(username): role = game_engine.get_player_role(game_id, username) leave_room(str(game_id) + role) except AuthException as ex: return (ex.msg, 401) if __name__ == '__main__': global game_engine with file('properties.json') as property_file: properties = json.load(property_file) storage = StorageMySql(properties['database']) users = UserStore(properties['database']) game_engine = engine.GameEngine(storage) socketio.run(app, properties['bind_ip_address'], port=properties['bind_port'])
def main(): parser = argparse.ArgumentParser( description="Benchmark an ai.", formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) parser.add_argument( "--iters", type=int, default=1000, help="How many games should be generated and tested", ) parser.add_argument( "--seed", type=int, default=100, help="Random seed to have identical matches to benchmark", ) parser.add_argument( "--filename", type=str, default="benchmarks/benchmark.txt", help="Name of file the benchmark gets saved to", ) parser.add_argument( "--writealong", type=bool, default=False, help="Writes to file after every loop" ) parser.add_argument( "--pickup", type=bool, default=False, help="Whether to open the file and pick up", ) args = parser.parse_args() generator = np.random.RandomState(seed=args.seed) e = engine.GameEngine(seed=args.seed, display=False) tracker = Tracker() skip_index = 0 if args.pickup: tracker.load_from_file(args.filename) skip_index = tracker.size() clear_screen() for i in tqdm(range(args.iters)): e.initialize_random_game() e.next_turn() if i % 2 == 0: e.next_turn() if i < skip_index: continue e.print_board(clear_screen=False, override=True) clue, words = e.play_computer_spymaster(give_words=True) tracker.add(str(clue)[2:-1], [str(word)[2:-1] for word in words], e) clear_screen() if args.writealong: tracker.save_to_file(args.filename) print(tracker.word_counts) print("Saving to file...") tracker.save_to_file(args.filename)
import engine import map # WW2 mania! # # A command line ww2 story. # map = map.Map('level_one_intro') # initializing map class ww2_mania = engine.GameEngine(map) # allowing the game engine to read the room ww2_mania.start() # starting the game
def main(): parser = argparse.ArgumentParser( description="Play the CodeNames game.", formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) parser.add_argument( "--nohide", type=bool, default=False, help="Shows only 1 clue, hides what the words for each clue", ) args = parser.parse_args() e = engine.GameEngine() # manual init pytesseract.pytesseract.tesseract_cmd = ( r"C:\\Program Files\\Tesseract-OCR\\tesseract.exe") config = "-l eng --oem 1 --psm 3" e.size = 5 pad = 20 img = cv.imread("board.png") colors_loc = [[], [], [], []] word_color_map = {} board = [] cx, cy = img.shape[1] // 5, img.shape[0] // 5 for y in range(5): for x in range(5): img_sec = img[y * cy + pad:(y + 1) * cy - pad, x * cx + pad:(x + 1) * cx - pad] img_gray = cv.cvtColor(img_sec, cv.COLOR_BGR2GRAY) avg = np.average(img_gray) mask1 = img_gray[:, :] < avg mask2 = img_gray[:, :] > avg img_gray[mask2] = 0 img_gray[mask1] = 255 kernel = np.ones((3, 3), np.uint8) erosion = cv.erode(img_gray, kernel, iterations=1) text = pytesseract.image_to_string(img_sec, config=config).replace( " ", "_") board.append(text) dev = [0, 0, 0, 0] for c in range(3): avg = np.median(img_sec[:, :, c]) for i, color in enumerate(colors): # print(avg, color[c]) dev[i] += (avg - color[c])**2 index, smol = 0, dev[0] if not args.nohide: print("({},{}) -> {}".format(x + 1, y + 1, text)) else: print("({},{}) -> {} = {}".format(x + 1, y + 1, text, dev)) for i in range(1, 4): if dev[i] < smol: smol = dev[i] index = i colors_loc[index].append(( x, y, )) word_color_map[text] = color_names[index] # cv.imshow('img', erosion) # cv.imshow('img_pre', img_sec) # cv.waitKey() # play the game active = {} for word in board: active[word] = True input("Loaded successfully! Hit enter to continue: ") print_board(board, active) values = None index = 0 side = "" given_words = [] while True: print_board(board, active) if values: if not args.nohide: clue, words, best_score = values[index] say(u"{3}{0:.3f} {1} {2}".format(best_score, str(clue)[2:-1], len(words), side)) else: for clue, words, best_score in values: say(u"{0:.3f} {2} {3} = {1}".format( best_score, " + ".join([str(w).upper()[2:-1] for w in words]), str(clue)[2:-1], len(words), )) text = input().upper() if text in ("EXIT", "QUIT"): return if text in board: active[text] = not active[text] if text in ("USE", "USED"): given_words.append(clue) elif text == "RED" or text == "BLUE": red_words = np.asarray([ word.lower().encode("utf8") for word in board if active[word] and word_color_map[word] == "red" ]) blue_words = np.asarray([ word.lower().encode("utf8") for word in board if active[word] and word_color_map[word] == "blue" ]) neutral_words = np.asarray([ word.lower().encode("utf8") for word in board if active[word] and word_color_map[word] == "white" ]) assassin_word = [ word.lower().encode("utf8") for word in board if active[word] and word_color_map[word] == "black" ] if text == "RED": values = play_computer_spymaster(e, red_words, blue_words, neutral_words, assassin_word, given_words) side = "red: " else: values = play_computer_spymaster(e, blue_words, red_words, neutral_words, assassin_word, given_words) side = "blue: " index = 0 elif text == "NEXT": index += 1 if index >= len(values): index -= len(values) elif text == "PREV": index -= 1 if index < 0: index += len(values)
import engine if __name__ == "__main__": game = engine.GameEngine() game.initializeGame()
ai_players = [] for i in range(len(ai_players_seed)): if ai_players_seed[i]: ai_players.append(i) human_players = [p for p in range(5) if p not in ai_players] if len(human_players) == 1: space = 0 ai_nums_str = ', '.join([str(x) for x in ai_players]) print('Player numbers {} are AI agents.'.format(ai_nums_str)) print() # Initiating the game object. mighty_game = engine.GameEngine() feedback = -1 final_trump = None introduce_hands(mighty_game.hands, human_players) # Here starts the game loop. while True: ''' ################################### TESTING ############################ import tempest print(repr(tempest.Inferences(mighty_game.perspective(0)))) input("\nWAITING...") ######################################################################## ''' call_type = mighty_game.next_call