示例#1
0
def play_finding_multiple():
    # TODO: make this pass
    # input("Starting: play_finding_multiple")
    S.reset()
    S.set_rack("ERDE")
    play_erde = D.Play("ERDE", "G8", "X")
    L.execute_play(play_erde)
    S.increase_turn()

    S.set_rack("DEN")
    area_den = D.Area("K6", "K8")
    subturn_den = Game.SubTurn(area_den)
    # highest scoring play should be DEN, K6, Y with ERDEN as bonus.
    print("highest scoring play for Area of K6 to K8:")
    print(subturn_den.highest_scoring_play)
    # play_den = D.Play("DEN", "K6", "Y")
    L.execute_play(subturn_den.highest_scoring_play)
    # L.execute_play(play_den)
    S.increase_turn()

    S.set_rack("URNE")
    Display.print_board()
    parallel_area = D.Area("I9", "L9")
    affected_parallel_plays = parallel_area.contested_plays
    print("affected_parallel plays:")
    pprint.pprint(affected_parallel_plays)

    parallel_subturn = Game.SubTurn(parallel_area)
    print("highest scoring play:")
    # expected: Still URNE on I9, X
    # bonus, DU, ER, DENN
    pprint.pprint(parallel_subturn.highest_scoring_play)
    print("Plays possible on I9 to L9:")
    pprint.pprint(parallel_subturn.possible_plays)
示例#2
0
def custom_turn():
    # Goal: all plays in the Area of L1 to L15 need bonus plays to be valid.
    # BUG: doesn't consider single letters along the way - investigate!
    # see also: Line 3378 in logic_new
    #
    S.reset()
    S.set_rack("ERNSTLUA")
    word_1 = D.Play("NEUTRAL", "F8", "x")
    L.execute_play(word_1)
    S.increase_turn()

    S.set_rack("ERNSTLUA")
    word_2 = D.Play("ANLAUTES", "K5", "y")
    L.execute_play(word_2)
    S.increase_turn()

    # S.set_rack("ERNSTLUA")
    S.set_rack("FASS")  # Fass should be valid on L2
    searching_area = D.Area("L1", "L15")
    possible_plays = Scratch.find_plays_for_area(searching_area)
    # pprint.pprint(possible_plays)

    max_length = len(searching_area.non_empty_letters) + len(S.get_rack()) + 1
    for current_length in range(max_length, 2, -1):
        highest_length = [
            item for item in possible_plays if len(item) == current_length
        ]
        print("Plays with a length of", current_length)
        pprint.pprint(highest_length)
    Display.print_board()
示例#3
0
def log_searching():
    S.reset()
    # finding the plays.
    S.set_rack("ERNSTLÜ")
    play_lustern = D.Play("LÜSTERN", "G8", "X")
    L.execute_play(play_lustern)
    S.increase_turn()
    # Display.print_board()

    # Set BORSTE
    S.set_rack("BORTE")
    play_borste = D.Play("BORSTE", "I5", "Y")
    L.execute_play(play_borste)
    S.increase_turn()
    # Display.print_board()

    # Set ERBE
    S.set_rack("ERE")
    play_erbe = D.Play("ERBE", "G5", "X")
    L.execute_play(play_erbe)
    S.increase_turn()
    # Display.print_board()

    # found_play = WL.find_active_play_by_position("G8")
    # print(found_play)
    # Find BEDARF,
    # Extends ERBE to DERBE
    # Extends LÜSTERN to FLÜSTERN
    # mark both extended-plays as "active" in the WordLog.
    # mark ERBE and LÜSTERN
    S.set_rack("BEDARF")
    test_area_bedarf = D.Area("F3", "F8")
    bedarf_turn = Game.SubTurn(test_area_bedarf.position_list)
    L.execute_play(bedarf_turn.highest_scoring_play)
    S.increase_turn()
    Display.print_board()

    print("All Plays:")
    all_plays = WL.read_log()
    pprint.pprint(all_plays)
    print("Length of all plays:", len(all_plays))

    print("updating to only active plays")
    WL.deactivate_extended_plays()

    print("Only the active plays:")
    active_plays = WL.get_active_plays()
    pprint.pprint(active_plays)
    print("Length of active plays:", len(active_plays))
    # test passes if the active plays are:
    # FLÜSTERN, DERBE, BORSTE and BEDARF
    print("PASSED.")
示例#4
0
def finding_usable_positions():
    S.reset()
    S.set_rack("BEDARF")
    test_play_b = D.Play("BEDARF", "M3", "Y")
    print(test_play_b)
    # print(WS.find_execution(test_play_b))
    print(test_play_b.find_execution())
    L.execute_play(test_play_b)
    S.increase_turn()

    Display.print_board()
    S.set_rack("BEDARF")
    test_area = D.Area(position_list=WS.find_usable_positions("M3", "x"))
    starting_positions = WS.find_starting_position("FADER", test_area)
    print("starting positions for FARBE on M3, X:")
    print(starting_positions)
示例#5
0
def area_find_occupied_neighbors():
    S.reset()
    S.set_rack("STRUDELN")
    first_play = D.Play("STRUDELN", "F8", "x")
    L.execute_play(first_play)
    S.increase_turn()

    S.set_rack("FARBE")
    second_play = D.Play("FARBEN", "M3", "y")
    L.execute_play(second_play)
    S.increase_turn()

    S.set_rack("BEDARF")
    Display.print_board()
    subturn_area = D.Area("L2", "L14")
    subturn_to_solve = Game.SubTurn(subturn_area)
    pprint.pprint(subturn_to_solve.possible_plays)
示例#6
0
def first_turn():
    S.reset()
    S.set_rack("ERNSTLU?")

    filled_positions = []
    usable_positions = WS.find_usable_positions("H8", "x")
    print("Usable positions:")
    first_area = D.Area(position_list=usable_positions)
    starting_positions = WS.find_starting_position("STRUDELN", first_area)
    print("starting positions for STRUDELN:")
    print(starting_positions)
    Display.print_board()

    print("Subturn in Turn 1:")
    first_subturn = Game.SubTurn(first_area)
    highest_play = first_subturn.highest_scoring_play
    L.execute_play(highest_play)
    Display.print_board()
示例#7
0
def play_finding_parallel():
    input("Starting: play_finding_parallel")
    S.reset()
    S.set_rack("ERDE")
    play_erde = D.Play("ERDE", "G8", "X")
    L.execute_play(play_erde)
    S.increase_turn()

    S.set_rack("URNE")
    Display.print_board()
    parallel_area = D.Area("I9", "L9")
    affected_parallel_plays = parallel_area.contested_plays
    print("affected_parallel plays:")
    pprint.pprint(affected_parallel_plays)

    parallel_subturn = Game.SubTurn(parallel_area)
    print("highest scoring play:")
    pprint.pprint(parallel_subturn.highest_scoring_play)
    print("Plays possible on I9 to L9:")
    pprint.pprint(parallel_subturn.possible_plays)
    print("PASSED.")
示例#8
0
def play_finding_by_position():
    # This passes when the play BEDARF, F3, Y
    # gets points for the 2 plays it extends.
    # (DERBE, E5, X) and (FL?STERN, E8, X)

    # Start by setting LÜSTERN
    S.set_rack("ERNSTL?")
    test_play_open = D.Play("LÜSTERN", "G8", "X")
    L.execute_play(test_play_open)
    S.increase_turn()
    Display.print_board()

    # Set BORSTE
    S.set_rack("BORTE")
    test_play_borste = D.Play("BORSTE", "I5", "Y")
    L.execute_play(test_play_borste)
    S.increase_turn()
    Display.print_board()

    # Set ERBE
    S.set_rack("ERE")
    test_play_erbe = D.Play("ERBE", "G5", "X")
    L.execute_play(test_play_erbe)
    S.increase_turn()
    Display.print_board()

    # found_play = WL.find_active_play_by_position("G8")
    # print(found_play)
    # Find BEDARF,
    # Extends ERBE to DERBE
    # Extends LÜSTERN to FLÜSTERN
    # mark both extended-plays as "active" in the WordLog.
    # mark ERBE and LÜSTERN

    S.set_rack("BEDARF")
    test_area_bedarf = D.Area("F3", "F8")
    # empty_area_with_no_neighbors = D.Area("D3", "D8")

    # Works.
    bedarf_turn = Game.SubTurn(test_area_bedarf.position_list)
    L.execute_play(bedarf_turn.highest_scoring_play)
    S.increase_turn()
    S.set_rack("VERNDE")
    Display.print_board()
    # Works.
    area_verderbende = D.Area("A5", "O5")
    verderbende_turn = Game.SubTurn(area_verderbende.position_list)
    L.execute_play(verderbende_turn.highest_scoring_play)
    S.increase_turn()
    Display.print_board()

    S.set_rack("ZIERENDE")
    area_extends_right = D.Area("N1", "N15")
    extends_right_turn = Game.SubTurn(area_extends_right.position_list)

    print("highest scoring play:")
    pprint.pprint(extends_right_turn.highest_scoring_play)
    L.execute_play(extends_right_turn.highest_scoring_play)
    S.increase_turn()
    Display.print_board()

    # active_plays = WL.get_active_plays()
    # pprint.pprint(active_plays)
    # print("Length of active plays:", len(active_plays))
    #
    # print("All plays of extends_right_turn")
    # pprint.pprint(extends_right_turn.possible_plays)

    # for position in test_area_bedarf.neighbors:
    #     L.set_letter_to_position(".", position)
    # Display.print_board()
    # print("-"*30)
    # print("LÜSTERN can be expanded at:", test_play_open.extendable_at)
    # test_area_flsternd = D.Area("F8", "N8")
    # print("contested at:", test_area_flsternd.contested_at)
    # print("contested play(s):")
    # print(test_area_flsternd.contested_plays)
    # TODO: the exact same play can be contested twice.
    #  -> identical play on 2 different positions

    S.set_rack("ERNSTZUNEHMEND")
    area_non_continuous = D.Area("L1", "L15")
    turn_non_continuous = Game.SubTurn(area_non_continuous.position_list)
    print("Current Rack:", S.get_rack())
    print("Plays possible on L1 to L15:")
    pprint.pprint(turn_non_continuous.possible_plays)

    # TODO, testing:
    # select an area directly adjacent to an existing word, make sure all sub-plays are
    # counted as well

    # UR on E13-F13 should be possible
    # Bonus: DU, E12-E13 // ER, F12-F13
    S.set_rack("ERDE")
    play_erde = D.Play("ERDE", "C12", "X")
    L.execute_play(play_erde)
    S.increase_turn()

    S.set_rack("URNE")
    Display.print_board()
    parallel_area = D.Area("C13", "H13")
    affected_parallel_plays = parallel_area.contested_plays
    print("affected_parallel plays:")
    pprint.pprint(affected_parallel_plays)

    parallel_subturn = Game.SubTurn(parallel_area.position_list)
    print("highest scoring play:")
    pprint.pprint(parallel_subturn.highest_scoring_play)
    print("Plays possible on C13 to F13:")
    pprint.pprint(parallel_subturn.possible_plays)

    # TODO, for Testing.:
    # create a situation on the board where the entire rack is played,
    # the word is vertical and extends all already existing words (7 extensions)

    # TODO: Idea - in an area with 2 or more possible extension_crossovers,
    # try to find the extensions first, then fill the area via regex-words.
    # needs: a function to reserve letters from the rack,
    # the word_search by regex,
    print("PASSED.")
示例#9
0
def word_search():
    # TODO: Redesign findPossibleWords.
    S.set_rack("ERNSTLUD")
    center = L.get_center_of_board()
    # L.set_letter_to_position(center, "E")
    print("Center Position:", center)
    # emptyRange = ["G8", "H8", "I8"]
    # what if we just plant a random letter onto the center?
    # rack = S.get_rack()
    # L.set_letter_to_position(center, rack[0])
    # rack.pop(0)
    # having no letters on the boeard should yield:
    # STERN, ERST, ER, ERNST, REST, LERN, URNE, LUST, DURST, STRUDEL
    # maybe the problem is with intersection_update()
    usable_range = WS.find_usable_positions(center, "x")
    start_at = usable_range[0]
    end_at = usable_range[-1]
    print("usable range", usable_range)
    # first_turn_plays = WS.find_open_plays(list(center), "x")
    # words = WS.createWords(usableRange, "x")

    # WARNING: STUPID
    test_range = D.Area(position_list=usable_range)
    # stupid_words = WS.create_words_stupid_for_testing(test_range)
    # unique_words_stupid = list(set(stupid_words))
    # print(unique_words_stupid)
    # print("length of unique_words_stupid:", len(unique_words_stupid))

    # OBJECTIVE: redesign create_words and find_starting_position
    # test against creat  e_words_stupid
    # both funxtions must work without letters on the board
    new_words = WS.create_words(test_range)
    unique_new_words = list(set(new_words))
    print(unique_new_words)
    print("length of unique_words_new:", len(unique_new_words))

    placeable_suggestions = []
    possible_plays = []
    for word in unique_new_words:
        start_position = WS.find_starting_position(word, test_range)
        if len(start_position) == 0:
            continue
        else:
            for s_pos in start_position:
                raw_word = D.Suggestion(word, s_pos, test_range.axis)
                if C.is_word_placeable(raw_word):
                    placeable_suggestions.append(raw_word)

    for suggestion in placeable_suggestions:
        possible_plays.append(
            D.Play(suggestion.word, suggestion.position, suggestion.axis))
    pprint.pprint(possible_plays)
    print(
        f"total possible plays for turn {S.GAME_SETTINGS['turn']}: {len(possible_plays)}"
    )
    # Display.print_board()
    # startingPositions = []
    # for current_word in unique_words:
    #     startingPositions.extend(WS.findStartingPosition(current_word,
    #                                                      stupid_range.pos_list,
    #                                                      stupid_range.axis,
    #                                                      []))
    # print(startingPositions)
    print("PASSED.")
    return