Reformat all code with black formatter.
This commit is contained in:
1 parent
497c48f853
commit
7cf685b507
4 files changed
+65
-37
No files matched your search
@@ -7,8 +7,9 @@ import wordle
|
|||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
def parse_guess(guess):
|
def parse_guess(guess):
|
||||||
return 'foody', 'CICMI'
|
return "foody", "CICMI"
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
@@ -19,7 +20,6 @@ def parse_guess(guess):
|
|||||||
@app.route("/<g1>/<g2>/<g3>/<g4>/<g5>")
|
@app.route("/<g1>/<g2>/<g3>/<g4>/<g5>")
|
||||||
@app.route("/<g1>/<g2>/<g3>/<g4>/<g5>/<g6>")
|
@app.route("/<g1>/<g2>/<g3>/<g4>/<g5>/<g6>")
|
||||||
def solver(g1=None, g2=None, g3=None, g4=None, g5=None, g6=None):
|
def solver(g1=None, g2=None, g3=None, g4=None, g5=None, g6=None):
|
||||||
|
|
||||||
constraints = wordle.Constraints()
|
constraints = wordle.Constraints()
|
||||||
|
|
||||||
guesses = []
|
guesses = []
|
||||||
@@ -65,5 +65,6 @@ def dictionary(page=0):
|
|||||||
|
|
||||||
words = words[start_word:end_word]
|
words = words[start_word:end_word]
|
||||||
|
|
||||||
return render_template("dictionary.html",
|
return render_template(
|
||||||
page=page, max_pages=max_pages, words=words)
|
"dictionary.html", page=page, max_pages=max_pages, words=words
|
||||||
|
)
|
||||||
@@ -6,7 +6,8 @@ import wordle
|
|||||||
def display_instructions():
|
def display_instructions():
|
||||||
"""Print out instuctions before starting play."""
|
"""Print out instuctions before starting play."""
|
||||||
|
|
||||||
print(f"""Welcome to Wordle!
|
print(
|
||||||
|
f"""Welcome to Wordle!
|
||||||
|
|
||||||
Wordle has a hidden word of five letters, and you get to
|
Wordle has a hidden word of five letters, and you get to
|
||||||
make up to six guesses to find out what it is.
|
make up to six guesses to find out what it is.
|
||||||
@@ -15,12 +16,13 @@ def display_instructions():
|
|||||||
* {wordle.display_result(wordle.LetterResult.CORRECT, "Correct!")}
|
* {wordle.display_result(wordle.LetterResult.CORRECT, "Correct!")}
|
||||||
* {wordle.display_result(wordle.LetterResult.MOVE, "Correct, in a different location.")}
|
* {wordle.display_result(wordle.LetterResult.MOVE, "Correct, in a different location.")}
|
||||||
* {wordle.display_result(wordle.LetterResult.INCORRECT, "Not in the word.")}
|
* {wordle.display_result(wordle.LetterResult.INCORRECT, "Not in the word.")}
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def read_valid_guess(guess_number):
|
def read_valid_guess(guess_number):
|
||||||
while True:
|
while True:
|
||||||
print(f"Guess {guess_number}: ", end='')
|
print(f"Guess {guess_number}: ", end="")
|
||||||
guess = input()
|
guess = input()
|
||||||
if guess in wordle.dictionary():
|
if guess in wordle.dictionary():
|
||||||
return guess
|
return guess
|
||||||
@@ -29,9 +31,9 @@ def read_valid_guess(guess_number):
|
|||||||
|
|
||||||
|
|
||||||
def display_results(guess, results):
|
def display_results(guess, results):
|
||||||
print(" ", end='')
|
print(" ", end="")
|
||||||
for i in range(wordle.WORDLE_LENGTH):
|
for i in range(wordle.WORDLE_LENGTH):
|
||||||
print(wordle.display_result(results[i], guess[i]), end='')
|
print(wordle.display_result(results[i], guess[i]), end="")
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
|
|
||||||
@@ -56,5 +58,5 @@ def play_game():
|
|||||||
print(f"Sorry, no guesses remaining. The word was: {target}")
|
print(f"Sorry, no guesses remaining. The word was: {target}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
play_game()
|
play_game()
|
||||||
+52
-26
@@ -9,49 +9,75 @@ import unittest
|
|||||||
|
|
||||||
|
|
||||||
class TestConstraints(unittest.TestCase):
|
class TestConstraints(unittest.TestCase):
|
||||||
|
|
||||||
def test_empty(self):
|
def test_empty(self):
|
||||||
constraints = wordle.Constraints()
|
constraints = wordle.Constraints()
|
||||||
self.assertTrue(constraints.matches('abcde'))
|
self.assertTrue(constraints.matches("abcde"))
|
||||||
self.assertTrue(constraints.matches('bcdef'))
|
self.assertTrue(constraints.matches("bcdef"))
|
||||||
|
|
||||||
def test_correct(self):
|
def test_correct(self):
|
||||||
constraints = wordle.Constraints()
|
constraints = wordle.Constraints()
|
||||||
constraints.update_graded('abcde', [LetterResult.CORRECT, LetterResult.INCORRECT, LetterResult.INCORRECT, LetterResult.INCORRECT, LetterResult.INCORRECT])
|
constraints.update_graded(
|
||||||
|
"abcde",
|
||||||
|
[
|
||||||
|
LetterResult.CORRECT,
|
||||||
|
LetterResult.INCORRECT,
|
||||||
|
LetterResult.INCORRECT,
|
||||||
|
LetterResult.INCORRECT,
|
||||||
|
LetterResult.INCORRECT,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
self.assertTrue(constraints.matches('amnop'))
|
self.assertTrue(constraints.matches("amnop"))
|
||||||
self.assertTrue(constraints.matches('aaaaa'))
|
self.assertTrue(constraints.matches("aaaaa"))
|
||||||
|
|
||||||
self.assertFalse(constraints.matches('abcde'))
|
self.assertFalse(constraints.matches("abcde"))
|
||||||
self.assertFalse(constraints.matches('lmnop'))
|
self.assertFalse(constraints.matches("lmnop"))
|
||||||
self.assertFalse(constraints.matches('aedcb'))
|
self.assertFalse(constraints.matches("aedcb"))
|
||||||
self.assertFalse(constraints.matches('amnob'))
|
self.assertFalse(constraints.matches("amnob"))
|
||||||
|
|
||||||
def test_correct_count_limit(self):
|
def test_correct_count_limit(self):
|
||||||
constraints = wordle.Constraints()
|
constraints = wordle.Constraints()
|
||||||
constraints.update_graded('aazzz', [LetterResult.CORRECT, LetterResult.INCORRECT, LetterResult.INCORRECT, LetterResult.INCORRECT, LetterResult.INCORRECT])
|
constraints.update_graded(
|
||||||
|
"aazzz",
|
||||||
|
[
|
||||||
|
LetterResult.CORRECT,
|
||||||
|
LetterResult.INCORRECT,
|
||||||
|
LetterResult.INCORRECT,
|
||||||
|
LetterResult.INCORRECT,
|
||||||
|
LetterResult.INCORRECT,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
self.assertTrue(constraints.matches('abcde'))
|
self.assertTrue(constraints.matches("abcde"))
|
||||||
self.assertTrue(constraints.matches('abbbb'))
|
self.assertTrue(constraints.matches("abbbb"))
|
||||||
|
|
||||||
self.assertFalse(constraints.matches('aabbb'))
|
self.assertFalse(constraints.matches("aabbb"))
|
||||||
self.assertFalse(constraints.matches('abbba'))
|
self.assertFalse(constraints.matches("abbba"))
|
||||||
self.assertFalse(constraints.matches('bbbbb'))
|
self.assertFalse(constraints.matches("bbbbb"))
|
||||||
self.assertFalse(constraints.matches('bbbba'))
|
self.assertFalse(constraints.matches("bbbba"))
|
||||||
self.assertFalse(constraints.matches('babbb'))
|
self.assertFalse(constraints.matches("babbb"))
|
||||||
|
|
||||||
def test_move(self):
|
def test_move(self):
|
||||||
constraints = wordle.Constraints()
|
constraints = wordle.Constraints()
|
||||||
constraints.update_graded('abcde', [LetterResult.MOVE, LetterResult.INCORRECT, LetterResult.INCORRECT, LetterResult.INCORRECT, LetterResult.INCORRECT])
|
constraints.update_graded(
|
||||||
|
"abcde",
|
||||||
|
[
|
||||||
|
LetterResult.MOVE,
|
||||||
|
LetterResult.INCORRECT,
|
||||||
|
LetterResult.INCORRECT,
|
||||||
|
LetterResult.INCORRECT,
|
||||||
|
LetterResult.INCORRECT,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
self.assertTrue(constraints.matches('zzzza'))
|
self.assertTrue(constraints.matches("zzzza"))
|
||||||
self.assertTrue(constraints.matches('zzzaa'))
|
self.assertTrue(constraints.matches("zzzaa"))
|
||||||
self.assertTrue(constraints.matches('zaaaa'))
|
self.assertTrue(constraints.matches("zaaaa"))
|
||||||
|
|
||||||
self.assertFalse(constraints.matches('azzzz'))
|
self.assertFalse(constraints.matches("azzzz"))
|
||||||
self.assertFalse(constraints.matches('zzzzz'))
|
self.assertFalse(constraints.matches("zzzzz"))
|
||||||
self.assertFalse(constraints.matches('zzzba'))
|
self.assertFalse(constraints.matches("zzzba"))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
Reference in new issue
Block a user