Git Product home page Git Product logo

wordle-cypress's Introduction

Wordle Solver with Cypress

Wordle was taking so much time! So, I've written my own automation to play it for me with Cypress, JavaScript and a list of 2,315 words. Here's the results.

Yes, the world is playing it so I've succumbed. I've been playing Wordle. It's irresistible and you only get one word a day, all part of the magic.

But it's also an irritating distraction, so the solution is automation. As Abraham Maslow said, 'when all you have is a hammer, everything looks like a nail'. Well said, and it does indeed look like a nail.

So, I've fired up VS Code; together with some Javascript, Cypress and the list of 2,315 words Wordle uses for its answers. Here's the result.

Details with video

Solving Wordle with Cypress

The Approach

Cypress is a great tool with good documentation, and I wanted to experiment with it. I structured the code into two classes:

PageActions class This handles the page interaction; button clicks, reads and records the response from Wordle. The shadow DOM on the Wordle page allows extraction of the score for each attempt: Green (correct), Yellow (present) and Grey (absent).

Solver class The Solver class uses the list of 2,315 words that Wordle uses for its answers. It loads these into an array and as the responses come back it eliminates words from this array to narrow down to the correct solution. As starting point, it uses STARE as its first word, a reasonable first guess I feel. I've read some analysis that other words might be better, ADIEU for example but I'll perhaps experiment with others later. Using the feedback from PageActions these word array is pruned; when a letter is correct then eliminate all words that letter(s) aren't in that position, where is present remove all word that don't contain it and that have that leter in that position and where a letter is absent then remove all words containing it. When making a guess if possible use a word with no repeat letters as that maximises our elimination or confirmation of letters.

This approach works well enough usually solving with four attempts which I feel is par for the puzzle. It could be improved using Information as Theory explained in the excellent 3Blue1Brown Solving Wordle using information theory but that's for another day.

Usage

git clone https://github.com/chrisrryan/wordle-cypress.git
cd wordle-cypress
npm install
npx cypress open

Then, click wordle_spec.js when the Cypress test runner starts.

wordle-cypress's People

Contributors

chrisrryan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.