コード例 #1
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