示例#1
0
 def __init__(self,
              env: AbstractEnvironment = Environment(),
              _command_processors: List[AbstractCommandProcessor] = None):
     self.__env = env
     self.__command_processors: Dict[str, AbstractCommandProcessor] = {
         x.keyword: x
         for x in _command_processors or (command_processors +
                                          [HelpCommandProcessor()])
     }
示例#2
0
 def __init__(
     self,
     bot_controller: AbstractBotController = BotController.get_instance(),
     room_state: AbstractRoomState = RoomState.get_instance(),
     data_service: AbstractDataService = DataService(),
     env: AbstractEnvironment = Environment()):
     self.__bot_controller = bot_controller
     self.__room_state = room_state
     self.__data_service = data_service
     self.__env = env
示例#3
0
 def __init__(self,
              env: AbstractEnvironment = Environment(),
              web_socket_client: AbstractWebSocketClient = WebSocketClient.
              get_instance()):
     if BotController.__instance:
         raise Exception('Use get_instance() instead!')
     self.__env = env
     self.__web_socket_client = web_socket_client
     self.__current_track: Optional[dict] = None
     self.__doped: bool = False
     self.__noped: bool = False
     BotController.__instance = self
示例#4
0
文件: main.py 项目: qubard/flo-env
def eval_genomes(genomes, config):
    genome_seed = random.randrange(0, 99999999)
    print("Selected seed", genome_seed)
    for genome_id, genome in genomes:
        genome.fitness = 0
        fov = 100
        env = Environment(render=False,
                          max_projectiles=100,
                          seed=genome_seed,
                          scale=5,
                          fov_size=fov)
        net = neat.nn.FeedForwardNetwork.create(genome, config)

        while not env.finished:
            raster = np.reshape(env.raster_array, (fov * 2, fov * 2))

            # 40,000 = 200x200 needs to be reduced by 5x5 to size 1600 (40x40)
            raster = block_reduce(raster, block_size=(5, 5), func=np.mean)
            output = net.activate(raster.flatten())
            env.take_action(np.argmax(
                output))  # Take the action and update the game state (tick)
        genome.fitness = env.fitness
示例#5
0
from src.env import Environment

import matplotlib.pyplot as plt
import numpy as np
from skimage.measure import block_reduce

fov = 100
env = Environment(scale=5, fov_size=fov)
lasthash = None

while not env.finished:
    env.take_action(3)
    print(env.finished, env.age, env.fitness, env.hash)

    if env.hash != lasthash:
        lasthash = env.hash
        raster = np.reshape(env.raster_array, (fov * 2, fov * 2))

        # 40,000 = 200x200 needs to be reduced by 5x5 to size 1600 (40x40)
        raster = block_reduce(raster, block_size=(5, 5), func=np.mean)
        plt.imshow(raster, cmap='gray', interpolation='nearest')
        plt.show()
示例#6
0
文件: main.py 项目: jqbx-bot/bot
                                 'roomId': env.get_jqbx_room_id(),
                                 'user': get_bot_user(env)
                             }))

    def __on_message(message: WebSocketMessage) -> None:
        logger.info('Incoming Message', message.as_dict())
        try:
            handler = web_socket_message_handler_map.get(message.label, None)
            if handler:
                handler.handle(message)
        except Exception as e:
            logger.error(e)

    def __on_error(error: BaseException) -> None:
        logger.error(error)

    def __on_close() -> None:
        logger.info('Websocket connection CLOSED')

    while True:
        web_socket_client.register(__on_open, __on_message, __on_error,
                                   __on_close)
        was_keyboard_interrupt = not web_socket_client.run()
        if was_keyboard_interrupt:
            break
        logger.error(Exception('Websocket client stopped. Restarting.'))


if __name__ == '__main__':
    main(WebSocketClient.get_instance(), Environment(), Logger())
示例#7
0
文件: main3.py 项目: qubard/flo-env
from src.env import Environment

#env = Environment(render=True, scale=5, fov_size=100, keyboard=True)
#env.run()

fov = 100
env = Environment(scale=5,
                  max_projectiles=100,
                  fov_size=fov,
                  render=True,
                  keyboard=True)
env.run()

print(env.fitness)
# Do a 200x200 (fov_size = 100) field of view, but convert it into a bitmap which is 200x200/(10*10) = 400 (20x20)
# can be generated in O(N) time
示例#8
0
 def __init__(self, env: AbstractEnvironment = Environment()):
     self.__base_url = env.get_data_service_base_url()
     self.__room_id = env.get_jqbx_room_id()