Esempio n. 1
0
def main():
    cleanup_at_exit()
    pins = (11, 13, 15, 16)
    menu = Menu()
    screen = Screen(menu)
    interface = Button_Interface(pins) if is_pi() else Keys_Interface()
    lcd = LCD() if is_pi() else Mock_LCD()
    io = IO_Mgr(interface, screen, menu, lcd)
    io.listen()
Esempio n. 2
0
def start(player_turn=1):
    state = State()
    screen = Screen()
    agent = Agent()
    agent_turn = 3 - player_turn
    while not state.winner():
        screen.render(state)
        if state.turn == agent_turn:
            choice = agent.choice(state, agent_turn)
            try:
                state.move(choice)
            except ValueError:
                cprint('Invalid position, AI is broken!', RED)
                input()
                continue
        elif state.turn == player_turn:
            inp = input()
            if inp == '':
                continue
            inp = int(inp)
            if inp < 1 or inp > 9:
                cprint('Invalid position', RED)
                input()
                continue
            pos = map_move[inp]
            try:
                state.move(pos)
            except ValueError:
                cprint('Invalid position', RED)
                input()
                continue

    screen.render(state)
    winner = state.winner()

    if winner == -1:
        cprint(f'Tie!\n', YELLOW)
    else:
        cprint(f'Player {winner} wins!\n', GREEN)
Esempio n. 3
0
import pygame
from julia import Julia
from display import Screen
from threading import Thread

screen_width = 500
screen_height = 500
screen_running = True
show_axis = True

p_i, q_i = -0.904, 0.224

display = Screen(screen_width, screen_height)
julia = Julia(screen_width, screen_height, [
    display.bg_color, display.RED, display.WHITE, display.YELLOW,
    display.GREEN, display.BLUE
], p_i, q_i)
display.julia = julia
display.running = screen_running
MAIN_THREAD = Thread(target=display.run)
MAIN_THREAD.setDaemon(True)
MAIN_THREAD.start()


def update():
    display.draw_background(show_axis)
    julia.calculate()
    display.show_layer(julia.image)


def p(p):