diff --git a/app.py b/app.py index b9c3335..9792f36 100644 --- a/app.py +++ b/app.py @@ -3,14 +3,67 @@ from flask import Flask from flask import render_template +import wordle + app = Flask(__name__) +def parse_guess(guess): + return 'foody', 'CICMI' + @app.route("/") -def solver(): - return render_template("solver.html") +@app.route("/") +@app.route("//") +@app.route("///") +@app.route("////") +@app.route("/////") +@app.route("//////") +def solver(g1=None, g2=None, g3=None, g4=None, g5=None, g6=None): + + constraints = wordle.Constraints() + + guesses = [] + results = [] + + for g in (g1, g2, g3, g4, g5, g6): + parsed_guess, parsed_result = parse_guess(g) + + if parsed_guess: + guesses.append(parsed_guess) + + if parsed_result: + results.append(parsed_result) + + if parsed_guess and parsed_result: + constraints.update_graded(parsed_guess, parsed_result) + + valid_words = wordle.filter_dictionary(constraints) + scored_words = wordle.scored_words(valid_words) + + # If a proposed solution was found... + if scored_words: + guesses.append(scored_words[0][0]) + + return render_template("solver.html", guesses=guesses, results=results) @app.route("/dictionary") -def dictionary(): - return render_template("dictionary.html") +@app.route("/dictionary/") +def dictionary(page=0): + PAGE_SIZE = 100 + words = sorted(wordle.dictionary()) + + try: + page = int(page) + except ValueError: + page = 0 + + max_pages = int(len(words) / PAGE_SIZE) + + start_word = page * PAGE_SIZE + end_word = start_word + PAGE_SIZE + + words = words[start_word: end_word] + + return render_template("dictionary.html", + page=page, max_pages=max_pages, words=words) diff --git a/templates/dictionary.html b/templates/dictionary.html index 774d5f1..404f2de 100644 --- a/templates/dictionary.html +++ b/templates/dictionary.html @@ -5,5 +5,19 @@ {% endblock %} {% block content %} - Words go here. + + {% if page > 0 %}Prev{% endif %} + + Page {{ page }} / {{ max_pages }} + + {% if page < max_pages %}Next{% endif %} + + +
    + {% for word in words %} +
  • {{ word }}
  • + {% endfor %} +
+ + {% endblock %} diff --git a/templates/layout.html b/templates/layout.html index c3fdeb4..cd94449 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -18,7 +18,8 @@ {% endblock %}
- I did this! + This is not associated with the New York Times or the offical version of + Wordle in any way.
diff --git a/templates/solver.html b/templates/solver.html index 75e65ea..90f1eee 100644 --- a/templates/solver.html +++ b/templates/solver.html @@ -1,9 +1,30 @@ {% extends "layout.html" %} {% block title %} -Solver! + Solver! {% endblock %} {% block content %} -Welcome to solver! -{% endblock %} +
    + {% for guess in guesses %} +
  • {{ guess }} + + {% for i in range(5) %} + + {% endfor %} +
  • + {% endfor %} +
+ + + {%if solution %} + The proposed solution is {{ solution }}. + {% else %} + No solution found. + {% endif %} +{% endblock %} \ No newline at end of file diff --git a/wordle.py b/wordle.py index 011f632..97dc84d 100644 --- a/wordle.py +++ b/wordle.py @@ -11,10 +11,10 @@ WORDLE_LENGTH = 5 class LetterResult(Enum): """Is an individual letter in a word in the result?""" - CORRECT = 1 - MOVE = 2 - INCORRECT = 3 - UNKNOWN = 4 + CORRECT = 'C' + MOVE = 'M' + INCORRECT = 'I' + UNKNOWN = 'U' class InvalidWord(Exception):