diff --git a/lib/chess/board.ex b/lib/chess/board.ex index 8dc8d65..b34026a 100644 --- a/lib/chess/board.ex +++ b/lib/chess/board.ex @@ -42,8 +42,8 @@ defmodule Chess.Board do if castling_move?(piece, from_file, to_file) do board |> castling_move(%{ - "from" => [from_file, from_rank], - "to" => [to_file, to_rank] + from: {from_file, from_rank}, + to: {to_file, to_rank} }) |> Map.get(:board) else @@ -65,7 +65,7 @@ defmodule Chess.Board do def castling_move?(_, _, _), do: false - def castling_move(board, %{"from" => [4, rank], "to" => [2, _rank]}) do + def castling_move(board, %{from: {4, rank}, to: {2, _rank}}) do move_piece(board, %{ "from" => [0, rank], "to" => [3, rank] diff --git a/lib/chess/game_state.ex b/lib/chess/game_state.ex index a220de2..76fa64f 100644 --- a/lib/chess/game_state.ex +++ b/lib/chess/game_state.ex @@ -68,7 +68,7 @@ defmodule Chess.GameState do |> Moves.available({file, rank}) |> Enum.all?(fn {to_file, to_rank} -> board - |> Board.move_piece(%{"from" => [file, rank], "to" => [to_file, to_rank]}) + |> Board.move_piece(%{from: {file, rank}, to: {to_file, to_rank}}) |> Map.get(:board) |> king_in_check?(piece["colour"]) end) diff --git a/lib/chess/moves/pieces/king/castling.ex b/lib/chess/moves/pieces/king/castling.ex index 52ec48b..4aafa3d 100644 --- a/lib/chess/moves/pieces/king/castling.ex +++ b/lib/chess/moves/pieces/king/castling.ex @@ -79,7 +79,7 @@ defmodule Chess.Moves.Pieces.King.Castling do [{2, rank}, {3, rank}] |> Enum.any?(fn {to_file, to_rank} -> board - |> Board.move_piece(%{"from" => [4, rank], "to" => [to_file, to_rank]}) + |> Board.move_piece(%{from: {4, rank}, to: {to_file, to_rank}}) |> Map.get(:board) |> GameState.king_in_check?(colour) end) @@ -89,7 +89,7 @@ defmodule Chess.Moves.Pieces.King.Castling do [{5, rank}, {6, rank}] |> Enum.any?(fn {to_file, to_rank} -> board - |> Board.move_piece(%{"from" => [4, rank], "to" => [to_file, to_rank]}) + |> Board.move_piece(%{from: {4, rank}, to: {to_file, to_rank}}) |> Map.get(:board) |> GameState.king_in_check?(colour) end) diff --git a/lib/chess_web/templates/game/board.html.leex b/lib/chess_web/templates/game/board.html.leex index 437d2e6..c5d3ede 100644 --- a/lib/chess_web/templates/game/board.html.leex +++ b/lib/chess_web/templates/game/board.html.leex @@ -1,4 +1,4 @@ -