def main(): vista.init() pygame.display.set_caption("Obb is loading.... Please wait") savefile = data.filepath("savegame.pkl") noise.nexttrack() if settings.restart: context.push(play.Play()) else: try: context.push(cPickle.load(open(savefile, "rb"))) except: context.push(play.Play()) clock = pygame.time.Clock() savetime = settings.savetimer while context.top(): dt = min(clock.tick(settings.maxfps) * 0.001, 1. / settings.minfps) if settings.fast: dt *= 2 con = context.top() events = pygame.event.get() keys = pygame.key.get_pressed() mousepos = pygame.mouse.get_pos() buttons = pygame.mouse.get_pressed() if settings.autosave: savetime -= dt if savetime < 0: cPickle.dump(con, open(savefile, "wb")) savetime = settings.savetimer for event in events: if event.type == QUIT: if settings.saveonquit: cPickle.dump(con, open(savefile, "wb")) return if event.type == KEYDOWN and event.key == K_ESCAPE: if settings.saveonquit: cPickle.dump(con, open(savefile, "wb")) return if event.type == KEYDOWN and event.key == K_F12: vista.screencap() if event.type == KEYDOWN and event.key == K_F9: # Manual save cPickle.dump(con, open(savefile, "wb")) con.think(dt, events, keys, mousepos, buttons) con.draw() if settings.showfps: pygame.display.set_caption("Obb - %.1ffps" % clock.get_fps()) if settings.fullscreen: print clock.get_fps() else: pygame.display.set_caption("Obb")
def __init__(self, path): self.plays = {} self.path = path with open(path) as f: self.playbook = json.load(f) for key in self.playbook: self.plays[key] = play.Play(key, self.playbook[key])
def prepare_tests(self): self.ui.information_label.setText("Przygotowywanie") self.settigns.game_settings.max_episodes_number = self.test_settings_ui.spinBox.value( ) self.settigns.agent_settings.is_LSTM = self.test_settings_ui.checkBox.isChecked( ) if self.test_settings_ui.saved_agent_radio.isChecked(): loaded_agent_directory = self.loaded_agent_directory else: loaded_agent_directory = "" if self.settigns.game_settings.game_name == "cartpole": self.game = play.Play(self.settigns, True, True, loaded_agent_directory, True) if game_type[self.settigns.game_settings.game_name] == "atari": self.game = play.PlayAtari(self.settigns, True, True, loaded_agent_directory, True) self.game.statistics.signal_plot.connect(self.plot) self.game.signal_episode.connect( self.update_infromation_about_episode_number) self.game.signal_done.connect(self.test_done) self.ui.information_label.setText("Testy:epizod 0") self.game.start()
def prepare_learning(self): self.ui.information_label.setText("Przygotowywanie...") self.settigns.game_settings.max_steps_number = self.learning_ui.steps_number.value( ) self.settigns.game_settings.target_accuracy = self.learning_ui.stop_accuracy.value( ) self.settigns.agent_settings.is_LSTM = self.learning_ui.Is_LSTM_checkbox.isChecked( ) if self.settigns.game_settings.game_name == "cartpole": self.game = play.Play( self.settigns, False, False, self.loaded_agent_directory, self.learning_ui.saved_agent_radio.isChecked()) if game_type[self.settigns.game_settings.game_name] == "atari": self.game = play.PlayAtari( self.settigns, False, False, self.loaded_agent_directory, self.learning_ui.saved_agent_radio.isChecked()) self.game.statistics.signal_plot.connect(self.plot) self.game.signal_episode.connect( self.update_infromation_about_episode_number) self.game.signal_done.connect(self.learning_done) self.ui.information_label.setText("Trwa uczenie:epizod 0") self.game.start()
def main_loop(self): """Method initalizing the menu and play loops """ while self.status.main: Main.menu_loop(self) self.play = play.Play() Main.play_loop(self)
def addEmptyPlay(self, key): template = json.loads('{"options" : {"autorun" : "true","scheduler" : {"sDT" : "2016-1-1 12:00:00","eDT" : "2016-1-1 12:00:00","interval" : "-1"}},"play" : []}') if key not in self.plays: self.playbook[key] = template data = self.playbook[key] self.plays[key] = play.Play(key, data) return {"status" : "added empty play"} else: return {"status" : "play already exists"}
def main(): game_kwargs = {'stones': 39, 'move_size': 3, 'verbose': True} game = nim.Nim rollouts = 400 player_start = 1 batch_size = 1 verbose = False p = play.Play(game_kwargs, game, rollouts, player_start, batch_size) p.play_game()
def __init__(self): config.actual_level = 1 py.display.set_mode((1024, 768)) config.clearBackground() config.screen.blit(config.again, (0, 0)) self.running = True self.button_choosen_id = 0 self.button_choosen = {0: 'images/again.png', 1: 'images/do_menu.png'} img = py.image.load('images/again.png').convert() config.screen.blit(img, (0, 0)) py.display.flip() while self.running: for event in py.event.get(): if event.type == py.KEYDOWN: if event.key == py.K_DOWN: self.button_choosen_id += 1 if self.button_choosen_id == 2: self.button_choosen_id -= 2 imagePath = self.button_choosen[self.button_choosen_id] img = py.image.load(imagePath).convert() config.screen.blit(img, (0, 0)) py.display.flip() py.display.update() if event.key == py.K_UP: self.button_choosen_id -= 1 if self.button_choosen_id < 0: self.button_choosen_id += 2 imagePath = self.button_choosen[self.button_choosen_id] img = py.image.load(imagePath).convert() config.screen.blit(img, (0, 0)) py.display.flip() py.display.update() if event.key == py.K_RETURN: if self.button_choosen_id == 0: play.Play(1) self.running = False if self.button_choosen_id == 1: py.mixer.init() py.mixer.music.load('sounds/title.wav') py.mixer.music.play(-1) py.mixer.music.set_volume(config.volume) titlescreen.Titlescreen() self.running = False
def read_file(filename): #Verify the logic works and now play lines are skipped with open(filename, 'rt') as testfile: data = " " current_team = " " data = testfile.readline() #Attempt to remove title= from string before the while loop while data: #Change the team if a line is the start of a drive data = data.replace('title=', '') print(data) if determine_info(data) == 'team': split_data = data.split() current_team = split_data[0] print("THIS IS A TEST") print(data) if split_data[0].lower() == split_data[2].lower(): current_team = split_data[0] + " " + split_data[1] if split_data[0].lower() == split_data[3].lower(): current_team = split_data[0]+ " " + split_data[1] + \ " " + split_data[2] elif determine_info(data) == 'play': current_play = play.Play() current_play.play_values(data.lower()) #Update yaml file if current_play.down != None: current_play.determine_success() print("START DEBUG") print("Down: %s" % current_play.down) print("Yards to go: %s " % current_play.yards_left) print("Yards result: %s " % current_play.result) print("Success: %s" % current_play.success) print("END DEBUG") team.update_team(current_team, current_play) #prepare next line for start of loop data = testfile.readline()
from tkinter import * from PIL import ImageTk, Image import random import play play = play.Play() window = Tk() window.geometry("470x470") window.resizable(False, False) window.title("RPSLS Game") rock_btn = Button(window, text="Rock", command=lambda: show_image(0)) paper_btn = Button(window, text="Paper", command=lambda: show_image(1)) scissors_btn = Button(window, text="Scissors", command=lambda: show_image(2)) lizard_btn = Button(window, text="Lizard", command=lambda: show_image(3)) spock_btn = Button(window, text="Spock", command=lambda: show_image(4)) rock_btn.place(x=25, y=370, width=90) paper_btn.place(x=190, y=370, width=90) scissors_btn.place(x=345, y=370, width=90) lizard_btn.place(x=110, y=420, width=90) spock_btn.place(x=280, y=420, width=90) rock = ImageTk.PhotoImage(Image.open("img/rock.jpg")) paper = ImageTk.PhotoImage(Image.open("img/paper.jpg")) scissors = ImageTk.PhotoImage(Image.open("img/scissors.jpg")) lizard = ImageTk.PhotoImage(Image.open("img/lizard.jpg")) spock = ImageTk.PhotoImage(Image.open("img/spock.jpg"))
from tornado.options import define, options #some global information like session import play import api # 先初始化播放器 global player # mongodb数据库 option = { 'host': 'localhost', 'port': 27017, 'db': 'MusicBox', } player = play.Play(option) define("port", default=80, help="run on the given port", type=int) define("db", default='MusicBox', help="database name", type=str) define("user", default='root', help="database user", type=str) define("pwd", default='xiaocao', help="database password", type=str) NetEase = api.NetEase() login = NetEase.login('username', 'password') class Application(tornado.web.Application): '''setting || main || router''' def __init__(self): handlers = [ #for html
def initPlays(self): for key in self.playbook: self.plays[key] = play.Play(key, self.playbook[key])
import time import base64 import uuid from tornado.escape import json_encode from tornado.options import define, options import play import api from dbsqlite import DbSqlite # 先初始化播放器 global player player = play.Play() db = DbSqlite() define("port", default=80, help="run on the given port", type=int) NetEase = api.NetEase() class Application(tornado.web.Application): '''setting || main || router''' def __init__(self): handlers = [ #for html (r"/", MainHandler), (r"/index", IndexHandler), (r"/shutdown", ShutdownHandler), # (r"/song.html", GetSongHandler),
def __init__(self): self.running = True self.sub_running = False self.button_choosen_id = 0 self.button_choosen = { 0: 'images/titlescreen_play.png', 1: 'images/titlescreen_instructions.png', 2: 'images/titlescreen_highscores.png', 3: 'images/titlescreen_exit.png' } self.backToMenu = py.image.load('images/do_menu.png').convert() self.again = py.image.load('images/again.png').convert() imagePath = self.button_choosen[self.button_choosen_id] img = py.image.load(imagePath).convert() config.screen.blit(img, (0, 0)) py.display.flip() while self.running: py.init() config.screen # = py.display.set_mode((1024, 768)) py.display.set_caption("Bomberman") icon = py.image.load('images/icon.png') py.display.set_icon(icon) vol = py.mixer.music.get_volume() text = config.font.render(str(round(vol, 1)), True, (255, 245, 1), (81, 81, 81)) textRect = text.get_rect() textRect.center = (950, 726) config.screen.blit(text, textRect) py.display.update() config.fps for event in py.event.get(): if event.type == py.QUIT: self.running = False py.quit() elif event.type == py.KEYDOWN: if event.key == py.K_DOWN and not self.sub_running: self.button_choosen_id += 1 if self.button_choosen_id == 4: self.button_choosen_id -= 4 imagePath = self.button_choosen[self.button_choosen_id] img = py.image.load(imagePath).convert() config.screen.blit(img, (0, 0)) py.display.flip() if event.key == py.K_UP and not self.sub_running: self.button_choosen_id -= 1 if self.button_choosen_id < 0: self.button_choosen_id += 4 imagePath = self.button_choosen[self.button_choosen_id] img = py.image.load(imagePath).convert() config.screen.blit(img, (0, 0)) py.display.flip() if event.key == py.K_RIGHT: if vol < 1: vol += 0.1 py.mixer.music.set_volume(round(vol, 1)) config.volume += 0.1 else: pass if event.key == py.K_LEFT: if vol > 0: vol -= 0.1 config.volume -= 0.1 py.mixer.music.set_volume(round(vol, 1)) else: pass if event.key == py.K_RETURN: if self.button_choosen_id == 3: self.running = False py.quit() if self.button_choosen_id == 2: self.sub_running = True h = highscore.Highscore() h.displayScore() self.running = False if self.button_choosen_id == 1: self.sub_running = True instructions.Instructions() self.running = False if self.button_choosen_id == 0: self.sub_running = True play.Play(1) self.running = False
def main(): anet_layers = { 3: [120, 64], 4: [120, 64], 5: [512, 256, 128, 64], 6: [240, 128, 64], 7: [240, 128, 64], 8: [240, 128, 64] } ################### # Game parameters # ################### side_length = 4 rollouts = (50, 'r') # r -> amount ; s -> seconds epsilon = 0.1 player_start = -1 # -1 -> random verbose = False play_game = True batch_size = 8 train_epochs = 200 rbuf_mbs = 64 topp_training = True topp_k = 5 play_versus = False num_versus_matches = 1000 pre_train = False pre_train_epochs = 1 pre_train_max_amount = 2000 run_topp = True games_per_series = 20 run_good_topp = False ################### # Anet parameters # ################### lrate = 2 optimizer = 'sgd' haf = 'tanh' oaf = 'sigmoid' loss = 'mean_absolute_error' hidden_layers = anet_layers[side_length] load_existing = True anet_name = None ######### # Setup # ######### game = hex.Hex game_kwargs = {'side_length': side_length, 'verbose': verbose} list_of_topps = [] input_layer_size = 2 * side_length**2 + 2 output_size = side_length**2 anet_name = 'anet_' + str(side_length) + 'x' + str( side_length) if not anet_name else anet_name layers = [input_layer_size] layers.extend(hidden_layers) layers.append(output_size) anet_kwargs = { 'layers': layers, 'haf': haf, 'oaf': oaf, 'loss': loss, 'optimizer': optimizer, 'lrate': lrate, 'model_name': anet_name, 'pre_train_epochs': pre_train_epochs, 'load_existing': load_existing } ############ # Gameplay # ############ p = play.Play(game_kwargs, game, rollouts, player_start, batch_size, rbuf_mbs, anet_kwargs=anet_kwargs, train_epochs=train_epochs, epsilon=epsilon) if play_game: list_of_topps = p.play_game(topp=topp_training, topp_k=topp_k) #game_kwargs['verbose'] = False if play_versus: anet_player = anet.Anet(**anet_kwargs) if pre_train: all_c = p.get_all_cases() pre_train_cases = all_c[0:pre_train_max_amount] random.shuffle(pre_train_cases) anet_player.train_on_cases(pre_train_cases) anet_player.save_model() v = versus.Versus(game_kwargs, game, num_versus_matches, player_start, player1=anet_player, player2=None) v.match() if run_topp: list_of_topps = list_of_topps if list_of_topps else [ 'anet_5x5_topp_0', 'anet_5x5_topp_50', 'anet_5x5_topp_100', 'anet_5x5_topp_150', 'anet_5x5_topp_200' ] topp_ = topp.Topp(list_of_topps, game_kwargs, game, games_per_series) topp_.run_topp() if run_good_topp: list_of_topps = [ 'anet_5x5_topp_0', 'anet_5x5_topp_50', 'anet_5x5_topp_100', 'anet_5x5_topp_150', 'anet_5x5_topp_200' ] topp_ = topp.Topp(list_of_topps, game_kwargs, game, games_per_series) topp_.run_topp()
def __init__(self, env, action_selector, agent, sneaky_env, sneaky_actor, record_lock, config): super(PlayClass, self).__init__() self.play = play.Play(env, action_selector, agent, sneaky_env, sneaky_actor, record_lock, config)