<commit_before>defmodule Hangman.Game do
  defstruct(
    turns_left: 7,
    game_state: :initializing,
    letters: [],
    used: MapSet.new,
  )

  def new_game(word) do
    %Hangman.Game{
      letters: word |> String.codepoints
    }
  end

  def new_game do
    new_game(Dictionary.random_word(Dictionary.start))
  end

  def tally(game) do
    %{
      game_state: game.game_state,
      turns_left: game.turns_left,
      letters: game.letters |> reveal_guessed(game.used),
      letters_used: MapSet.to_list(game.used)
    }
  end

  def make_move(game = %{ game_state: state }, _guess) when state in [:won, :lost] do
    game
  end

  def make_move(game, guess) do
    accept_move(game, guess, MapSet.member?(game.used, guess))
  end

  ####################

  defp accept_move(game, _guess, _already_guest = true) do
    Map.put(game, :game_state, :already_used)
  end<commit_msg>:hammer: we don't need to call Dictionary.start anymore<commit_after>defmodule Hangman.Game do
  defstruct(
    turns_left: 7,
    game_state: :initializing,
    letters: [],
    used: MapSet.new,
  )

  def new_game(word) do
    %Hangman.Game{
      letters: word |> String.codepoints
    }
  end

  def new_game do
    new_game(Dictionary.random_word)
  end

  def tally(game) do
    %{
      game_state: game.game_state,
      turns_left: game.turns_left,
      letters: game.letters |> reveal_guessed(game.used),
      letters_used: MapSet.to_list(game.used)
    }
  end

  def make_move(game = %{ game_state: state }, _guess) when state in [:won, :lost] do
    game
  end

  def make_move(game, guess) do
    accept_move(game, guess, MapSet.member?(game.used, guess))
  end

  ####################

  defp accept_move(game, _guess, _already_guest = true) do
    Map.put(game, :game_state, :already_used)
  end
{'fraction_non_alphanumeric': 0.12915742793791574, 'fraction_numerical': 0.0011086474501108647, 'mean_word_length': 3.217289719626168, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3350445', 'n_tokens_mistral': 674, 'n_tokens_neox': 647, 'n_words': 144}