Snapshot flask development.
Dictionary and solver pages can partially display, but can't make any changes.
This commit is contained in:
1 parent
f7dd7c40f8
commit
17c8aefbed
5 files changed
+100
-11
No files matched your search
@@ -3,14 +3,67 @@
|
|||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask import render_template
|
from flask import render_template
|
||||||
|
|
||||||
|
import wordle
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
def parse_guess(guess):
|
||||||
|
return 'foody', 'CICMI'
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def solver():
|
@app.route("/<g1>")
|
||||||
return render_template("solver.html")
|
@app.route("/<g1>/<g2>")
|
||||||
|
@app.route("/<g1>/<g2>/<g3>")
|
||||||
|
@app.route("/<g1>/<g2>/<g3>/<g4>")
|
||||||
|
@app.route("/<g1>/<g2>/<g3>/<g4>/<g5>")
|
||||||
|
@app.route("/<g1>/<g2>/<g3>/<g4>/<g5>/<g6>")
|
||||||
|
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")
|
@app.route("/dictionary")
|
||||||
def dictionary():
|
@app.route("/dictionary/<page>")
|
||||||
return render_template("dictionary.html")
|
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)
|
||||||
@@ -5,5 +5,19 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
Words go here.
|
|
||||||
|
{% if page > 0 %}<a href="{{ url_for('dictionary', page=page-1) }}">Prev</a>{% endif %}
|
||||||
|
|
||||||
|
Page {{ page }} / {{ max_pages }}
|
||||||
|
|
||||||
|
{% if page < max_pages %}<a href="{{ url_for('dictionary', page=page+1) }}">Next</a>{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
{% for word in words %}
|
||||||
|
<li>{{ word }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -18,7 +18,8 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
<hr />
|
<hr />
|
||||||
<footer>
|
<footer>
|
||||||
I did this!
|
This is not associated with the New York Times or the offical version of
|
||||||
|
Wordle in any way.
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
+22
-1
@@ -5,5 +5,26 @@ Solver!
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
Welcome to solver!
|
<ul>
|
||||||
|
{% for guess in guesses %}
|
||||||
|
<li>{{ guess }}
|
||||||
|
|
||||||
|
{% for i in range(5) %}
|
||||||
|
<select name="g{{i}}" id="g{{i}}">
|
||||||
|
<option value="U">Unknown</option>
|
||||||
|
<option value="I">Incorrect</option>
|
||||||
|
<option value="M">Move</option>
|
||||||
|
<option value="C">Correct</option>
|
||||||
|
</select>
|
||||||
|
{% endfor %}
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
{%if solution %}
|
||||||
|
The proposed solution is <b>{{ solution }}</b>.
|
||||||
|
{% else %}
|
||||||
|
No solution found.
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -11,10 +11,10 @@ WORDLE_LENGTH = 5
|
|||||||
|
|
||||||
class LetterResult(Enum):
|
class LetterResult(Enum):
|
||||||
"""Is an individual letter in a word in the result?"""
|
"""Is an individual letter in a word in the result?"""
|
||||||
CORRECT = 1
|
CORRECT = 'C'
|
||||||
MOVE = 2
|
MOVE = 'M'
|
||||||
INCORRECT = 3
|
INCORRECT = 'I'
|
||||||
UNKNOWN = 4
|
UNKNOWN = 'U'
|
||||||
|
|
||||||
|
|
||||||
class InvalidWord(Exception):
|
class InvalidWord(Exception):
|
||||||
|
|||||||
Reference in new issue
Block a user