Exemple #1
0
        def OnPaint(self, evt) : # triggerd from EVT_PAINT after glcanvas.Refresh from abstractimer
            wx.PaintDC(self.canvas) # prepare glcanvas for opengl drawing
            self.canvas.SetCurrent()
            if not self.init: self.initFrameRate()
            self.app.step() # call subclass step method
##            engine.step() # step all objects in stack
            engine.render() #self.fcount)
            self.app.render() #engine) # main application
            self.canvas.SwapBuffers()
Exemple #2
0
 def render(self):
     try:
         engine.render(self.data)
         self.render_error = None
     except Exception as error:
         if self.render_error != error.message:
             print("Unable to render, reason:")
             print(error)
             self.render_error = error.message
Exemple #3
0
def run(Q_table, tree, render, learn, playable):

    init(Q_table, tree, learn)

    #simulaton loop
    for i in range(20):

        actions = protagonist.get_possible_actions()
        str_actions = list()
        for i in range(0, len(actions)):
            a = actions[i]
            str_actions.append(str(protagonist.action_labels[a]))

        world.update()

        if render == True:
            e.render(1, world, str_actions)

        choice = None
        if playable == True:
            #input from human
            while True:
                choice = input()
                if choice == "x":
                    sys.exit()
                try:
                    choice = int(choice)
                    break
                except:
                    print("input is not an int")
        else:
            choice = protagonist.choose_action()

        state = protagonist.generate_state_key()

        protagonist.take_possible_action(choice)
        world.run_all_agents()

        if learn == True:
            protagonist.learn(state, choice)

        #when protagonist leaves pharma and has drugs or was refused drugs, then end siumlation
        if (protagonist.has_item("drugs") == True
                or protagonist.refused_sell == True) and choice == 23:
            break

    result = 0
    if protagonist.has_item("drugs"):
        if protagonist.stole == True:
            result = 1  # agent stole drugs
        else:
            result = 2  # agent baught drugs
    elif protagonist.refused_sell == True:
        result = 3  # no drugs becauase agent was refused by pharmacist

    return [result, protagonist.line_skipped, protagonist.Q_table]
Exemple #4
0
 def OnPaint(
     self, evt
 ):  # triggerd from EVT_PAINT after glcanvas.Refresh from abstractimer
     wx.PaintDC(self.canvas)  # prepare glcanvas for opengl drawing
     self.canvas.SetCurrent()
     if not self.init: self.initFrameRate()
     self.app.step()  # call subclass step method
     ##            engine.step() # step all objects in stack
     engine.render()  #self.fcount)
     self.app.render()  #engine) # main application
     self.canvas.SwapBuffers()
Exemple #5
0
        def mainWindowLoop(self) :
            self.running = 1
            self.app.start()
            while self.running :   # we are done with everything so enter the endless loop
                if self.events.deal() == -1 : break # break the loop to quit
                self.clock.tick(self.frameRate) # mantain framerate in fps                
##                engine.step()              # step all objects in stack
                self.app.step()                 # call subclass step method
                engine.render()
                self.app.render() #engine) # render in main application
                pygame.display.flip()
            self.app.end() # just before exiting
            engine.end()
            pygame.quit() # quiting
Exemple #6
0
 def mainWindowLoop(self):
     self.running = 1
     self.app.start()
     while self.running:  # we are done with everything so enter the endless loop
         if self.events.deal() == -1: break  # break the loop to quit
         self.clock.tick(self.frameRate)  # mantain framerate in fps
         ##                engine.step()              # step all objects in stack
         self.app.step()  # call subclass step method
         engine.render()
         self.app.render()  #engine) # render in main application
         pygame.display.flip()
     self.app.end()  # just before exiting
     engine.end()
     pygame.quit()  # quiting
Exemple #7
0
# Теперь можем несколько усложнить наше приложение
# сделаем так чтобы в коробке было несколько мячей

from engine import initialize, process_events, modify, render
from config import state

initialize(state)
while 1:
  process_events(state)
  modify(state)
  render(state)
Exemple #8
0
    world = engine.render_world(lines, 75)
    save_image(os.path.join(args.output_directory, 'world.png'), world)

    times = []

    cam_pos = np.array((0, 0))
    cam_angle = 0
    max_angle_jump = np.radians(10)

    data = np.empty((N_steps, 3 + cam_size))
    for i in range(N_steps):
        cam = Camera(cam_pos, cam_angle, cam_fov, cam_size)

        start_time = time.time()
        img = engine.render(lines, cam)
        times.append(time.time() - start_time)

        data[i, 0:2] = cam_pos
        data[i, 2] = cam_angle
        data[i, 3:] = img

        save_image(os.path.join(args.output_directory, 'im_%03d.png' % i), img)

        cam_angle += np.random.uniform(-max_angle_jump, max_angle_jump)

    np.savetxt(os.path.join(args.output_directory, 'data.txt'),
               data,
               header="x, y, theta, pixels (%d)" % cam_size)
    print("Scene render time (s) (Avg. Max. Min.): %0.4f %0.4f %0.4f" %
          (sum(times) / len(times), max(times), min(times)))
Exemple #9
0
def main():
    engine.render()
Exemple #10
0
 def render(self):
     self.app.step()
     engine.render()
     self.app.render()
Exemple #11
0
if __name__ == '__main__':
    import engine as en
    import random as rnd

    clean_board = en.new_board()

    en.render(clean_board)

    play_board = clean_board.copy()
    play_board = tuple(play_board)
    playing = 'O'
    game_mode = input(
        'Human or AI game?\n1) for Human\n2) for Human v2s AI\n3) for AI vs AI\n'
    )

    if game_mode == '1':

        player_1 = 3
        3

        player_2 = 'H'
        player_type = player_1
        waiting = player_2

        en.lets_play(play_board, playing, player_type, waiting)

    if game_mode == '2':
        ai_type = input('Choose AI type:\n1) for random\n2) for Pro\n')
        if ai_type == '1':
            ai_type = 'A'
        elif ai_type == '2':