Skip to content

Instantly share code, notes, and snippets.

@Lakret
Created February 28, 2019 01:17
Show Gist options
  • Save Lakret/604bc05addabdffab4413eae46812dda to your computer and use it in GitHub Desktop.
Save Lakret/604bc05addabdffab4413eae46812dda to your computer and use it in GitHub Desktop.
Level 1. Improved naming
defmodule Chess do
alias Chess.{Board, Player, Move, Interaction}
def play() do
play(Board.init(), Player.first_turn(), 0)
end
def play(board, player, turn) do
move = Interaction.read_move(player)
case Move.execute(move, board, player) do
{:ok, new_board} ->
if Board.checkmate?(new_board) do
Interaction.victory(player, turn)
else
play(board, Player.next(player), turn + 1)
end
{:error, illegal_move} ->
Interaction.illegal_move(player, illegal_move)
play(board, player, turn)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment