예제 #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):
    from itertools import count
    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)

    assistant = KeyboardWebAssistant(ctrl)

    if args.repeat:
        iterations = count(1)
    else:
        iterations = ['']

    for i, suffix in enumerate(iterations):
        if i >= 1:
            assistant.restart()
        run_assistant(assistant.gen_board(), assistant.make_move,
                      args.from_start)
예제 #3
0
파일: 2048.py 프로젝트: pandermatt/KI-2048
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)
    from gamectrl import Fast2048Control
    gamectrl = Fast2048Control(ctrl)

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

    score_list = []
    high_score = 0
    sum_tile = 0
    sum_score = 0
    iterations = 10
    for i in range(iterations):
        board, game = play_game(gamectrl)
        score_list.append(game)
        with open("score.txt", "a") as myfile:
            myfile.write("Score %d \n" % game.final_score)
            myfile.write("Tile %d \n" % game.maxval)
            myfile.write("Board:\n")
            myfile.write(str(board))
            myfile.write("\n --------------\n")
            myfile.close()
        if high_score < game.final_score:
            high_score = game.final_score
        time.sleep(0.3)
        gamectrl.restart_game()
    for score in score_list:
        sum_tile = sum_tile + score.maxval
        sum_score = sum_score + score.final_score
        print("Score %d; highest tile %d." % (score.final_score, score.maxval))
    print("Final score %d" % high_score)
    print("Avg score %d" % (sum_score / iterations))
    print("Avg Tile %d" % (sum_tile / iterations))
예제 #4
0
파일: 2048.py 프로젝트: edualc/HS2017_KI1
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)