Пример #1
0
def main(argv):
    args = parse_args(argv)

    if args.browser == 'firefox':
        from ffctrl import FirefoxDebuggerControl
        if args.port is None:
            args.port = 32000
        ctrl = FirefoxDebuggerControl(args.port)
    elif args.browser == 'firefox-rc':
        from ffctrl import FirefoxRemoteControl
        if args.port is None:
            args.port = 32000
        ctrl = FirefoxRemoteControl(args.port)
    elif args.browser == 'chrome':
        from chromectrl import ChromeDebuggerControl
        if args.port is None:
            args.port = 9222
        ctrl = ChromeDebuggerControl(args.port)

    if args.ctrlmode == 'keyboard':
        from gamectrl import Keyboard2048Control
        gamectrl = Keyboard2048Control(ctrl)
    elif args.ctrlmode == 'fast':
        from gamectrl import Fast2048Control
        gamectrl = Fast2048Control(ctrl)
    elif args.ctrlmode == 'hybrid':
        from gamectrl import Hybrid2048Control
        gamectrl = Hybrid2048Control(ctrl)

    if gamectrl.get_status() == 'ended':
        gamectrl.restart_game()

    play_game(gamectrl)
Пример #2
0
def main(argv):
    args = parse_args(argv)

    if args.browser == 'firefox':
        from ffctrl import FirefoxRemoteControl
        if args.port is None:
            args.port = 32000
        ctrl = FirefoxRemoteControl(args.port)
    elif args.browser == 'chrome':
        from chromectrl import ChromeDebuggerControl
        if args.port is None:
            args.port = 9222
        ctrl = ChromeDebuggerControl(args.port)

    if args.ctrlmode == 'keyboard':
        from gamectrl import Keyboard2048Control
        gamectrl = Keyboard2048Control(ctrl)
    elif args.ctrlmode == 'fast':
        from gamectrl import Fast2048Control
        gamectrl = Fast2048Control(ctrl)
    elif args.ctrlmode == 'hybrid':
        from gamectrl import Hybrid2048Control
        gamectrl = Hybrid2048Control(ctrl)

    if gamectrl.get_status() == 'ended':
        gamectrl.restart_game()

    '''========================================================================================
        Start playing 2048
    ========================================================================================'''

    for i in range(games_to_be_played):
        if log_each_game_as_csv:
            '''Log Each Game'''
            file_name = 'log/' + timestamp() + '_' + current_ai.__name__ +'.csv'
            with open(file_name, 'w', newline='') as csv_file:
                file_writer = csv.writer(csv_file)
                current_ai.print_csv_header(file_writer)

                '''Initialize global variables for current_ai'''
                initialize_current_ai_globals(file_writer)

                '''Play full game and reset'''
                play_game(gamectrl)
                gamectrl.restart_game()

        else:
            '''Initialize global variables for current_ai'''
            initialize_current_ai_globals(None)

            '''Play full game and reset'''
            play_game(gamectrl)
            gamectrl.restart_game()

    '''Log Totals'''
    if log_totals_as_csv:
        file_name = 'log/' + timestamp() + '_' + current_ai.__name__ + '_totals.csv'
        with open(file_name, 'w', newline='') as csv_file2:
            csv_writer2 = csv.writer(csv_file2)
            for line in games_played:
                csv_writer2.writerow(line)