def get_selfplay_data(self, n_rounds, epsilon=0.5, gamma=0.9): states = list() action_values = list() if self.verbose: starttime = time.time() print("Start self-play process with rounds [{0}]:".format(n_rounds)) for i in range(n_rounds): if self.verbose: print("{0}th self-play round...".format(i+1)) engine = GameEngine( state_shape=self.state_shape, ai=self.ai, verbose=self.verbose ) _states, _action_values = engine.start_selfplay(epsilon=epsilon, gamma=gamma) for i in range(len(_action_values)): states.append(_states[i]) action_values.append(_action_values[i]) if self.verbose: endtime = time.time() print("End of self-play process with data size [{0}] and cost time [{1:.1f}s].".format( len(action_values), (endtime - starttime))) #states = np.array(states) action_values = np.array(action_values) next_states = states[:-1] next_states.append(None) return states, action_values, next_states
def __init__(self, **kwargs): super().__init__(**kwargs) self.game = GameEngine() self.board_view = BoardView(self.game.get_svg_board(), parent=self) self.game.set_board_view(self.board_view) self.game.start() self.command = QLineEdit() layout = QGridLayout(self) layout.addWidget(self.board_view) layout.addWidget(self.command) # Signaling self.command.returnPressed.connect(self.execute_command) self.commands = dict( # Exit application. qq=self.quit, # Save current board state to svg. sb=self.save_board, # Halt auto play. q=self.game.halt, # Toggle edit mode. ee=self.game.toggle_edit_mode, # Check result. cc=(lambda: logger.info(self.game.board.result())), # Print legal moves. lm=(lambda: logger.info(', '.join( [str(move) for move in self.game.board.legal_moves]))), # Print available commands. hh=(lambda: logger.info('Commands: ' + ', '.join( list(self.commands.keys()) + list(self.game.commands.keys()))) ))
def main_function(): global SHARED_DATA ge = GameEngine() for frame in range(FRAMES_LIMIT): ge.set_params(NUM_OF_OBSTACLE, METHOD) ge.cycle() SHARED_DATA = ge.to_json() sleep(TIME_EPSILLON * GAME_SPEED)
def __init__(self): DirectObject.__init__(self) self.gameEngine = GameEngine() # If you press Escape @ the server window, the server will quit. self.accept("escape", self.quit) self.lastConnection = None self.serverClock = 0 self.lobbyWaitTime = 6 self.randomValue = {} self.playerCount = 0 self.listenStat = 1 self.listPkg = PyDatagram() self.clientInputList = PyDatagram() self.clientInputList.addUint16(SERVER_INPUT) self.clientInputList.addUint64(self.serverClock) self.clientsAlive = {} self.displayText = GameUI.createDisplayUI("Loading...") # Create network layer objects # Deals with the basic network stuff self.cManager = QueuedConnectionManager() # Listens for new connections and queue's them self.cListener = QueuedConnectionListener(self.cManager, 0) # Reads data send to the server self.cReader = QueuedConnectionReader(self.cManager, 0) # Writes / sends data to the client self.cWriter = ConnectionWriter(self.cManager, 0) # open a server socket on the given port. Args: (port,timeout) self.tcpSocket = self.cManager.openTCPServerRendezvous(PORT, 1) # Tell the listener to listen for new connections on this socket self.cListener.addConnection(self.tcpSocket) # Start Listener task taskMgr.add(self.listenTask, "serverListenTask", -40) # Start Read task taskMgr.add(self.readTask, "serverReadTask", -39)
def __init__(self, network): self.gameEngine = GameEngine() self.network = network self.lastConnection = None self.serverClock = 0 self.count_down_time = 0 self.client_received_list = [] self.listPkg = PyDatagram() self.clientInputList = PyDatagram() self.clientInputList.addUint16(SERVER_INPUT) self.clientInputList.addUint64(self.serverClock) self.clientsAlive = [] self.clientsDead = [] self.display_text = GameUI.createDisplayUI("Loading...") self.count = 0
bricks = [brick for brick in bricks if brick.is_alive()] # Change speed by accoriding to touches array change_ball_speed(touches) # Get the new position cursor compute_cursor(key_pressed) return ball, cursor, bricks, lifes # Use it to determine the main program, RESPECT THE SYNTAX if __name__ == '__main__': width_screen = 600 height_screen = 600 # Enable graphics engine engine = GameEngine(width_screen, height_screen) # Create ball ball = Ball(width_screen / 2, height_screen - 200) ball.dx = -6 ball.dy = -3 # Create cursor cursor = Cursor(width_screen / 2, height_screen - 30) # Create Bricks bricks = add_lines_brick(2, 3, width_screen) # Create lifes lifes = [ Life(5, height_screen - 100), Life(50, height_screen - 100), Life(100, height_screen - 100)
"""main runner file for our chess engine setup 13.11.2019 - @yashbonde""" import os import uuid import random import logging from flask import request, make_response from flask import Flask, jsonify from game import Player, GameEngine # make the app and run the server app = Flask(__name__) game = GameEngine() print("INIT GAME:", game) # neuraPlayer = Player() @app.route('/move', methods = ["POST"]) def make_move(): # # get payload data # payload = request.get_json() print("\n\n", request.args) # auth_token = payload["auth_token"] # game_id = payload['game_id'] # from_ = payload['from'] # to_ = payload['target'] # player_no = payload['player_no'] # board_fen = payload['board_fen'] # san = payload['san'] # this is the notation we would like to save}
from game import pg, Screen, GameObject, InterfaceObject, Player, GameEngine from game.assets import imgsetb, imgsety, maps, imgwall from game.constants import gspeed, gunity screen = Screen() background = pg.transform.scale(pg.image.load('assets/img/background.jpg'), (60 * gunity, 30 * gunity)) arena = InterfaceObject(screen, background) game = GameEngine(screen, arena, maps['eights']) game.add_player(imgsety, 1, -200, 0, [pg.K_w, pg.K_a, pg.K_s, pg.K_d]) winners = game.game_loop() print(winners)
if args.playai: print( "Play \"Five or More\" game by AI. Please close game in terminal after closing window (i.e, Press Ctrl+C)." ) from ai import AI from game import GameEngine ai = AI(state_shape=__default_state_shape__, verbose=verbose) if verbose: print("loading latest model: [{0}] ...".format(__filename__), end="") ai.load_nnet(__filename__) if verbose: print("load OK!") gameengine = GameEngine(state_shape=__default_state_shape__, ai=ai, verbose=verbose) gameengine.start_ai() if args.play: print( "Play \"Five or More\" game. Please close game in terminal after closing window (i.e, Press Ctrl+C)." ) from game import GameEngine gameengine = GameEngine(state_shape=__default_state_shape__, verbose=verbose) gameengine.start()
from game import GameEngine import init from log import end from ui.window import ClientWindow app = wx.App(False) # Parse command line options parser = argparse.ArgumentParser() parser.add_argument("--config-dir", help="An alternative configuration directory", default=".") args = parser.parse_args() # Load the user configuration engine = GameEngine(args.config_dir) engine.load() # Select the configured language lang = engine.settings.get_language() select(lang) # Create the client and ClientWindow window = ClientWindow(engine) world = window.world if world is not None: reactor.callLater(0, window.panel.CreateClient) reactor.registerWxApp(app) reactor.run(installSignalHandlers=0) end()
menu = MainMenu(screen) config = menu.menu_loop() while config['player_number'] != 0: n = config['player_number'] players = config['players'] sprites = players['sprites'] controls = players['controls'] orientations = config['map']['orientations'] positions = config['map']['positions'] if n > 0: background = pg.transform.scale( pg.image.load('assets/img/background.jpg'), (60 * gunity, 30 * gunity)) arena = InterfaceObject(screen, background) game = GameEngine(screen, arena, config['map']) for i in range(n): game.add_player(sprites[i], orientations[i], *positions[i], controls[i]) winners = game.game_loop() menu.ending_screen(winners) del game