示例#1
0
def entire_turn(number_of_turns: int = 5):
    # TODO: DEBUG A WHOLE LOT
    # BUG: # considers FARBEN a proper play on M2, y
    # only FARBE gets planted.
    # if there's no letter on the rack, it's still trying to find a valid play.
    # TODO: Add checks to ensure at least one Rack-letter must be used.
    # BUG: "FABEL" on L4-L8 is considered the best play on Turn 3 in this setup.
    # The available Area is F8 to F14...
    # Also doesn't check for bonus-plays
    # which would need to be: FA, AR, BB, and EE

    # tested in debugger:
    # expected
    # [STRUDELN                    F8-M8:x         score:20(20+0)      ,
    #  FARBEN                      M3-M8:y         score:24(24+0)      ,
    #  BEDARF                      K7-K12:y        score:22(22+0)      ,
    #  RAFFE                       H12-L12:x       score:24(24+0)      ,
    #  BEDARF                      I5-N5:x         score:22(22+0)      ]

    S.reset()
    # S.fill_rack()
    turn_number = S.GAME_SETTINGS['turn']
    all_turns = []

    while turn_number < number_of_turns:
        # TODO: finally make Game_settings a proper Object
        turn_number = S.GAME_SETTINGS['turn']
        if C.is_first_turn() is True:
            S.set_rack("ERNSTLU?")
        else:
            S.set_rack("BEDARF")
        print(f"  Turn No.: {turn_number}  ".center(80, "-"))
        Display.print_board()

        turn = Game.Turn(None, S.get_rack())
        all_turns.append(turn)
        # input("Press Enter to execute the highest scoring play from this turn...")
        L.execute_play(turn.highest_scoring_play)
        print("  End of turn.  ".center(80, "-"))
        # S.fill_rack()
        S.increase_turn()

        Display.print_board()
        pprint.pprint(WL.get_active_plays())
        print("PASSED.")
示例#2
0
def entire_game(is_automatic: bool = False, always_ERNSTLUA: bool = False):
    # emulate the turns, from start to empty bag.
    # ask before executing a play whether it's correct,
    # write "incorrect" plays to a list for debugging.
    S.reset()
    remaining_letters_initial = len(S.INITIAL_SETTINGS['bag'])
    # remaining_letters_initial = len("AAAA")
    remaining_letters = deepcopy(remaining_letters_initial)
    turn_number = S.GAME_SETTINGS['turn']
    all_turns = []
    incorrect_plays = []
    game_score = 0
    previous_best_play = None
    current_rack = []
    running = True

    print("Number of Letters:", remaining_letters)

    while running:

        if always_ERNSTLUA is True:
            # 4 letters still in the bag: only "ERNS" should be on the rack.
            num_letters_replaced = len("ERNSTLUA") - len(S.get_rack())
            print("number of letters replaced:", num_letters_replaced)

            if remaining_letters == 0:
                pass
            elif remaining_letters < num_letters_replaced:
                offset = len("ERNSTLUA") - remaining_letters
                ernstlua_letters = "ERNSTLUA"[0:-offset]
                S.set_rack(ernstlua_letters)
            else:
                S.set_rack("ERNSTLUA")
            current_rack = S.get_rack()
            remaining_letters -= num_letters_replaced

        else:
            S.fill_rack()
            current_rack = S.get_rack()
            remaining_letters = len(S.GAME_SETTINGS['bag'])

        # highest_scoring_play = None
        print(f"  Turn No.: {turn_number}  ".center(80, "-"))
        Display.print_board()

        # BUG: sometimes yields the same turn?
        # see scatch.md

        turn = Game.Turn(None, current_rack)
        # highest_scoring_play = turn.highest_scoring_play

        # print("Total possible Plays for this turn:")
        # pprint.pprint(turn.possible_plays)

        Display.print_board()

        print("The Highest scoring play is:".center(80))
        pprint.pprint(turn.highest_scoring_play)

        # TODO: this never fires.
        # if previous_best_play is not None:
        #     if highest_scoring_play == previous_best_play:
        #         raise NotImplementedError("Previous Best Play is identical to the current best Play.")

        if is_automatic is True:
            answer = "y"
        else:
            answer = ""

        while answer.casefold() not in ["y", "n"]:
            if answer == "":
                answer = input(
                    "Check against the board - is this play correct? [y/n]: >")
            if len(answer) == 0:
                continue
            elif answer.casefold() == "n":
                incorrect_plays.append(turn.highest_scoring_play)
                break
            elif answer.casefold() == "y":
                break

        print("  End of turn.  ".center(80, "-"))
        print("Remaining letters:", remaining_letters)
        L.execute_play(turn.highest_scoring_play)
        # previous_best_play = highest_scoring_play
        game_score += turn.highest_scoring_play.score_total

        if remaining_letters < 0 and len(S.get_rack()) == 0:
            running = False
            break

        S.increase_turn()

    print("Game has ended.")
    print("Total score:", game_score)
    print("Incorrect plays:")
    pprint.pprint(incorrect_plays)

    print("Play Log:")
    pprint.pprint(WL.get_active_plays())