From 6c944243fb376b03bc2d9eb6626868d64c780715 Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Sun, 18 Mar 2018 10:31:34 -0400 Subject: [PATCH] Re-organise pieces --- lib/chess/moves.ex | 12 +++++----- lib/chess/moves/piece.ex | 2 +- lib/chess/moves/{ => pieces}/bishop.ex | 2 +- lib/chess/moves/{ => pieces}/king.ex | 2 +- lib/chess/moves/{ => pieces}/knight.ex | 2 +- lib/chess/moves/{ => pieces}/pawn.ex | 2 +- lib/chess/moves/{ => pieces}/queen.ex | 6 ++--- lib/chess/moves/{ => pieces}/rook.ex | 2 +- test/chess/moves/{ => pieces}/bishop_test.exs | 2 +- test/chess/moves/{ => pieces}/king_test.exs | 2 +- test/chess/moves/{ => pieces}/knight_test.exs | 2 +- test/chess/moves/{ => pieces}/pawn_test.exs | 22 +++++++++---------- test/chess/moves/{ => pieces}/queen_test.exs | 2 +- test/chess/moves/{ => pieces}/rook_test.exs | 2 +- 14 files changed, 31 insertions(+), 31 deletions(-) rename lib/chess/moves/{ => pieces}/bishop.ex (88%) rename lib/chess/moves/{ => pieces}/king.ex (87%) rename lib/chess/moves/{ => pieces}/knight.ex (86%) rename lib/chess/moves/{ => pieces}/pawn.ex (97%) rename lib/chess/moves/{ => pieces}/queen.ex (58%) rename lib/chess/moves/{ => pieces}/rook.ex (89%) rename test/chess/moves/{ => pieces}/bishop_test.exs (97%) rename test/chess/moves/{ => pieces}/king_test.exs (96%) rename test/chess/moves/{ => pieces}/knight_test.exs (96%) rename test/chess/moves/{ => pieces}/pawn_test.exs (82%) rename test/chess/moves/{ => pieces}/queen_test.exs (97%) rename test/chess/moves/{ => pieces}/rook_test.exs (97%) diff --git a/lib/chess/moves.ex b/lib/chess/moves.ex index da153ae..0441835 100644 --- a/lib/chess/moves.ex +++ b/lib/chess/moves.ex @@ -1,12 +1,12 @@ defmodule Chess.Moves do @moduledoc false - alias Chess.Moves.Pawn - alias Chess.Moves.Bishop - alias Chess.Moves.Knight - alias Chess.Moves.Rook - alias Chess.Moves.Queen - alias Chess.Moves.King + alias Chess.Moves.Pieces.Pawn + alias Chess.Moves.Pieces.Bishop + alias Chess.Moves.Pieces.Knight + alias Chess.Moves.Pieces.Rook + alias Chess.Moves.Pieces.Queen + alias Chess.Moves.Pieces.King def available(board, {file, rank}) do piece = board["#{file},#{rank}"] diff --git a/lib/chess/moves/piece.ex b/lib/chess/moves/piece.ex index f107bb5..18c8fca 100644 --- a/lib/chess/moves/piece.ex +++ b/lib/chess/moves/piece.ex @@ -2,7 +2,7 @@ defmodule Chess.Moves.Piece do @moduledoc false alias Chess.Moves.Generator - alias Chess.Moves.Knight + alias Chess.Moves.Pieces.Knight def attacked?(board, {file, rank}) do attacked_by_rook_or_queen?(board, {file, rank}) || diff --git a/lib/chess/moves/bishop.ex b/lib/chess/moves/pieces/bishop.ex similarity index 88% rename from lib/chess/moves/bishop.ex rename to lib/chess/moves/pieces/bishop.ex index f4e590f..512dcf2 100644 --- a/lib/chess/moves/bishop.ex +++ b/lib/chess/moves/pieces/bishop.ex @@ -1,4 +1,4 @@ -defmodule Chess.Moves.Bishop do +defmodule Chess.Moves.Pieces.Bishop do @moduledoc false alias Chess.Moves.Generator diff --git a/lib/chess/moves/king.ex b/lib/chess/moves/pieces/king.ex similarity index 87% rename from lib/chess/moves/king.ex rename to lib/chess/moves/pieces/king.ex index 4d482b2..77b56f7 100644 --- a/lib/chess/moves/king.ex +++ b/lib/chess/moves/pieces/king.ex @@ -1,4 +1,4 @@ -defmodule Chess.Moves.King do +defmodule Chess.Moves.Pieces.King do @moduledoc false alias Chess.Moves.Generator diff --git a/lib/chess/moves/knight.ex b/lib/chess/moves/pieces/knight.ex similarity index 86% rename from lib/chess/moves/knight.ex rename to lib/chess/moves/pieces/knight.ex index c521b67..9615b3e 100644 --- a/lib/chess/moves/knight.ex +++ b/lib/chess/moves/pieces/knight.ex @@ -1,4 +1,4 @@ -defmodule Chess.Moves.Knight do +defmodule Chess.Moves.Pieces.Knight do @moduledoc false alias Chess.Moves.Generator diff --git a/lib/chess/moves/pawn.ex b/lib/chess/moves/pieces/pawn.ex similarity index 97% rename from lib/chess/moves/pawn.ex rename to lib/chess/moves/pieces/pawn.ex index b134217..b2f7c47 100644 --- a/lib/chess/moves/pawn.ex +++ b/lib/chess/moves/pieces/pawn.ex @@ -1,4 +1,4 @@ -defmodule Chess.Moves.Pawn do +defmodule Chess.Moves.Pieces.Pawn do @moduledoc false def moves(board, {file, rank}) do diff --git a/lib/chess/moves/queen.ex b/lib/chess/moves/pieces/queen.ex similarity index 58% rename from lib/chess/moves/queen.ex rename to lib/chess/moves/pieces/queen.ex index 6061046..8f881b0 100644 --- a/lib/chess/moves/queen.ex +++ b/lib/chess/moves/pieces/queen.ex @@ -1,8 +1,8 @@ -defmodule Chess.Moves.Queen do +defmodule Chess.Moves.Pieces.Queen do @moduledoc false - alias Chess.Moves.Rook - alias Chess.Moves.Bishop + alias Chess.Moves.Pieces.Rook + alias Chess.Moves.Pieces.Bishop def moves(board, {file, rank}) do Rook.moves(board, {file, rank}) ++ diff --git a/lib/chess/moves/rook.ex b/lib/chess/moves/pieces/rook.ex similarity index 89% rename from lib/chess/moves/rook.ex rename to lib/chess/moves/pieces/rook.ex index 4d79372..6283e15 100644 --- a/lib/chess/moves/rook.ex +++ b/lib/chess/moves/pieces/rook.ex @@ -1,4 +1,4 @@ -defmodule Chess.Moves.Rook do +defmodule Chess.Moves.Pieces.Rook do @moduledoc false alias Chess.Moves.Generator diff --git a/test/chess/moves/bishop_test.exs b/test/chess/moves/pieces/bishop_test.exs similarity index 97% rename from test/chess/moves/bishop_test.exs rename to test/chess/moves/pieces/bishop_test.exs index 9ffa149..11197b6 100644 --- a/test/chess/moves/bishop_test.exs +++ b/test/chess/moves/pieces/bishop_test.exs @@ -1,4 +1,4 @@ -defmodule Chess.Moves.BishopTest do +defmodule Chess.Moves.Pieces.BishopTest do use Chess.DataCase alias Chess.Moves diff --git a/test/chess/moves/king_test.exs b/test/chess/moves/pieces/king_test.exs similarity index 96% rename from test/chess/moves/king_test.exs rename to test/chess/moves/pieces/king_test.exs index 5a2cfe5..94520f4 100644 --- a/test/chess/moves/king_test.exs +++ b/test/chess/moves/pieces/king_test.exs @@ -1,4 +1,4 @@ -defmodule Chess.Moves.KingTest do +defmodule Chess.Moves.Pieces.KingTest do use Chess.DataCase alias Chess.Moves diff --git a/test/chess/moves/knight_test.exs b/test/chess/moves/pieces/knight_test.exs similarity index 96% rename from test/chess/moves/knight_test.exs rename to test/chess/moves/pieces/knight_test.exs index f89042d..dc62d38 100644 --- a/test/chess/moves/knight_test.exs +++ b/test/chess/moves/pieces/knight_test.exs @@ -1,4 +1,4 @@ -defmodule Chess.Moves.KnightTest do +defmodule Chess.Moves.Pieces.KnightTest do use Chess.DataCase alias Chess.Moves diff --git a/test/chess/moves/pawn_test.exs b/test/chess/moves/pieces/pawn_test.exs similarity index 82% rename from test/chess/moves/pawn_test.exs rename to test/chess/moves/pieces/pawn_test.exs index e1827fb..461a402 100644 --- a/test/chess/moves/pawn_test.exs +++ b/test/chess/moves/pieces/pawn_test.exs @@ -1,17 +1,17 @@ -defmodule Chess.Moves.PawnTest do +defmodule Chess.Moves.Pieces.PawnTest do use Chess.DataCase - alias Chess.Moves.Pawn + alias Chess.Moves test "white pawn can move forward one or two spaces" do - moves = Pawn.moves(default_board(), {4, 1}) + moves = Moves.available(default_board(), {4, 1}) expected_moves = [{4, 2}, {4, 3}] assert moves == expected_moves end test "black pawn can move forward one or two spaces" do - moves = Pawn.moves(default_board(), {4, 6}) + moves = Moves.available(default_board(), {4, 6}) expected_moves = [{4, 5}, {4, 4}] assert moves == expected_moves @@ -19,7 +19,7 @@ defmodule Chess.Moves.PawnTest do test "white pawn not on starting square can move forward one space" do board = %{"4,2" => %{"type" => "pawn", "colour" => "white"}} - moves = Pawn.moves(board, {4, 2}) + moves = Moves.available(board, {4, 2}) expected_moves = [{4, 3}] assert moves == expected_moves @@ -27,7 +27,7 @@ defmodule Chess.Moves.PawnTest do test "black pawn not on starting square can move forward one space" do board = %{"4,5" => %{"type" => "pawn", "colour" => "black"}} - moves = Pawn.moves(board, {4, 5}) + moves = Moves.available(board, {4, 5}) expected_moves = [{4, 4}] assert moves == expected_moves @@ -38,7 +38,7 @@ defmodule Chess.Moves.PawnTest do "4,1" => %{"type" => "pawn", "colour" => "white"}, "4,3" => %{"type" => "pawn", "colour" => "black"}, } - moves = Pawn.moves(board, {4, 1}) + moves = Moves.available(board, {4, 1}) expected_moves = [{4, 2}] assert moves == expected_moves @@ -49,7 +49,7 @@ defmodule Chess.Moves.PawnTest do "4,1" => %{"type" => "pawn", "colour" => "white"}, "4,2" => %{"type" => "pawn", "colour" => "black"}, } - moves = Pawn.moves(board, {4, 1}) + moves = Moves.available(board, {4, 1}) expected_moves = [] assert moves == expected_moves @@ -60,7 +60,7 @@ defmodule Chess.Moves.PawnTest do "4,2" => %{"type" => "pawn", "colour" => "white"}, "4,3" => %{"type" => "pawn", "colour" => "black"}, } - moves = Pawn.moves(board, {4, 2}) + moves = Moves.available(board, {4, 2}) expected_moves = [] assert moves == expected_moves @@ -71,7 +71,7 @@ defmodule Chess.Moves.PawnTest do "4,2" => %{"type" => "pawn", "colour" => "white"}, "5,3" => %{"type" => "pawn", "colour" => "black"}, } - moves = Pawn.moves(board, {4, 2}) + moves = Moves.available(board, {4, 2}) expected_moves = [{4, 3}, {5, 3}] assert moves == expected_moves @@ -82,7 +82,7 @@ defmodule Chess.Moves.PawnTest do "6,6" => %{"type" => "pawn", "colour" => "black"}, "5,5" => %{"type" => "pawn", "colour" => "white"}, } - moves = Pawn.moves(board, {6, 6}) + moves = Moves.available(board, {6, 6}) expected_moves = [{6, 5}, {6, 4}, {5, 5}] assert moves == expected_moves diff --git a/test/chess/moves/queen_test.exs b/test/chess/moves/pieces/queen_test.exs similarity index 97% rename from test/chess/moves/queen_test.exs rename to test/chess/moves/pieces/queen_test.exs index 7bc105e..9e1fef6 100644 --- a/test/chess/moves/queen_test.exs +++ b/test/chess/moves/pieces/queen_test.exs @@ -1,4 +1,4 @@ -defmodule Chess.Moves.QueenTest do +defmodule Chess.Moves.Pieces.QueenTest do use Chess.DataCase alias Chess.Moves diff --git a/test/chess/moves/rook_test.exs b/test/chess/moves/pieces/rook_test.exs similarity index 97% rename from test/chess/moves/rook_test.exs rename to test/chess/moves/pieces/rook_test.exs index 0927158..e08646d 100644 --- a/test/chess/moves/rook_test.exs +++ b/test/chess/moves/pieces/rook_test.exs @@ -1,4 +1,4 @@ -defmodule Chess.Moves.RookTest do +defmodule Chess.Moves.Pieces.RookTest do use Chess.DataCase alias Chess.Moves