def thread_handle(board_short, thread_post_id): current_board = Engine.get_board_by_short(board_short) return render_template( 'thread.html', current_board=current_board.dump_to_dict(), boards=Engine.get_boards_dumped(), posts=[Engine.get_thread_dumped(current_board, thread_post_id)])
def test_switchPlayer(self): e = Engine(4) e.current_player = 0 self.assertIs(e.current_player, 0) self.assertIs(e.switchPlayer(), 1) self.assertIs(e.switchPlayer(), 2) self.assertIs(e.switchPlayer(), 0)
def main(): args = get_args() engine = Engine("kernels/raytracer.cl", args.scene, args.w, args.h, args.noise, args.obj, args.animation, args.record, args.no_gui) engine.run()
def post_constructor_handle(board_short): board = Engine.get_board_by_short(board_short) parent_post = Engine.get_post_by_id(request.args.get('parent_post_id')) return render_template('post_constructor.html', boards=Engine.get_boards_dumped(), current_board=board, parent_post=parent_post)
def board_handle(board_short): current_board = Engine.get_board_by_short(board_short) return render_template( 'board.html', current_board=current_board.dump_to_dict(), boards=Engine.get_boards_dumped(), posts=Engine.get_threads_preview_dumped(current_board))
def board_make_post_handle(board_short): board = Engine.get_board_by_short(board_short) parent_post_id = int(request.args.get('parent_post_id')) body = request.args.get('body') head = request.args.get('head') files = json.loads(request.args.get('files')) parent_post = None if parent_post_id == 1: parent_post = Post.query.filter_by(id=parent_post_id).first() else: parent_post = Post.query.filter_by(id=parent_post_id, board=board).first() if not parent_post: return "<h1>There is no such post :|</h1>" new_post = Post(parent=parent_post, head=head, body=body, board=board) db.session.add(new_post) db.session.commit() Engine.associate_with_post(files, new_post) thread_post = get_thread_post(new_post) return redirect('/%s/thread/%s' % (board.short, thread_post.id))
class App(QtWidgets.QMainWindow): def __init__(self): super(App, self).__init__() # Main timer self.timer = QTimer(self) # Restart function used to init environment self.restart(True) self.timer.stop() self.timer.timeout.connect(self.ui.mainCanvas.animate) self.timer.timeout.connect(self.ui.statsCanvas.animate) self.timer.timeout.connect(self.engine.update) self.timer.start(16) def restart(self, firstTime=False): self.timer.stop() if firstTime: self.ui = Ui() self.ui.setupUi(self) if firstTime: self.engine = Engine() else: # Update all parameters to correct self.engine.__init__(height=self.ui.heightValue.current, radius=self.ui.radiusValue.current, mass=self.ui.massValue.current, velocity=self.ui.velocityValue.current, k=self.ui.kValue.current) # Engine configuration self.ui.mainCanvas.setPaintCallback(self.engine.draw) self.ui.mainCanvas.setZoomCallback(self.engine.zoom) self.ui.mainCanvas.setDragCallback(self.engine.drag) # Plotter configuration if firstTime: self.plotter = PlotterEngine() else: self.plotter.__init__() self.ui.statsCanvas.setPaintCallback(self.plotter.draw) self.engine.setDataCallback(self.plotter.update) # Buttons configuration self.ui.pauseButton.setCallback(self.engine.start, 0) self.ui.pauseButton.setCallback(self.engine.stop, 1) self.ui.timeHigherButton.setCallback(self.engine.positiveAccelerate) self.ui.timeLowerButton.setCallback(self.engine.negativeAccelerate) self.ui.restartButton.setCallback(self.restart) # Quality/Performance realtime callback self.ui.qualityValue.setCallback(self.engine.setQuality) self.timer.start(16)
def test_checkForDraw(self): map_size = 3 e = Engine(map_size) e.game_map.promptMap() self.assertIs(e.checkForDraw(), False) for y in range(0, map_size): for x in range(0, map_size): e.game_map.setElement(x, y, 'o') e.game_map.promptMap() self.assertIs(e.checkForDraw(), True)
def run(self): logger\ .nl()\ .indented('Envd')\ .indented('2016, version 0.1a')\ .splitter()\ .info('Mode: ' + self._arguments.arg(['client', 'keeper', 'server'], 'client')) routes = { 'DELETE': [self._on_route_delete, 1], 'GET': [self._on_route_get, 1], 'INFO': [self._on_route_info, 0], 'PATCH': [self._on_route_patch, 1], 'POST': [self._on_route_post, 1], 'PUT': [self._on_route_put, 1] } def f_resp(env, start_response): route = routes.get(env['REQUEST_METHOD']) if route: try: path = env['PATH_INFO'][1:].split('/') if len(path) >= route[1]: code = '200 OK' data = route[0](env, *path) else: code = self._errors['BadArgumentError'] data = None except BaseException as e: if e.__class__.__name__ in self._errors: code = self._errors[e.__class__.__name__] else: code = '500 Internal Server Error' data = e.message if isinstance(e, Error) else None if self._arguments.debug: traceback.print_exc() else: code = self._errors['NotExistsError'] data = None start_response(code, [('Content-Type', 'application/json')]) return [json.dumps(data)] bind = self._arguments.arg('bind', const.BIND) port = int(self._arguments.arg(['p', 'port'], int(const.PORT))) self._engine = Engine(self._config)\ .set_storage_mode( self._arguments.arg(['client', 'keeper', 'server'], 'client') ) logger.warning('Server is up and running on: ' + bind + ':' + str(port)) WSGIServer((bind, port), f_resp, log=None).serve_forever()
def test_checkIfElementIsAccessible(self): e = Engine(4) self.assertIs(e.checkIfElementIsAccessible(1, 1), True) self.assertIs(e.checkIfElementIsAccessible(0, 0), True) self.assertIs(e.checkIfElementIsAccessible(50, 50), False) self.assertIs(e.checkIfElementIsAccessible(1, 59), False) self.assertIs(e.checkIfElementIsAccessible(39248, 2), False) self.assertIs(e.checkIfElementIsAccessible('', ''), False) self.assertIs(e.checkIfElementIsAccessible('zqmeofij', 'zoei'), False)
def restart(self, firstTime=False): self.timer.stop() if firstTime: self.ui = Ui() self.ui.setupUi(self) if firstTime: self.engine = Engine() else: # Update all parameters to correct self.engine.__init__(height=self.ui.heightValue.current, radius=self.ui.radiusValue.current, mass=self.ui.massValue.current, velocity=self.ui.velocityValue.current, k=self.ui.kValue.current) # Engine configuration self.ui.mainCanvas.setPaintCallback(self.engine.draw) self.ui.mainCanvas.setZoomCallback(self.engine.zoom) self.ui.mainCanvas.setDragCallback(self.engine.drag) # Plotter configuration if firstTime: self.plotter = PlotterEngine() else: self.plotter.__init__() self.ui.statsCanvas.setPaintCallback(self.plotter.draw) self.engine.setDataCallback(self.plotter.update) # Buttons configuration self.ui.pauseButton.setCallback(self.engine.start, 0) self.ui.pauseButton.setCallback(self.engine.stop, 1) self.ui.timeHigherButton.setCallback(self.engine.positiveAccelerate) self.ui.timeLowerButton.setCallback(self.engine.negativeAccelerate) self.ui.restartButton.setCallback(self.restart) # Quality/Performance realtime callback self.ui.qualityValue.setCallback(self.engine.setQuality) self.timer.start(16)
def upload_handle(board_short): filedata = None try: filetracker = Engine.upload_file(request.files, board_short) except Exception as exc: raise exc return jsonify({'Response': 'ERR'}) res = {'Response': 'OK', 'file': filetracker} return jsonify(res)
import sys from src.engine import Engine engine = Engine() def reply_uci(): sys.stdout.write("id name " + engine.name + " \n") sys.stdout.write("id author " + engine.author + " \n") sys.stdout.write("uciok \n") def reply_isready(): sys.stdout.write("readyok \n") def reply_quit(): sys.exit() def reply_position(arg: list): pos_type = arg[0] if pos_type == "startpos": fen_string = None moves = [] if len(arg) > 2: moves = arg[2:] engine.set_position(fen_string, moves) elif pos_type == "fen":
import pygame as pg import numpy as np import time import sys from src.engine import Engine if __name__ == "__main__": pg.init() height, width = 600, 1000 numbers = 50 eng = Engine(width, height) eng.initialization(numbers) pg.display.set_caption('Boids') screen = pg.display.set_mode((width, height)) bg = 25, 25, 25 screen.fill(bg) loop = True while (loop): screen.fill(bg) ev = pg.event.get() for event in ev: if (event.type == pg.QUIT): loop = False
from pyglet.window import Window from pyglet.window.key import KeyStateHandler from pyglet.app import run from pyglet.clock import schedule from src.engine import Engine from src.line import Line from src.vec2d import Vec2D from src.wall import Wall window = Window(**WINDOW_ARGS) keys = KeyStateHandler() window.push_handlers(keys) engine = Engine(window, keys) l, t, r, b = engine._top_down_bounds h = t - b w = r - l # engine.walls.extend( # [ # Wall(Vec2D(l + 50, t - 100), Vec2D(r - 50, t - 100), [100, 200, 200]), # Wall(Vec2D(l + 50, t - 100), Vec2D(l + 50, b + 100), [200, 0, 40]), # Wall(Vec2D(l + 100, b + 100), Vec2D(r - 50, b + 100), [50, 20, 100]), # Wall(Vec2D(r - 50, b + 100), Vec2D(r - 50, t - 150), [100, 100, 100]), # Wall(Vec2D(l + w / 2, t - h / 3), Vec2D(l + w / 2, b + h / 3), [255, 0, 0]), # Wall(Vec2D(l + w / 3, b + h / 2), Vec2D(r - w / 3, b + h / 2), [0, 255, 0]), # ] # ) engine.walls.extend([
def index_handle(): return render_template('index.html', boards=Engine.get_boards_dumped())
import argparse import os import shutil from src.engine import Engine from src.utils.util import load_log, mkdir_p if __name__== '__main__': parser = argparse.ArgumentParser() parser.add_argument('--config_path', default='', help="Path to a config") parser.add_argument('--tag', default='', help="tag to discern training instances") parser.add_argument('--train_dir', help="Path to a train dir") args = parser.parse_args() train_dir = mkdir_p(args.train_dir) train_dir_name = train_dir.split('/')[-1] log_name = train_dir_name log = load_log(log_name) shutil.copyfile(args.config_path, os.path.join(train_dir, "config.yml")) engine = Engine( mode='train', config_path=args.config_path, log=log, train_dir=train_dir) engine.train()
import logging import argparse from src.engine import Engine from src.paquet import Data_str logging.basicConfig( filename="trump.log", format='''%(asctime)s %(levelname)s %(filename)s %(funcName)s %(lineno)d %(message)s''', level=logging.INFO) parser = argparse.ArgumentParser() parser.add_argument("-p", nargs='?', dest='p', default=None, type=int) parser.add_argument("-d", nargs='?', dest='d') args = parser.parse_args() engine = Engine(ip='::', port=args.p, bootstrap=[ (int("6722a421aadb51bd", 16), ('2001:660:3301:9200::51c2:1b9b', 1212)), ], data=[Data_str(args.d)] if args.d else []) engine.start()
import argparse from src.engine import Engine if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--config', default='default.yml', help='config name') parser.add_argument('--tag', default='', help='tag to discern evaluation instances') args = parser.parse_args() engine = Engine(config_name=args.config, tag=args.tag) engine.evaluate()
import os from src.engine import Engine os.environ["LINES"] = "30" os.environ["COLUMNS"] = "100" if __name__ == "__main__": engine = Engine() engine.run()
import argparse import torch from src.engine import Engine if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--config', default='resnet18', help="Config name") parser.add_argument('--tag', default='', help="tag to discern training instances") args = parser.parse_args() engine = Engine(mode='train', config_name=args.config, tag=args.tag) engine.train()
if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--config_path', default='', help="Path to a config") parser.add_argument('--tag', default='', help="tag to discern evaluation instances") parser.add_argument('--checkpoint_dir', default='', help='directory where checkpoints are') args = parser.parse_args() eval_dir = mkdir_p(os.path.join(args.checkpoint_dir, 'eval_' + args.tag)) eval_dir_name = '/'.join(eval_dir.split('/')[-2:]) log_name = eval_dir_name log = load_log(log_name) if not args.config_path: args.config_path = os.path.join(args.checkpoint_dir, 'config.yml') log.warning('config_path is not given: use [%s] as default.', args.config_path) shutil.copyfile(args.config_path, os.path.join(eval_dir, 'config.yml')) engine = Engine(mode='eval', config_path=args.config_path, log=log, train_dir=args.checkpoint_dir, eval_dir=eval_dir) engine.evaluate()
def main(): game = Engine(PlayState()) game.start()
import argparse import torch from src.engine import Engine if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--config', default='resnet18', help="Config name") parser.add_argument('--tag', default='', help="tag to discern evaluation instances") args = parser.parse_args() engine = Engine(mode='eval', config_name=args.config, tag=args.tag) engine.evaluate()