1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00

Make code clearer

This commit is contained in:
Daniel Barber 2018-03-13 22:45:13 -04:00
parent 682ce67652
commit bfa49b48b6
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8

View File

@ -3,28 +3,29 @@ defmodule Chess.Moves.Pawn do
def moves(board, {file, rank}) do def moves(board, {file, rank}) do
board["#{file},#{rank}"] board["#{file},#{rank}"]
|> Map.get("colour")
|> _moves(board, {file, rank}) |> _moves(board, {file, rank})
end end
defp _moves(%{"colour" => "white"}, board, {file, rank}) do defp _moves("white", board, {file, rank}) do
cond do cond do
obstruction?(board, {file, rank + 1}) -> [] obstruction?(board, {file, rank + 1}) ->
rank == 1 -> [ []
{file, rank + 1} | rank == 1 ->
_moves(%{"colour" => "white"}, board, {file, rank + 1}) [{file, rank + 1} | _moves("white", board, {file, rank + 1})]
] true ->
true -> [{file, rank + 1}] [{file, rank + 1}]
end end
end end
defp _moves(%{"colour" => "black"}, board, {file, rank}) do defp _moves("black", board, {file, rank}) do
cond do cond do
obstruction?(board, {file, rank - 1}) -> [] obstruction?(board, {file, rank - 1}) ->
rank == 6 -> [ []
{file, rank - 1} | rank == 6 ->
_moves(%{"colour" => "black"}, board, {file, rank - 1}) [{file, rank - 1} | _moves("black", board, {file, rank - 1})]
] true ->
true -> [{file, rank - 1}] [{file, rank - 1}]
end end
end end