Search⌘ K
AI Features

Hits and Misses

Explore how to build functions to track hits and misses in a game using Elixir. Understand how to update guesses with coordinates, use pattern matching to separate hits and misses, and ensure game state integrity. This lesson helps you implement data management that supports game logic effectively.

We'll cover the following...

Let’s define the functions we need to play the game in each module we’ve covered so far. Coordinates don’t need any more functionality.

Let’s begin with guesses.

Keep track of guesses

As players guess coordinates in the game, we need to keep track of those guesses to accurately represent their opponent’s board. We’ll need to add the guessed coordinates but not remove them.

We need a function to add the guessed coordinates to a Guesses struct and determine whether they go into the set of the hits or of the misses. We’ll ...