def __init__(self): if len(sys.argv) < 2: print "Usage: python AdventureMaker.py <name of scene to edit>" sys.exit(1) screen = pyglet.window.get_platform().get_default_display().get_default_screen() super(AdventureMakerWindow,self).__init__(width=screen.width-20, height=gamestate.norm_h, vsync=True) gamestate.main_window = self gamestate.scripts_enabled = False gamestate.init_scale() gamestate.keys = pyglet.window.key.KeyStateHandler() gamestate.main_window.push_handlers(gamestate.keys) engine.init() pyglet.gl.glEnable(pyglet.gl.GL_BLEND) pyglet.gl.glBlendFunc(pyglet.gl.GL_SRC_ALPHA, pyglet.gl.GL_ONE_MINUS_SRC_ALPHA) self.set_caption("Scene Editor: %s" % sys.argv[1]) self.editorview = editorview.EditorView(sys.argv[1]) pyglet.clock.schedule_interval(self.on_draw, 1/60.0) pyglet.clock.schedule_interval(self.editorview.update, 1/120.0)
def play_game(net): """Plays one game controlled by the given network. Returns the score the network achieved.""" engine.init() # Play until the net tries to make the same move twice. # If this happens, it will be fed with the same input again, # so there will be an infinite loop. # This has the added advantage that if it is impossible to make a move # the loop will exit as well, so I don't have to call engine.can_move(), # which is inefficient. prev = None while engine.board != prev: prev = engine.copy_board() max_item = max(map(max, engine.board)) inputs = [] for row in engine.board: for item in row: # Each number is fed to the neural network as a fraction # of the maximum. inputs.append(item / max_item) outputs = net.compute(inputs) # find the index of the highest output move_index = outputs.values.index(max(outputs)) engine.move(move_index) return engine.score
def __init__(self, reset_save=False, reset_at_scene=None): reset_save = reset_save or reset_at_scene if util.settings.fullscreen: super(AdventureWindow,self).__init__(fullscreen=True, vsync=True) else: super(AdventureWindow,self).__init__(width=gamestate.norm_w, height=gamestate.norm_h, vsync=True) gamestate.main_window = self # Make main window accessible to others. # Necessary for convenient event juggling. gamestate.init_scale() # Set up scaling transformations to have # a consistent window size gamestate.event_manager = eventmanager.EventManager() pyglet.gl.glEnable(pyglet.gl.GL_BLEND) pyglet.gl.glBlendFunc(pyglet.gl.GL_SRC_ALPHA, pyglet.gl.GL_ONE_MINUS_SRC_ALPHA) pyglet.gl.glEnable(pyglet.gl.GL_LINE_SMOOTH) self.game_handler = None engine.init() # Set up resource paths self.init_load() with pyglet.resource.file(util.respath('game', 'info.json'), 'r') as game_info_file: self.game_info = json.load(game_info_file) self.game_info['reset_save'] = reset_save if reset_at_scene: self.game_info['first_scene'] = reset_at_scene self.set_caption(self.game_info["name"]) # Stupid hack to get around pyglet loading bullshit pyglet.clock.schedule_once(self.finish_loading, 0.0000001)
def main(): engine.init() print(colors.WARNING) banner() print(colors.ENDC) ip = input(colors.OKBLUE + '[---] IP : ' + colors.ENDC) port = int(input(colors.OKBLUE + '[---] PORT : ' + colors.ENDC)) victim = input(colors.OKBLUE + '[---] IP OF VICTIM : ' + colors.ENDC) engine.run(ip, port, victim)
def request_swap(self): try: print("Attempting to swap engine...") reload(engine) print("Engine swapped. Reinitializing engine...") engine.init() print("Engine reinitialized\n") except Exception as error: print("Errors were thrown in the engine swap:") print(error)
def main(): objUser = open("USERNAME.txt", "r") objPassword = open("PASSWORD.txt", "r") flag = 0 browser = webdriver.Firefox() tag = getHashtag(browser, flag) engine.init(browser, tag, flag) engine.update(browser)
def main(): global clock global main_menu global surface pygame.init() pygame.display.set_caption("GC2 Snake v1.0") pygame.font.init() os.environ['SDL_VIDEO_CENTERED'] = '1' surface = pygame.display.set_mode(WINDOW_SIZE) clock = pygame.time.Clock() setting_menu = create_menu('Settings') setting_menu.add_selector('Players: ', [('1', 1), ('2', 2), ('3', 3), ('4', 4)], selector_id='players', default=0, onchange=player_changed) setting_menu.add_selector('Speed: ', [('1', 1), ('2', 2), ('3', 3), ('4', 4), ('5', 5), ('6', 6), ('7', 7), ('8', 8), ('9', 9)], selector_id='speed', default=5, onchange=speed_changed) setting_menu.add_option('Return to main', pygameMenu.events.BACK) about_menu = create_menu('About') for m in ABOUT: about_menu.add_line(m) about_menu.add_line(pygameMenu.locals.TEXT_NEWLINE) about_menu.add_option('Return to main', pygameMenu.events.BACK) main_menu = create_menu('Main') main_menu.add_option('Start', play_function) main_menu.add_option('Settings', setting_menu) main_menu.add_option('About', about_menu) main_menu.add_option('Quit', pygameMenu.events.EXIT) main_menu.set_fps(FPS) engine.init(clock, surface) while True: clock.tick(FPS) main_background() events = pygame.event.get() for event in events: if event.type == pygame.QUIT: exit() main_menu.mainloop(events) pygame.display.flip()
def main(): game_state = init(max_guess, guesses) while not game_state.game_over: game_state = guess(game_state, prompt(game_state)) end_game(game_state)
def startGame(self,depth,firstMove=0,players=1): self.state = engine.init(depth,computer=firstMove,humans=players) if(players == 1): self.engineThread = EngineThread(self.state) self.findMove.connect(self.engineThread.findMove) self.engineThread.searchFinished.connect(self.computerMove) self.threadHandle = QtCore.QThread() self.engineThread.moveToThread(self.threadHandle) self.threadHandle.start() self.play()
def run(self): engine.init() clock = pygame.time.Clock() self.running = True dt = 0 frames = 0 while self.running: self.handle_input() if self.swapped: self.swapped = False continue self.simulate(dt) self.render() dt = clock.tick(self.FPS) frames += 1 # Report framerate on exit ticks = pygame.time.get_ticks() framerate = frames / (ticks / 1000.0) print("Framerate was {0}".format(framerate))
def __init__(self): # initialise variables self.src = 0 self.dst = 0 self.thinking = False self.gameover = 0 self.side_to_move = RED #self.computer_colour = WHITE self.red_player = HUMAN self.white_player = COMPUTER self.custom_search_depth = 2 self.custom_time_limit = 2 self.level = 0 # set paths to images. opening book etc (opening_book_path, end_game_2pc_path, end_game_3pc_path, end_game_4pc_path) = self.set_data_paths() # initialise the engine # Pass in the paths of the opening book and endgame databases to load board_position = engine.init(opening_book_path, end_game_2pc_path, end_game_3pc_path, end_game_4pc_path) # instantiate board, gui, classes self.board = board.Board(board_position) self.gui = gui.Gui() self.board.set_refs(self, self.gui) self.gui.set_refs(self, self.board) # build gui, board self.gui.build_gui() self.board.build_board() # restore users settings to values from previous game self.restore_settings() # set status bar msg self.gui.set_status_bar_msg(self.get_side_to_move_msg()) self.gui.init_all_dnd()
def __init__(self): gv.gshogi = self # set global variables for debug messages gv.verbose, gv.verbose_usi = utils.get_verbose() # prefix to find package files/folders self.prefix = utils.get_prefix() # set up .gshogi directory in the home directory self.gshogipath = utils.create_settings_dir() self.glade_dir = os.path.join(self.prefix, "glade") # get settings saved from previous game self.settings = utils.get_settings_from_file(self.gshogipath) self.ask_before_promoting = False self.gameover = False self.time_limit = "00:10" self.stopped = True self.quitting = False self.src = "" self.src_x = "" self.src_y = "" self.startpos = "startpos" self.start_stm = BLACK self.search_depth = 39 self.thinking = False self.cmove = "none" self.movelist = [] self.redolist = [] self.player = ["Human", "gshogi"] self.pondermove = [None, None] opening_book_path = os.path.join(self.prefix, "data/opening.bbk") engine.init(opening_book_path, gv.verbose) gv.gui = gui.Gui() gv.pieces = pieces.Pieces() # custom pieceset path if self.settings != "": gv.pieces.set_custom_pieceset_path( self.settings.custom_pieceset_path) gv.pieces.load_pieces(self.prefix) # usiw is the instance that plays white (gote) # usib is the instance that plays black (sente) gv.usib = usi.Usi("b") gv.usiw = usi.Usi("w") # instantiate board, gui, classes gv.tc = time_control.Time_Control() gv.engine_manager = engine_manager.Engine_Manager() gv.board = board.Board() self.set_board_colours = set_board_colours.get_ref() # set colours to previous game (if any) if self.settings != "": self.set_board_colours.restore_colour_settings( self.settings.colour_settings) gv.gui.build_gui() gv.board.build_board() self.engine_output = engine_output.get_ref() # set level command = "level 0 " + self.time_limit engine.command(command) # turn off beeps if not BEEP: engine.command("beep") # restore users settings to values from previous game self.restore_settings(self.settings) gv.usib.set_engine(self.player[BLACK], None) gv.usiw.set_engine(self.player[WHITE], None) gv.gui.update_toolbar(self.player) self.move_list = move_list.get_ref() gv.tc.reset_clock() gv.gui.enable_go_button() gv.gui.disable_stop_button() self.stm = self.get_side_to_move() self.timer_active = False self.set_board_colours.apply_colour_settings()
def handle_restart(self): self.state = init(self.max_guess, self.tries) self._update_state()
from selenium import webdriver from time import sleep import engine chromedriver = './chromedriver.exe' webdriver = webdriver.Chrome(executable_path=chromedriver) engine.init(webdriver) engine.update(webdriver) sleep(10) webdriver.close()
def gameRender(): global ball # must pass integers to the engine function call below x = int(ball.x) y = int(ball.y) radius = int(ball.radius) # draw the ball engine.drawCircle(x, y, radius) # engine configuration dict configuration = { 'DEBUG': False, 'SCREEN_WIDTH': 1920 / 2, 'SCREEN_HEIGHT': 1080 / 2, 'USE_FULLSCREEN': False, 'WINDOW_TITLE': 'Python Bouncing Ball Demo', 'create': 'gameCreate', 'destroy': 'gameDestroy', 'update': 'gameUpdate', 'render': 'gameRender' } # the engine will execute this python file on load # and this function call kicks things off engine.init(configuration)
import json from engine import init, predict from datetime import datetime from flask import Flask, render_template, jsonify, redirect, url_for, request, Response, json from flask_cors import CORS import time import requests #from license.License import isValid #from Digified.OCR.Utility.error_handler import ErrorHandler #Functions,classes, variables and so on are places here for the production ready app = Flask(__name__) app.config.from_object(__name__) app.config['UPLOAD_FOLDER'] = 'uploads' app.config['PROPAGATE_EXCEPTIONS'] = True svm, knn = init() CORS(app) def analyze_tweets(tweetsList): result = [] for tweet in tweetsList: emotion = {} emotion['tweet'] = tweet emotion['svm'] = predict(tweet, svm, knn, mode='svm') #emotion['knn'] = predict(tweet, svm, knn, mode='knn') result.append(emotion) return result
# -*- coding: utf-8 -*- from OpenGL.GL import * import engine as en, time import evsys as ev import signals import game from bind import * import harimau, track import cube en.init() root = game.Component() def lookAt(dir, up): m = en.Matrix() z = en.Vector(dir) z.normalize() x = en.Vector(up.cross(z)) x.normalize() y = en.Vector(z.cross(x)) m.m11, m.m12, m.m13 = x.x, x.y, x.z m.m21, m.m22, m.m23 = y.x, y.y, y.z m.m31, m.m32, m.m33 = z.x, z.y, z.z return m class Camera(game.Component): def __init__(self, evsys, updates, player): game.Component.__init__(self) #evsys.signal("keydown_left").Connect(self.move(-1, 0, 0)) """evsys.signal("keydown_left").Connect(bind(self.startMove, 1, 0, 0)) evsys.signal("keyup_left").Connect(bind(self.stopMove, 1, 0, 0))
def init(rng_state): # If I was smart, the dependency injection would have been on the random # module itself, not on the seed, but that's too late to change now. engine.init(rng_state) random.setstate(rng_state)
from random import randrange # import os # # # Engine Imports from Game Directory # # from engine import beach # from engine import text # from engine import conch # from engine import sun # from engine import title # from engine import island # from engine import init # from engine import Fore, Back, Style # from engine import names # from engine import license # from engine import tips # init(autoreset=True) # ############################################## # INTRODUCTION # title.title() # This will print the title defined in /engine/title.py text.print_fast("""Programming: Dawson Diaz """) title = raw_input(Fore.GREEN + Style.BRIGHT + "Press enter to begin or enter " + Style.BRIGHT + Fore.RED + "'l'" + Style.BRIGHT + Fore.GREEN + " for licenses and disclaimers, and " + Style.BRIGHT + Fore.RED + "'?'" + Style.BRIGHT + Fore.GREEN +" for Tips\nand Frequently Asked Questions\n") # This will require the player to press enter before printing next line os.system('cls' if os.name == 'nt' else 'clear') # This will clear the window # INTRODUCTION # if title == 'l': license.license() raw_input(Fore.CYAN + Style.BRIGHT +'Press enter to continue...') if title == "?": tips.tips()
pypath = os.path.join(pypath, "gshogi") sys.path.append(pypath) import engine text_opening_book = 'data/gnushogi.tbk' bin_opening_book = 'data/opening.bbk' booksize = 8000 bookmaxply = 40 # check input file exists if (not os.path.exists(text_opening_book)): print "Input file", text_opening_book, "not found" sys.exit() # delete the output file if it exists try: os.remove(bin_opening_book) except OSError, oe: pass # initialise the engine verbose = False engine.init(bin_opening_book, verbose) # call engine function to generate book file engine.genbook(text_opening_book, bin_opening_book, booksize, bookmaxply)
def __init__(self): self.verbose = False self.verbose_usi = False for arg in sys.argv: if arg == '-v' or arg == '--verbose': self.verbose = True if arg == '-vusi': self.verbose_usi = True self.ask_before_promoting = False self.gameover = False self.time_limit = '00:10' self.stopped = True self.quitting = False self.src = '' self.src_x = '' self.src_y = '' self.startpos = 'startpos' self.start_stm = BLACK self.search_depth = 39 self.thinking = False self.cmove = 'none' self.movelist = [] self.redolist = [] self.player = ["Human", "gshogi"] self.pondermove = [None, None] # set paths to images. opening book etc self.set_data_paths() opening_book_path = os.path.join(self.prefix, "data/opening.bbk") engine.init(opening_book_path, self.verbose) self.glade_dir = os.path.join(self.prefix, 'glade') utils.set_game_ref(self) # usiw is the instance that plays white (gote) # usib is the instance that plays black (sente) self.usib = usi.Usi(self.verbose, self.verbose_usi, 'b') self.usiw = usi.Usi(self.verbose, self.verbose_usi, 'w') utils.set_usi_refs(self.usib, self.usiw) # instantiate board, gui, classes self.tc = time_control.Time_Control(self.verbose) utils.set_tc_ref(self.tc) self.engine_manager = engine_manager.Engine_Manager(self.verbose) self.board = utils.get_board_ref() self.pieces = utils.get_pieces_ref() self.gui = utils.get_gui_ref() self.board.set_refs(self, self.gui) self.gui.set_refs(self, self.board, self.engine_manager, self.tc) self.gui.build_gui() self.board.build_board() self.engine_manager.set_refs(self, self.gui, self.usib, self.usiw) self.usib.set_refs(self, self.engine_manager, self.gui, self.tc) self.usiw.set_refs(self, self.engine_manager, self.gui, self.tc) self.tc.set_refs(self, self.gui) self.set_board_colours = set_board_colours.get_ref() self.engine_output = engine_output.get_ref() # set level command = 'level 0 ' + self.time_limit engine.command(command) # turn off beeps if not BEEP: engine.command('beep') # restore users settings to values from previous game self.restore_settings() self.usib.set_engine(self.player[BLACK], None) self.usiw.set_engine(self.player[WHITE], None) self.gui.update_toolbar(self.player) self.move_list = move_list.get_ref() self.tc.reset_clock() self.gui.enable_go_button() self.gui.disable_stop_button() self.stm = self.get_side_to_move() self.timer_active = False
def __init__(self): engine.init()
def main(): flag = 0 browser = webdriver.Firefox() tag = getHashtag(browser, flag) engine.init(browser, tag)
def run(): engine.init() while engine.can_move(): engine.move(random.randrange(4)) return engine.score
import sys def timer(): t0 = time.time() paused = False paused_time_elapsed = [] while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: paused = not paused if paused: paused_time_elapsed.append([time.time()]*2) else: paused_time_elapsed[-1][-1] = time.time() if not paused: engine.Display.update(int(time.time() - t0 - sum(map(lambda i: i[1]-i[0], paused_time_elapsed)))) if __name__ == "__main__": engine.init(4) engine.caption("7 Segment Display") timer()
####### #AS5 #Name: Zachary Carlson #Partner: Brittany McGarr ####### # create, initialize, and run the 381 engine import engine engine = engine.Engine() engine.init() engine.run()
import game import pirate import engine import player from bot import Bot miki = player.Player("miki" , 1) _game = game.Game(miki) dudu = player.Player("dudu" , 0) _game2 = game.Game(dudu) # with follwing exmple there is a problem ''' piratesA = [pirate.pirate(miki ,2*i + i* 1j, i ,4 ,2) for i in range(0,5)] piratesA += [pirate.pirate(dudu ,2*i + i* 1j, i ,4 ,2) for i in range(5,10)] hashlistX = [[i for i in range(0,10)] ,[_pirate for _pirate in piratesA]] hashlistY = [[i for i in range(0,10)] ,[_pirate for _pirate in piratesA]] hashlists = hashlistX ,hashlistY engine.init(piratesA ,hashlistX[0] , hashlistX[1] , \ hashlistY[0] , hashlistY[1 ]) # ---------------------- . piratesA[2].power = 3 piratesA[2].speed = 3 piratesA[6].speed = 7 piratesA[6].power = 7
class EngineThread(Thread): def __init__(self, args, id): Thread.__init__(self) self.args = args self.id = id self.result = None def run(self): self.result = engine.run(self.args, self.id) if __name__ == '__main__': # workaround for a bug in strptime - ref: http://bugs.python.org/issue7980 time.strptime('', '') argss = json.loads(raw_input()) engine.init() threads = [] results = [] for i in range(0, len(argss)): args = argss[i] thread = EngineThread(args, i) threads.append(thread) thread.start() for i in range(0, len(argss)): threads[i].join()
bin_opening_book = "gshogi/data/opening.bbk" booksize = 8000 bookmaxply = 40 # check input file exists if (not os.path.exists(text_opening_book)): print("Input file", text_opening_book, "not found") sys.exit() # create data folder for bin book data_folder = os.path.dirname(bin_opening_book) if not os.path.exists(data_folder): try: os.makedirs(data_folder) except OSError as exc: print("Unable to create data folder", data_folder) sys.exit() # delete the output file if it exists try: os.remove(bin_opening_book) except OSError as oe: pass # initialise the engine verbose = False engine.init(bin_opening_book, verbose) # call engine function to generate book file engine.genbook(text_opening_book, bin_opening_book, booksize, bookmaxply)
import engine from engine import pygame import time import sys def counter(): total = 0 while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type in [pygame.KEYDOWN, pygame.MOUSEBUTTONDOWN]: total += 1 engine.Display.update(total) if __name__ == "__main__": engine.init(2) engine.caption("Example - Counter display") counter()