コード例 #1
0
def rack_simple():
    S.reset()
    S.set_rack("ERNST")
    rack = S.get_rack()
    print("rack after reset:", rack)
    S.fill_rack()
    print("rack after fill_rack, without re-assignment:", rack)
    print("PASSED.")
    return
コード例 #2
0
def rack_complete():
    S.reset()

    print("Drawing all letters from the bag...")
    letters_drawn = []
    bag = S.GAME_SETTINGS['bag']
    while len(bag) > 0:
        print("number of letters still in the bag:", len(bag))
        S.fill_rack()
        letters_drawn.extend(S.get_rack())
        print("letters drawn:", S.get_rack())
        S.set_rack("")
    print("total letters drawn:", len(letters_drawn))
    print("in order:", letters_drawn)
    print("PASSED.")
コード例 #3
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())