Created
February 28, 2019 01:17
-
-
Save Lakret/604bc05addabdffab4413eae46812dda to your computer and use it in GitHub Desktop.
Level 1. Improved naming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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