Skip to main content

The popular word game recreated in Python, deployable with custom answers.

Project description

Wordle

View on GitHub and PyPI.


Updates

Version 2.0.0

A new function to get a random answer based on the day. You can deploy this Wordle and have it give you a random answer automatically every day! Instead of manually changing the answer, the program (can) automatically change its answer every day.

Use wordle.random_answer(daily = True). You can instantiate a game using this parameter:

import wordle

wordle.Wordle(word = wordle.random_answer(daily = True), real_words = True).run()

If this game is run in the same day, the answer word will be the same. Tomorrow, however, it will change. I did this using UNIX. The dictionary is shuffled and an iterator is calculated using multiples of 86400000 (milliseconds in a day). The program then gets a word from the randomized dictionary.jumbled_words list based on the iterator.

The behavior is that the program will have the same answer intraday but will automatically run with a new unique answer the next day. By standardizing this using UNIX time I avoided the need for a central database of "used" words. To reset it all, dictionary.jumbled_words has to be recalculated using random.sample(dictionary.words, len(dictionary.words)).

This is a much better way to deploy to the cloud as the game is completely self-sufficient!

Version 1.9.0

Completely redesigned the Wordle class as it was totally inefficient. It used to take the parameter self.real_words, given on object instantiation, and then run in two separate ways. The logic worked in this way:

class Wordle:
    def run(self):
        if self.real_words == True:
            run_with_logic_that_words_must_be_checked()
        elif self.real_words == False:
            run_with_logic_that_words_must_not_be_checked()

This was very inefficient because fixes and upgrades had to be made to both aspects of the Wordle.run() function. Initially it was necessary because the logic for checking against the dictionary was unique, but now, I'm hosting a dictionary of thousands of five-letter words here. So, I rewrote the class to have this structure:

class Wordle:
    def run(self):
        run_with_interspersed_realWords_conditions()

Which works much better. I introduced a failed_dictionary_test boolean which resets every time a new attempt is entered but allows the program to alert non-real words only if self.real_words == True AND guess.lower() not in dictionary.words. It's clean, faster, and more efficient!

Version 1.8.0

An issue was brought up on GitHub. If the answer was "games" for example, and you guessed "trees", the program would capitalize both of the letters "e" in your guess. It would behave in this way:

# Answer = 'games'

Attempt 1 >>> trees
t   r   E   E   *S*

I corrected the error with a functional list(self.word) that resets itself every attempt. Now the program behaves properly, in the way we'd expect:

# Answer = 'games'

Attempt 1 >>> trees
t   r   E   e   *S*

Documentation

Wordle is super fun and popular game. Unfortunately, it's new and nonstandard, meaning the backend technology is not prevalent and recreatable online. There are a couple web-based customizable Wordle tools, which work very well, but they're front-end only (you can't clone, copy, modify, or edit the back-end to deploy it to a website or run your own game). That said, the logic behind Wordle is quite simple which is why it's now a Python library, enabling all the functions of an open-sourced game.

Currently, the module is logic based and runs in a shell. I'd love it if this project was forked into a GUI-based application, possibly using pygame, allowing users to take this a step further and deploy a version with a user-interface. As it stands, the best way I can think of to deploy Wordle to the web is by using an embedded Python console like Trinket and putting it in 'run-only' mode so users can't see the source code (where the answer is). See an example of this in real deployment here.

In any case, usage of this module is wickedly simple.

import wordle

game = wordle.Wordle(word = 'HELLO', real_words = False)
game.run()

# Or even more simply:
wordle.Wordle(word = 'hello', real_words = True).run() # runs in one line. 

Instantiate a game object using game = wordle.Wordle(). The two positional requirements of the Wordle class are word and real_words. word is the answer to the game. If the object is instantiated with real_words = True, word must be a real, five-letter word or an exception will be raised, and you'll have to change your instantiation to reflect a real word. real_words is a boolean. If it's True, the package will check user's (in-game) guesses against a comprehensive inbuilt database of thousands of five-letter words. If it's False, any guess (real or not) will be accepted. In summary, real_words applies both to the answer in the code's instantiation and in the user's in-game guesses.

In the game of Wordle, part of the challenge is that guesses must be real words. This prevents users from guessing "aeiou" as their first attempt, for example. That's it's relevant and important for you to tell the game object whether it should check for real words or not.

Note: In version 1.5.10, the issue disallowing a lower-case word has been patched. word = 'hello' and word = 'HELLO' are both acceptable in the game initialization.

To view the docstring (explainer) of a particular function, use wordle.Wordle.run.__doc__ where run can be repalced with any other function. For example, running print(wordle.Wordle.run.__doc__) will return: Run the game. Depends on bool real_words from instantiation. Depending on your IDE, hovering over a function in the editor will show the function's docstring (works in VS Code).

import wordle

if __name__ == "__main__":
    print(wordle.Wordle.__doc__)
    print(wordle.Wordle.run.__doc__)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wordle-python-2.0.6.tar.gz (35.7 kB view details)

Uploaded Source

Built Distribution

wordle_python-2.0.6-py3-none-any.whl (32.2 kB view details)

Uploaded Python 3

File details

Details for the file wordle-python-2.0.6.tar.gz.

File metadata

  • Download URL: wordle-python-2.0.6.tar.gz
  • Upload date:
  • Size: 35.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for wordle-python-2.0.6.tar.gz
Algorithm Hash digest
SHA256 d8c196d6f0ddd9c80b0d4bf5fb2aec97a8810d686ef8b2860cd6546d76cb2815
MD5 c3cb7ca4b51d05e1a210f28c7ad4e44a
BLAKE2b-256 e70bac12cec88fb7ed038812e1e510aa67b6547e048997bacd3d12620d031903

See more details on using hashes here.

File details

Details for the file wordle_python-2.0.6-py3-none-any.whl.

File metadata

  • Download URL: wordle_python-2.0.6-py3-none-any.whl
  • Upload date:
  • Size: 32.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for wordle_python-2.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 d2f3542881228110a400c9e70742865c6c17ed25a410baab35e7a16990accfec
MD5 6b05d2fa6da0695bad5adcb263686459
BLAKE2b-256 fd59e9c0761eef8dca614e57753d3b35fad7761f851e888b77c4051554f2d37a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page