def game(): """ create or join a game """ data = json.loads(request.data) battle_tag = data.get('battle_tag') user_id = data.get('user_id') if user_id is None: raise InvalidUsage("user_id required", status_code=401) if battle_tag is not None: game = GameHandler().join_game(user_id, battle_tag) return json.dumps(GameHandler.to_dict(game)) else: game = GameHandler().new_game(user_id) return json.dumps(GameHandler.to_dict(game))
def __init__(self, matrix): self.matrix = matrix self.frame = np.zeros((20, 35, 3), np.uint8) self.points = { "Settings": Settings(self.matrix, self), "Games": GameHandler(self.matrix, self), "Ambient": AmbientHandler(self.matrix, self) } self.background_app_labels = background_apps_conf.background_apps self.background_apps = [] for app_label in self.background_app_labels: app = app_label(self.matrix, self) app.start() self.background_apps.append(app) self.background = False self.active_background_app = None self.keys = self.points.keys() self.index = 0 self.active = self self.keys_down = self.matrix.get_keys() self.last_keys_down = self.keys_down self.active_paused = False self.back_time = time.time() self.standby_timeout = 20
def login(): data = json.loads(request.data) username = data.get('username') password = data.get('password') user = UserHandler.to_dict(UserHandler().log_user(username, password)) history = GameHandler().get_player_history(user['user_id']) user['history'] = history return json.dumps(user)
def playGame(): game_controller = GameController() game_controller.start_browser() game_controller.startup_game() game_handler = GameHandler(game_controller) # game_handler.play_game() parser = argparse.ArgumentParser(description='Description of your program') parser.add_argument('-m', '--mode', help='Train / Run', required=True) args = vars(parser.parse_args()) game = Model(game_handler) game.playGame(args)
def get_user(): user_id = request.args.get('user_id') if not user_id: UserHandler().get_all_users() user = UserHandler().get_user(user_id) if not user: raise InvalidUsage("User %s not found" % user_id, status_code=404) user = UserHandler.to_dict(user) history = GameHandler().get_player_history(user_id) user['history'] = history return json.dumps(user)
def post_scene(): """ Send user choice on this scene """ data = json.loads(request.data) user_id = data.get('user_id') game_id = data.get('game_id') choice = data.get('choice') try: GameHandler().update_user_answer(user_id, game_id, choice) except BadAnswerException as e: raise InvalidUsage(str(e), status_code=400) except GameEndedException as e: raise InvalidUsage(str(e), status_code=404) return json.dumps({})
def enter_game(self, newbie): p = player.player_database.find_full(self.username) if p is None: self.send("Cannot find player!") self.protocol.drop_connection() return if p.logged_in: p.protocol.drop_connection() p.protocol.handler.hung_up() p.protocol.clear_handlers() p.newbie = newbie p.logged_in = True p.protocol = self.protocol p.protocol.remove_handler() p.protocol.add_handler(GameHandler(self.protocol, p))
action = np.random.randint(0, 4) else: # choose best action from Q(s,a) values action = np.argmax(qval) # Take action, observe new state S' score = game.play_move(state, action, randomState) # Observe reward reward = game.get_reward(state, score) # Get max_Q(S',a) newQ = model.predict(state.reshape(1, 16), batch_size=1) maxQ = np.max(newQ) y = np.zeros((1, 4)) y[:] = qval[:] if score == 0: update = np.exp(c) else: update = score + gamma * maxQ y[0][action] = update # target output model.fit(state.reshape(1, 16), y, batch_size=1, nb_epoch=1, verbose=0) if score == 0: status = 0 if i % 10 == 0: print("Game #: %s Score: %s" % (i, c)) epsilon -= 1 / epochs randomState = np.random.RandomState(0) GameHandler(size=4, player=AIPlayer(model), state=randomState)
""" bbg_main.py The main file for Boss Battle Game. Run this to play the game. """ from io_handler import * from game_handler import GameHandler if __name__ == '__main__': io = IOHandler() game = GameHandler() while True: instruction = io.getInput() game.playGame(instruction)
def setup(node, data): gfx = GameGfx(node, data) gui = GuiManager(data, gfx) handler = GameHandler(gfx, gui, data)
#! /usr/bin/env python # -*- coding: utf-8 -*- # python imports import os import sys # chillin imports from chillin_server import GameServer, Config # project imports from game_handler import GameHandler config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "gamecfg.json") if len(sys.argv) > 1: config_path = sys.argv[1] app = GameServer(config_path) app.register_game_handler(GameHandler(Config.config)) app.run()
import logging import os import sys from game_handler import GameHandler log = logging.getLogger(__name__) logging.basicConfig(stream=sys.stdout, level=logging.INFO) parser = argparse.ArgumentParser(description='Gather user anonymous feedback.') parser.add_argument('--debug', '-d', dest='debug', action='store_true', help='Debug mode') parser.add_argument('--simple', '-s', dest='simple', action='store_true', help='Simple mode using y only, less precise') if __name__ == "__main__": args = parser.parse_args() if args.debug: if not os.path.exists("./debug"): os.makedirs("./debug") logging.getLogger().setLevel(logging.DEBUG) GameHandler(debug=args.debug, simple=args.simple).play()
from game_handler import GameHandler GameHandler(size=4)
def game_details(request, game_id): handler = GameHandler() template_context = handler.get_game_details(request.user, game_id) return render_to_response("game_details.html", template_context)
def create_game(request, opponent_fb_id): handler = GameHandler() game_id = handler.create_game(request.user, request.access_token, opponent_fb_id) return HttpResponseRedirect(reverse('app.views.game_details', args=(game_id,)))
def get_scene(): user_id = request.args.get('user_id') game_id = request.args.get('game_id') return json.dumps(GameHandler().get_scene(user_id, game_id))
from content_handler import ContentHandler from game_handler import GameHandler, BadAnswerException, GameEndedException from user_handler import UserHandler log = logging.getLogger("hackaton-vidfr") parser = argparse.ArgumentParser(description='Show transversal xml properties.') parser.add_argument('--debug', '-d', dest='debug', action='store_true', help='Debug mode') app = Flask(__name__) app.secret_key = "test" GameHandler().init_db() UserHandler().init_db() class InvalidUsage(Exception): status_code = 500 def __init__(self, message, status_code=None, payload=None): Exception.__init__(self) self.message = message if status_code is not None: self.status_code = status_code self.payload = payload def to_dict(self): rv = dict(self.payload or ())