def main(): # Give introduction to program and goal. introduction() # Get recognizer and microphone objects. r, mic = prepare_mic() # Instantiate empty graph object. g = Graphic() # Set dataset and filename values of graph object by choosing dataset. g = choose_dataset(g) # Run speech recognition and graphing in a streaming format. attentive = True while attentive: with mic as source: audio = get_audio(r, source) try: text = r.recognize(audio) print('You said: ' + text) except LookupError: print("Didn't get audio.") continue if text: terms = tokenize(text) attentive = is_attentive(terms) if not attentive: print 'Goodbye' return None g = update_graph(g, terms) g.make_gg_plot()
def run(): n = 5 width, height = 10, 10 model_file = 'current_policy.model' try: board = Board(width=width, height=height, n_in_row=n) game = Game(board) graphic = Graphic() # graphic.run() print(1111) # thread1 = threading.Thread(target=graphic.run, args=()) best_policy = PolicyValueNet(width, height, model_file='./model/' + model_file) mcts_player = MCTSPlayer(best_policy.policy_value_fn, c_puct=5, n_playout=1200) human = Human(graphic) # set start_player=0 for human first thread2 = threading.Thread(target=game.start_play, args=(human, mcts_player, graphic, 1, 1)) # game.start_play(human, mcts_player, graphic, start_player=0, is_shown=1) thread2.setDaemon(True) thread2.start() graphic.run() except KeyboardInterrupt: print('\n\rquit')
def __init__(self, memory): self.mode = 0 # Mode 0 = HBlank (VRAM accessible) # Mode 1 = VBlank (VRAM accessible) # Mode 2 = OAM used (OAM not accessible) # Mode 3 = OAM & VRAM used (OAM + VRAM not accessible) # Representation of modes on full cycle: # One full refresh should in theory take ~16.6 ms # because 60hz * 16.6ms = 1sec # # ____ 144 of these lineupdates # | | # 000233000233000233000233000233000233...111111111111 # |_| Takes 48.6 uS | | # | Takes 19 uS | | # || Takes 41 uS | | # |____| Takes 109 uS Takes 1ms_|__________| # A full screen refresh takes 70224 cycles. From these there are # 4560 Cycles reserved for VBlank(1). The remaining 65664 Cycles are # used for 144 line updates, each taking 456 cycles to complete. # Of these 456 cycles # Mode 0 takes 201-207 cycles # Mode 2 takes 77-83 cycles # Mode 3 takes 169-175 cycles # The vague cycle duration is because of instructions taking multiple cycles (1-6) # | lines | VBlank # (144 * 456) + 4560 = 70224 self.scrollX = 0 self.scrollY = 0 self.line = 0 self.lcdc = 0 self.cycles = 0 self.seconds = 0 self.tile_offset = 0 self.memory = memory self.set_tile_offset() self.window = Graphic() # self.tile_window = Graphic(height=128) self.window.show() self.window.clear(0x474741) # self.tile_window.clear(0x474741) self.window.update() # self.tile_window.update() self.palette = { 0: 0xffffff, 1: 0xaaaaaa, 2: 0x555555, 3: 0x000000, } self.pixels = {0: [], 1: [], 2: [], 3: []}
def __init__(self, cartridge): self.screen_cycles = int((4.194304 * 1e6 / 59.7) / 144) self.done = False self.all_cycles = 0 self.cartridge = cartridge self.register = Registers() self.stack = Stack() self.g = Graphic(160, 144) self.memory = Memory() self.gpu = Gpu(self.memory) self.codes = { 0x00: ("NOP", 1, 4, self.nop), 0x01: ("LD BC,d16", 3, 12, self.ld_bc_d16), 0x06: ("LD B,d8", 2, 8, self.ld_b_d8), 0x0e: ("LD C,d8", 2, 8, self.ld_c_d8), 0x11: ("LD DE,d16", 3, 12, self.ld_de_d16), 0x16: ("LD D,d8", 2, 8, self.ld_d_d8), 0x1a: ("LD A,(DE)", 1, 8, self.ld_a_de), 0x1e: ("LD E,d8", 2, 8, self.ld_e_d8), 0x21: ("LD HL,d16", 3, 12, self.ld_hl_d16), 0x22: ("LD (HL+),A", 1, 8, self.ld_hl_p_a), 0x2a: ("LD A,(HL+)", 1, 8, self.ld_a_hl_p), 0x2e: ("LD L,d8", 2, 8, self.ld_l_d8), 0x31: ("LD SP,d16", 3, 12, self.ld_sp_d16), 0x32: ("LD (HL-),A", 1, 8, self.ld_hl_m_a), 0x36: ("LD (HL),d8", 1, 8, self.ld_hl_d8), 0x3e: ("LD A,d8", 2, 8, self.ld_a_d8), 0x46: ("LD B,(HL)", 1, 8, self.ld_b_hl), 0x47: ("LD B,A", 1, 4, self.ld_b_a), 0x4f: ("LD C,A", 1, 4, self.ld_c_a), 0x56: ("LD D,(HL)", 1, 8, self.ld_d_hl), 0x57: ("LD D,A", 1, 4, self.ld_d_a), 0x5e: ("LD E,(HL)", 1, 8, self.ld_e_hl), 0x5f: ("LD E,A", 1, 4, self.load_e_a), 0x67: ("LD H,A", 1, 4, self.ld_h_a), 0x77: ("LD (HL),A", 1, 8, self.ld_hl_a), 0x78: ("LD A,B", 1, 4, self.ld_a_b), 0x79: ("LD A,C", 1, 4, self.ld_a_c), 0x7b: ("LD A,E", 1, 4, self.ld_a_e), 0x7c: ("LD A,H", 1, 4, self.ld_a_h), 0x7d: ("LD A,L", 1, 4, self.ld_a_l), 0x7e: ("LD A,(HL)", 1, 8, self.ld_a_hl), 0xe2: ("LD (C),A", 1, 8, self.ld_c_a), 0xea: ("LD (a16),A", 3, 16, self.ld_a16_a), 0xe0: ("LDH (a8),A", 2, 12, self.ldh_a8_a), 0xf0: ("LDH A,(a8)", 2, 12, self.ldh_a_a8), 0x04: ("INC B", 1, 4, self.inc_b), 0x0c: ("INC C", 1, 4, self.inc_c), 0x13: ("INC DE", 1, 8, self.inc_de), 0x23: ("INC HL", 1, 8, self.inc_hl), 0x24: ("INC H", 1, 4, self.inc_h), 0x05: ("DEC B", 1, 4, self.dec_b), 0x0b: ("DEC BC", 1, 8, self.dec_bc), 0x0d: ("DEC C", 1, 4, self.dec_c), 0x15: ("DEC D", 1, 4, self.dec_d), 0x1d: ("DEC E", 1, 4, self.dec_e), 0x3d: ("DEC A", 1, 4, self.dec_a), 0x18: ("JR r8", 2, 12, self.jr_r8), 0x20: ("JR NZ,r8", 2, 12, self.jr_nz_r8), 0x28: ("JR Z,r8", 2, 12, self.jr_z_r8), 0xc3: ("JP d16", 3, 16, self.jp_d16), 0xe9: ("JP (HL)", 1, 4, self.jp_hl), 0x17: ("RLA", 1, 4, self.rla), 0x19: ("ADD HL,DE", 1, 8, self.add_hl_de), 0x2f: ("CPL", 1, 4, self.cpl), 0x86: ("ADD A,(HL)", 1, 8, self.add_a_hl), 0x87: ("ADD A,A", 1, 8, self.add_a_a), 0x90: ("SUB B", 1, 4, self.sub_b), 0xa0: ("AND B", 1, 4, self.and_b), 0xa1: ("AND C", 1, 4, self.and_c), 0xa9: ("XOR C", 1, 4, self.xor_c), 0xaf: ("XOR A", 1, 4, self.xor_a), 0xb0: ("OR B", 1, 4, self.or_b), 0xb1: ("OR C", 1, 4, self.or_c), 0xe6: ("AND d8", 2, 8, self.and_d8), 0xbe: ("CP (HL)", 1, 8, self.cp_hl), 0xc1: ("POP BC", 1, 12, self.pop_bc), 0xc5: ("PUSH BC", 1, 16, self.push_bc), 0xc9: ("RET", 1, 16, self.ret), 0xd5: ("PUSH DE", 1, 16, self.push_de), 0xcd: ("CALL a16", 3, 24, self.call_a16), 0xd6: ("SUB d8", 2, 8, self.sub_d8), 0xe1: ("POP HL", 1, 12, self.pop_hl), 0xf3: ("DI", 1, 4, self.di), 0xfb: ("EI", 1, 4, self.ei), 0xfe: ("CP d8", 2, 8, self.cp_d8), 0xef: ("RST_28H", 1, 16, self.rst_28h), 0xff: ("RST_38H", 1, 16, self.rst_38h), 0xcb37: ("SWAP A", 2, 8, self.swap_a), 0xcb3f: ("SRL A", 2, 8, self.srl_a), 0xcb7c: ("BIT 7,H", 2, 8, self.cb_bit_7_h), 0xcb11: ("RL C", 2, 8, self.cb_rl_c) }
def main(): g = Graphic() game = Game(g)