def main():
    code = read_input(2020, 8)
    game_console = GameConsole.from_code(code)

    for i in range(len(game_console.instructions)):
        old_instruction = None
        game_console.reset()

        if isinstance(game_console.instructions[i], JmpInstruction):
            old_instruction = game_console.instructions[i]
            game_console.instructions[i] = NopInstruction(
                old_instruction.value)
        elif isinstance(game_console.instructions[i], NopInstruction):
            old_instruction = game_console.instructions[i]
            game_console.instructions[i] = JmpInstruction(
                old_instruction.value)

        game_console.run()

        if not game_console.infinite_loop:
            break

        if old_instruction is not None:
            game_console.instructions[i] = old_instruction

    print(game_console.acc)
Exemple #2
0
 def init(self):
     self.window = pygame.display.set_mode((640, 480))
     pygame.display.set_caption('Gnosis - Epiphany generator')
     self.screen = pygame.display.get_surface()
     pygame.font.init()
     pygame.mixer.init()
     self.debugfont = pygame.font.SysFont("Courier New", 9)
     self.show_states = False
     self.console = GameConsole(self.screen, self)
 def get_device(self, state, internet_status):
     return GameConsole(state, internet_status)
Exemple #4
0
class Game(Singleton):
    def __init__(self):
        Singleton.__init__(self)
        self.init()
        
    def init(self):
        self.window = pygame.display.set_mode((640, 480))
        pygame.display.set_caption('Gnosis - Epiphany generator')
        self.screen = pygame.display.get_surface()
        pygame.font.init()
        pygame.mixer.init()
        self.debugfont = pygame.font.SysFont("Courier New", 9)
        self.show_states = False
        self.console = GameConsole(self.screen, self)

    def input(self, events):
        
        for event in events:
            if event.type == QUIT:
                sys.exit(0)
            elif event.type == KEYUP:
                if event.key == 275:
                    pass
                if event.key == 276:
                    pass
                if event.key == 273:
                    pass
                if event.key == 274:
                    pass
                if event.key == 282:
                    #F1
                    self.console.set_active()

    def trans_neighbours(self, neigh, trans_rules):
        new_neigh = dict()
        for trans_rule in trans_rules:
            if self.match_neighbours(neigh, trans_rule[0]):
                for (key, value) in trans_rule[1].items():
                    new_neigh[key]= value
                break
        return new_neigh
    
    def match_neighbours(self, neigh1, neigh2):
        set1 = set(neigh1.items())
        set2 = set(neigh2.items())
        return set2.issubset(set1)

    def start(self):
        level = Level()
        level.init()
        (entities, trans) = parse_gsl_file(Config.data_path+'/testfile.gsl')
        
        
#        parse_emdl_file(entities, Config.data_path+'/map/level10.map', level)
        
        
        while True:
            self.console.process_input()
            self.input(pygame.event.get())
            self.screen.fill((0, 0, 0))
            pygame.time.wait(100)
            level.update_on_events()
            level.update()
            
            level.draw(self.screen)
            
            if self.show_states == True:
                level.draw_debug(self.screen)
                
            self.console.draw()    


            #self.screen.blit(surface, (0, 0))
            pygame.display.flip()

    def toggle_states(self):
        self.show_states = not self.show_states
Exemple #5
0
def main():
    code = read_input(2020, 8)
    game_console = GameConsole.from_code(code)
    game_console.run()
    print(game_console.acc)