Beispiel #1
0
    def __init__(self, ev_manager: EventManager, model: GameEngine):
        '''
        This function is called when the Controller is created.
        For more specific objects related to a game instance
            , they should be initialized in Controller.initialize()
        '''
        self.ev_manager = ev_manager
        ev_manager.register_listener(self)

        self.model = model
    def __init__(self, ev_manager: EventManager, AI_names: list):
        '''
        This function is called when the GameEngine is created.
        For more specific objects related to a game instance
            , they should be initialized in GameEngine.initialize()
        '''
        self.ev_manager = ev_manager
        ev_manager.register_listener(self)

        self.state_machine = StateMachine()
        self.AI_names = AI_names
        while len(self.AI_names) < 4:
            self.AI_names.append("m")
        self.check_probability()
Beispiel #3
0
    def run(self):
        try:
            EventManager.i().emitAppStart(self)
            self.startLogger()
            self.runGui()
            self.stopLogger()
            EventManager.i().emitAppQuit(self, "app shutdown")

        except KeyboardInterrupt:
            lTime = time.gmtime()
            EventManager.i().emitAppQuit(self, "user_interupt")
        except:
            EventManager.i().emitAppQuit(self, "unexpected_end")
            raise
Beispiel #4
0
 def atexit_handler(self):
     EventManager.i().emitAppQuit(EventManager.EVT_APP_QUIT, 'at_exit')
Beispiel #5
0
 def __init__(self):
     self._store = Sqlite(
         os.path.join(os.path.expanduser("~"), '.PyTime', "user_test." + pwd.getpwuid(os.getuid())[0] + ".sqlite"))
     self._eventSource = Mate.Mate()
     self._gui = Gui.Mate.Mate()
     self._listener = PyTimeController.Listener(self._store, self._gui)
     EventManager.i().register(EventManager.EVT_SCREEN_LOCK, self._listener)
     EventManager.i().register(EventManager.EVT_SCREEN_UNLOCK, self._listener)
     EventManager.i().register(EventManager.EVT_APP_QUIT, self._listener)
     EventManager.i().register(EventManager.EVT_SCREEN_EXIT, self._listener)
     EventManager.i().register(EventManager.EVT_APP_REQUEST_LOG, self._listener)
     EventManager.i().register(EventManager.EVT_APP_START, self._listener)
     atexit.register(self.atexit_handler)
Beispiel #6
0
 def onQuitClick(self, widget, data=None):
     EventManager.i().emitAppQuit(self, "quit click")
     gtk.main_quit()
Beispiel #7
0
 def onWindowDestory(self, widget, data=None):
     EventManager.i().emitAppQuit(self, "window destroy")
     gtk.main_quit()
Beispiel #8
0
 def onQuit(self, widget):
     gtk.main_quit()
     EventManager.i().emitAppQuit(self, "GUI: user request")
Beispiel #9
0
 def logStop(self, widget):
     EventManager.i().emitScreenUnlock('test unlock')
Beispiel #10
0
 def logStart(self, widget):
     EventManager.i().emitAppRequestEvent(self,
                                          {'event': 'started', 'request': 'log.start', 'reason': 'manual entry',
                                           'time': time.gmtime()})
Beispiel #11
0
 def __init__(self, harbor_size):
     self.math = Math()
     self.events_iter = EventManager()
     self.dock_manager = Dock_Harbor_Manager(3)
     self.tug = Tug()
Beispiel #12
0
class Main:
    
    def __init__(self, harbor_size):
        self.math = Math()
        self.events_iter = EventManager()
        self.dock_manager = Dock_Harbor_Manager(3)
        self.tug = Tug()
        
        
        
    def run(self):
        
        currentT = 0
        finalT = 43800.0
        self.events_iter.add_events(events['ARRIVE'], self.math.ExpDistribution(8.0))
        i = 0
        while currentT < finalT:
            
            event = self.events_iter.next_event()
            #print(event.get_type())
            currentT = event.get_time()
            
            #Arriba un carguero al puerto
            if event.get_type() is 1:
                ship = Ship()
                self.dock_manager.register_ship_arrive(ship, currentT)
                print("En el puerto un barco de tamano ", ship.size, "Time :", currentT)
                if self.tug.get_status() is 1:
                    print("Llevando el barco para el muelle", "Time :", currentT)
                    self.tug.move_ship(ship)    
                    self.tug.set_status(5)
                    self.events_iter.add_events(events['TO_HARBOR'] , currentT + self.math.ExpDistribution(2.0) ,ship)
                    
                    
                else:
                    print("el remolcador esta ocupado, llevar el barco a la cola" , "Time :", currentT)
                    self.dock_manager.enqueue_ship_port(ship)
               
                self.events_iter.add_events(events['ARRIVE'], currentT +  self.math.ExpDistribution(8.0))
                continue; 
            
            #Un carguero termina de cargar
            if event.get_type() is 2:
                ship_finish = event.get_ship()
               # i+=1
                print("El carguero termino de cargar" , "Time :", currentT)
                if self.tug.get_status() is 2:
                    #sacando carguero de la lista de muelles 
                #    i-=1 
                    
                    print("el carguero es llevado al puerto" , "Time :", currentT)
                    self.tug.move_ship(ship)
                    self.tug.set_status(4) 
                    self.events_iter.add_events(events['TO_PORT'], currentT +  self.math.ExpDistribution(1))
                
                
                
                else:
                    #El carguero se pone en la cola del muelle
                    print("El carguero se pone en la cola del muelle", "Time :", currentT)
                    self.dock_manager.register_harbor_finish(ship_finish, currentT)
                    self.dock_manager.enqueue_ship_harbor(ship_finish)
                continue;
            #el remolcador regresa solo para el puerto
            if event.get_type() is 3:
                
                if self.dock_manager.any_ship_port_waiting():
                    
                    print("Sacando barco de la cola del puerto", "Time :", currentT)
                    ship = self.dock_manager.dequeue_ship_port()
                    self.tug.move_ship(ship)
                    self.tug.set_status(5)
                    
                    self.events_iter.add_events(events['TO_HARBOR'], currentT + self.math.ExpDistribution(2), ship)
                    
                    
                    
                else:
                    print("El remolcador se pone en modo espera", "Time :", currentT)
                    self.tug.set_status(1)
                continue;
            #el remolcador lleva un carguero al puerto
            if event.get_type() is 4:
                self.dock_manager.register_ship_leave(self.tug.get_ship(), currentT)
                print("sacar el carguero de la cola del puerto", "Time :", currentT)
                
                if self.dock_manager.any_ship_port_waiting():
                    ship = self.dock_manager.dequeue_ship_port()
                    self.tug.move_ship(ship)
                    self.tug.set_status(5)
                    print("Llevando el carguero para el muelle", "Time :", currentT)
                    self.events_iter.add_events(events['TO_HARBOR'],currentT + self.math.ExpDistribution(2), ship)
                else:
                    #deja el carguero y se pone a esperar
                    print("El remolcador de pone en espera en el puerto" , "Time :", currentT)
                    self.tug.leave_ship()
                    self.tug.set_status(1)
                
                continue;
            #el remolcador lleva un carguero al muelle
            if event.get_type() is 5:
                
                print("El remolcador traer un carguero al muelle")
                ship_harbor = self.tug.get_ship()
                self.dock_manager.enter_ship_harbor(ship_harbor)
                
                
                if self.dock_manager.any_ship_harbor_waiting():
                    print("El remolcador se lleva un barco al puerto", "Time :", currentT)
                    ship = self.dock_manager.dequeue_ship_harbor()
                    self.tug.move_ship(ship)
                    self.dock_manager.register_harbor_leave(ship, currentT)
                    
                    self.tug.set_status(4)
                    self.events_iter.add_events(events['TO_PORT'],currentT + self.math.ExpDistribution(1))
                elif self.dock_manager.any_harbor_free():
                    #el remolcador se va para el puerto solo
                    print("El remolcador se dirige al puerto solo")
                    self.tug.set_status(3)
                    self.tug.leave_ship()
                    self.events_iter.add_events(events['MOVE_ALONE'], currentT + self.math.ExpDistribution(0.25))
                else:
                    #se pone a esperar q halla un hueco libre
                    #print("ENTROOOOOOOOOOOOOOO")
                    #if self.dock_manager.any_harbor_free() :
                    #    i+=1
                    print("El remolcador se pone en espera en el muelle")
                    self.tug.leave_ship()
                    self.tug.set_status(2)
                
                #Caso ahora para generar el tiemppo de carga del barco
                if ship_harbor.get_size() is 1:
                    self.events_iter.add_events(events['LOADING'], currentT + self.math.NormalDistribution(9,1), ship_harbor)
                    continue;
                if ship_harbor.get_size() is 2:
                    self.events_iter.add_events(events['LOADING'], currentT + self.math.NormalDistribution(12,2), ship_harbor)    
                    continue;
                if ship_harbor.get_size() is 3:
                    self.events_iter.add_events(events['LOADING'], currentT + self.math.NormalDistribution(18,3), ship_harbor)
                    continue;
                continue;
        print(i)
        print(self.dock_manager.mean_total())
        return self.dock_manager.mean_harbor()