Skip to content

Latest commit

 

History

History
192 lines (142 loc) · 6.22 KB

games_wordle.livemd

File metadata and controls

192 lines (142 loc) · 6.22 KB

Games: Wordle

Mix.install([
  {:jason, "~> 1.4"},
  {:kino, "~> 0.9", override: true},
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"}
])

Navigation

Games: Wordle

Requirements

In your existing Games project, you're going to create a Wordle game.

Wordle is a popular game where players get six attempts to guess a word. They are given feedback clues to guess the word.

  • Green if the letter is in the word and in the correct spot.
  • Yellow if the letter is in the word but in the incorrect spot.
  • Gray if the letter is not in the word.

For example for the word "TOAST" the guess "TARTS" would be

flowchart LR
style 1 fill:green
style 2 fill:yellow
style 3 fill:gray
style 4 fill:yellow
style 5 fill:yellow

1[T] --- 2[A] --- 3[R] --- 4[T] --- 5[S]
Loading

Tests

You're going to create a full test suite for the wordle game. Write (at least) the following test cases

  • All green
  • All yellow
  • All grey
  • some green, yellow, and grey

Bonus: Edge Case: same letter is all 3 colors

Games.Wordle.feedback("XXXAA", "AAAAY") == [:yellow, :grey, :grey, :green, :grey]

Handle greens first, then fill out yellows in order. The remaining characters are grey.

Be warned, this is a hard bonus challenge that significantly increases the complexity of the solution. Consider solving the exercise without this edge-case first.

Feedback/0

You should be able to start your project by running the following from the game folder in the command line.

iex -S mix

Given an answer and a guess, your Games.Wordle module will provide feedback as a list of color atoms :green, :yellow, and :grey.

                         #answer   #guess
iex> Games.Wordle.feedback("aaaaa", "aaaaa")
[:green, :green, :green, :green, :green]

iex> Games.Wordle.feedback("aaaaa", "aaaab")
[:green, :green, :green, :green, :grey]

iex> Games.Wordle.feedback("abdce", "edcba")
[:yellow, :yellow, :yellow, :yellow, :yellow]

# If There Are Duplicate Characters In The Guess Prioritize Exact Matches.
iex> Games.Wordle.feedback("aaabb", "xaaaa")
[:grey, :green, :green, :yellow, :grey]

Play

Use the IEx shell to start a game of Wordle. This should prompt the user to guess a five letter word.

iex> Games.Wordle.play()
Enter a five letter word:  

Randomly generate a word for the wordle game. You might randomly retrieve a word from a list of words such as ["toast", "tarts", "hello", "beats"].

Retrieve user input and provide feedback based on their guess. For example, this would be the output if the word toast were randomly generated.

Enter a five letter word: tarts
[:green, :yellow, :grey, :yellow, :yellow]

Bonus: Six Guesses

After six guesses, the player should lose the game if they do not get the correct answer.

Bonus: Color Feedback

Use IO.ANSI to provide actual colored feedback.

IO.puts(IO.ANSI.green() <> "green")
IO.puts(IO.ANSI.yellow() <> "yellow")
IO.puts(IO.ANSI.light_black() <> "grey")

Make sure you reset the color.

IO.puts(IO.ANSI.green() <> "green" <> IO.ANSI.reset() <> " reset color")

Commit Your Progress

DockYard Academy now recommends you use the latest Release rather than forking or cloning our repository.

Run git status to ensure there are no undesirable changes. Then run the following in your command line from the curriculum folder to commit your progress.

$ git add .
$ git commit -m "finish Games: Wordle exercise"
$ git push

We're proud to offer our open-source curriculum free of charge for anyone to learn from at their own pace.

We also offer a paid course where you can learn from an instructor alongside a cohort of your peers. We will accept applications for the June-August 2023 cohort soon.

Navigation