Exemplo n.º 1
0
def main():
    terminal.open()
    terminal.refresh()

    controller = Controller()
    player = Player(controller)
    hunger = Hunger(player)

    walls = [
        Wall(WALL_X, WALL_Y[0]),
        Wall(WALL_X, WALL_Y[1]),
        Wall(WALL_X, WALL_Y[2]),
    ]

    food_list = [
        Food(FOOD_X[0], FOOD_Y[0]),
        Food(FOOD_X[1], FOOD_Y[1]),
        Food(FOOD_X[2], FOOD_Y[2]),
    ]

    entities = [
        player,
        hunger,
    ]

    entities.extend(food_list)
    entities.extend(walls)

    updater = Updater(entities)
    collider = Collider(entities)
    render = Render(entities)

    while True:

        controller.update()

        if controller.is_exit:
            break

        if player.is_game_over:
            render_game_over()
        else:
            terminal.refresh()

            updater.update()
            collider.update()
            render.update()

    terminal.close()
Exemplo n.º 2
0
def run():
    parser = optparse.OptionParser()
    parser.add_option('-p', '--parked', dest='parked', default=False, action='store_true')
    parser.add_option('-d', '--display', dest='display', default=True, action='store_true')
    parser.add_option('-k', '--numCars', type='int', dest='numCars', default=3)
    parser.add_option('-l', '--layout', dest='layout', default='small')
    parser.add_option('-s', '--speed', dest='speed', default='slow')
    parser.add_option('-f', '--fixedSeed', dest='fixedSeed', default=False, action='store_true')
    parser.add_option('-a', '--auto', dest='auto', default=False, action='store_true')
    (options, _) = parser.parse_args()

    Const.WORLD = options.layout
    Const.CARS_PARKED = options.parked
    Const.SHOW_CARS = options.display
    Const.NUM_AGENTS = options.numCars
    Const.INFERENCE = 'none'
    Const.AUTO = options.auto
    Const.SECONDS_PER_HEARTBEAT = 0.001

    signal.signal(signal.SIGINT, signal_handler)

    # Fix the random seed
    if options.fixedSeed: random.seed('driverlessCar')

    learner = Learner()

    iterations = 0
    numIter = Const.TRAIN_MAX_AGENTS * Const.TRAIN_PER_AGENT_COUNT
    for i in range(1, Const.TRAIN_MAX_AGENTS + 1):
        for j in range(Const.TRAIN_PER_AGENT_COUNT):
            percentDone = int(iterations * 100.0 / numIter)
            print str(percentDone) + '% done'
            Const.NUM_AGENTS = i
            quit = Controller().learn(learner)
            if quit:
                Display.endGraphics()
                return
            iterations += 1

    transFileName = Const.WORLD + 'TransProb.p'
    transFilePath = os.path.join('learned', transFileName)
    with open(transFilePath, 'wb') as transFile:
        learner.saveTransitionProb(transFile)
        print 'saved file: ' + transFilePath
    Display.endGraphics()
Exemplo n.º 3
0
    
    Const.WORLD = options.layout
    Const.CARS_PARKED = options.parked
    Const.SHOW_CARS = options.display
    Const.NUM_AGENTS = options.numCars
    Const.INFERENCE = options.inference
    Const.SPEED = options.speed
    Const.HEARTBEATS_PER_SECOND = Const.HEARTBEAT_DICT[Const.SIM_SPEED]
    Const.SECONDS_PER_HEARTBEAT = 1.0 / Const.HEARTBEATS_PER_SECOND
    Const.AUTO = options.auto
    
    signal.signal(signal.SIGINT, signal_handler)

    # Fix the random seed
    if options.fixedSeed: random.seed('driverlessCar')
    QLearner = QLearningAlgorithm([0, 1])
    winCount = 0
    for i in range(100):
        controller = Controller(QLearner)
        (quit, isWin) = controller.drive()
        if not quit:
            controller.freezeFrame()
        print 'closing...'
        Display.endGraphics()
        if isWin:
            winCount += 1
        if i % 10 == 0:
            print 'iteration={0}'.format(i)
            print QLearner.weights
    print 'winCount={0}'.format(winCount)
Exemplo n.º 4
0
    Const.WORLD = options.layout
    Const.CARS_PARKED = options.parked
    Const.SHOW_CARS = options.display
    Const.NUM_AGENTS = options.numCars
    Const.INFERENCE = options.inference
    Const.SPEED = options.speed
    Const.HEARTBEATS_PER_SECOND = Const.HEARTBEAT_DICT[Const.SIM_SPEED]
    Const.SECONDS_PER_HEARTBEAT = 1.0 / Const.HEARTBEATS_PER_SECOND
    Const.AUTO = options.auto

    signal.signal(signal.SIGINT, signal_handler)

    # Fix the random seed
    if options.fixedSeed: random.seed('driverlessCar')
    QLearner = QLearningAlgorithm([0, 1])
    winCount = 0
    for i in range(100):
        controller = Controller(QLearner)
        (quit, isWin) = controller.drive()
        if not quit:
            controller.freezeFrame()
        print 'closing...'
        Display.endGraphics()
        if isWin:
            winCount += 1
        if i % 10 == 0:
            print 'iteration={0}'.format(i)
            print QLearner.weights
    print 'winCount={0}'.format(winCount)
Exemplo n.º 5
0
    parser.add_option('-k', '--numCars', type='int', dest='numCars', default=3)
    parser.add_option('-l', '--layout', dest='layout', default='small')
    parser.add_option('-i', '--inference', dest='inference', default='exactInference')
    parser.add_option('-s', '--speed', dest='speed', default='verySlow')
    parser.add_option('-a', '--auto', dest='auto', default=False, action='store_true')
    parser.add_option('-f', '--fixedSeed', dest='fixedSeed', default=False, action='store_true')
    (options, _) = parser.parse_args()
    
    Const.WORLD = options.layout
    Const.CARS_PARKED = options.parked
    Const.SHOW_CARS = options.display
    Const.NUM_AGENTS = options.numCars
    Const.INFERENCE = options.inference
    Const.SPEED = options.speed
    Const.HEARTBEATS_PER_SECOND = Const.HEARTBEAT_DICT[Const.SIM_SPEED]
    Const.SECONDS_PER_HEARTBEAT = 1.0 / Const.HEARTBEATS_PER_SECOND
    Const.AUTO = options.auto
    
    signal.signal(signal.SIGINT, signal_handler)

    # Fix the random seed
    if options.fixedSeed: random.seed('driverlessCar')

    controller = Controller()
    quit = controller.drive()
    if not quit:
        controller.freezeFrame()
    
    print 'closing...'
    Display.endGraphics()