Skip to content

Instantly share code, notes, and snippets.

@mrjoelkemp
Created September 17, 2020 18:03
Show Gist options
  • Save mrjoelkemp/28e1578a87d5995bf01d76cc40d4058e to your computer and use it in GitHub Desktop.
Save mrjoelkemp/28e1578a87d5995bf01d76cc40d4058e to your computer and use it in GitHub Desktop.
defmodule Game do
require Board
defstruct board: %Board{}
def is_complete?(%Game{ board: board } = game) do
Board.has_winner?(board) or Board.is_draw?(board)
end
end
defmodule Board do
# Positions with the x coord and y coord separated by an underscore
defstruct "0_0": "", "0_1": "", ...
def has_winner?(%Board{} = board) do
# All that logic to check for TicTacToe win states
end
def is_draw?(%Board{} = board) do
# All that logic to check for all positions taken with no winner
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment