def click(x, y): global MENU global MODE global COUNT_WIN global COUNT_LOST if MODE == 'menu': for el in MENU: if el[1] + el[3] > x > el[1] and el[2] + el[4] > y > el[2]: if el[0] == 'START GAME': MODE = 'game' newGameInit(GAME_STATE) elif el[0] == 'EXIT': MODE = 'exit' elif el[0] == 'RECORD': message(f'WIN: {COUNT_WIN}', (WIDTH_WIN - 200) / 2, HEIGHT_WIN // 2, 200) MODE = 'message' return elif MODE == 'game': widKl = WIDTH // 3 index = 0 for i in range(3): for j in range(3): if widKl * j + widKl > x - X_POS > widKl * j and widKl * i + widKl > y - Y_POS > widKl * i: if GAME_STATE[index] is None: GAME_STATE[index] = 'x' win = get_winner(GAME_STATE) if win == 'x_win': COUNT_WIN += 1 draw_state(GAME_STATE, X_POS, Y_POS, WIDTH) canvas.draw() time.sleep(1) message('YOU WIN', (WIDTH_WIN - 200) / 2, HEIGHT_WIN // 2, 200) MODE = 'message' return elif win == 'draw': message('DRAW', (WIDTH_WIN - 200) / 2, HEIGHT_WIN // 2, 200) MODE = 'message' return tmp = get_bot_move(GAME_STATE) if tmp is not None: GAME_STATE[tmp] = 'o' tmp = get_winner(GAME_STATE) if tmp == 'o_win': COUNT_LOST += 1 draw_state(GAME_STATE, X_POS, Y_POS, WIDTH) canvas.draw() time.sleep(1) message('YOU LOST', (WIDTH_WIN - 200) / 2, HEIGHT_WIN // 2, 200) MODE = 'message' return elif tmp == 'draw': message('DRAW', (WIDTH_WIN - 200) / 2, HEIGHT_WIN // 2, 200) MODE = 'message' return index += 1
def play(env, agent): """ 本番テスト """ best_episode = [] max_R = 0 for i in range(10): obs = env.reset() done = False R = 0 t = 0 pos_tmp = [] while not done and t < 200: # env.render() action = agent.act(obs) obs, r, done, _ = env.step(action) R += r t += 1 pos_tmp.append(env.car.get_vec()) print('test episode:', i, 'R:', R) agent.stop_episode() if R > max_R: max_R = R best_episode = pos_tmp # 最良エピソードを描画する (pygame使用) import canvas canvas.draw(best_episode) print('Finish demo')
def my_click(x, y): colors = ["Pink", 'Lime', 'Red', "Blue", 'Crimson', 'Gold', 'RosyBrown'] a = enumerate(colors) for i in a: canvas.set_color(str(i[1])) b = range(15) canvas.circle(x, y, b[i[0]]) # canvas.fill_circle(x, y, 15) canvas.draw()
import canvas import datetime while True: data = datetime.datetime.now() data_str = data.strftime('%H:%M:%S') canvas.stroke_rect(70, 105, 200, 100) canvas.fill_text(data_str, 170, 160, font='Monospace', size=25, align="center") canvas.draw() canvas.clear()
def my_click(x, y): canvas.circle(x, y, 15) canvas.draw()
import canvas import random canvas = canvas.canvas(32, 24) while True: canvas.draw() canvas.pixel(random.randrange(0, 32), random.randrange(0, 24), random.randrange(0, 3))