mirror of
https://github.com/danbee/chess
synced 2025-03-04 08:39:06 +00:00
Boards need a king on both sides
This commit is contained in:
parent
659f748ada
commit
fff2c342ff
@ -38,6 +38,10 @@ defmodule Chess.GameState do
|
|||||||
|> Board.search(%{"type" => "king", "colour" => colour})
|
|> Board.search(%{"type" => "king", "colour" => colour})
|
||||||
|> List.first
|
|> List.first
|
||||||
|
|
||||||
|
if king == nil do
|
||||||
|
raise "There is no #{colour} king!"
|
||||||
|
end
|
||||||
|
|
||||||
board
|
board
|
||||||
|> Piece.attacked?(king)
|
|> Piece.attacked?(king)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -3,7 +3,13 @@ defmodule ChessWeb.PageController do
|
|||||||
|
|
||||||
use ChessWeb, :controller
|
use ChessWeb, :controller
|
||||||
|
|
||||||
|
import Chess.Auth, only: [current_user: 1]
|
||||||
|
|
||||||
def index(conn, _params) do
|
def index(conn, _params) do
|
||||||
|
if current_user(conn) != nil do
|
||||||
|
conn |> redirect(to: game_path(conn, :index)) |> halt()
|
||||||
|
else
|
||||||
render(conn, "index.html")
|
render(conn, "index.html")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|||||||
@ -29,7 +29,7 @@ defmodule Chess.Features.GamesTest do
|
|||||||
|> click(button("Create game"))
|
|> click(button("Create game"))
|
||||||
|
|
||||||
session
|
session
|
||||||
|> assert_has(css("h2", text: "Game with Zelda"))
|
|> assert_has(css("p", text: "Playing Zelda"))
|
||||||
|> assert_has(css(".board"))
|
|> assert_has(css(".board"))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ defmodule Chess.Features.GamesTest do
|
|||||||
|> click(link("New game"))
|
|> click(link("New game"))
|
||||||
|> select("game[opponent_id]", option: "Urbosa")
|
|> select("game[opponent_id]", option: "Urbosa")
|
||||||
|> click(button("Create game"))
|
|> click(button("Create game"))
|
||||||
|> click(link("Back to games"))
|
|> click(link("Chess"))
|
||||||
|
|
||||||
session
|
session
|
||||||
|> assert_has(css(".table tr", count: 1))
|
|> assert_has(css(".table tr", count: 1))
|
||||||
@ -96,6 +96,6 @@ defmodule Chess.Features.GamesTest do
|
|||||||
|> click(link("Game with Zelda"))
|
|> click(link("Game with Zelda"))
|
||||||
|
|
||||||
session
|
session
|
||||||
|> assert_has(css("h2", text: "Game with Zelda"))
|
|> assert_has(css("p", text: "Playing Zelda"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -130,6 +130,7 @@ defmodule Chess.Features.MovesTest do
|
|||||||
board: %{
|
board: %{
|
||||||
"4,0" => %{"type" => "king", "colour" => "white"},
|
"4,0" => %{"type" => "king", "colour" => "white"},
|
||||||
"3,7" => %{"type" => "queen", "colour" => "black"},
|
"3,7" => %{"type" => "queen", "colour" => "black"},
|
||||||
|
"7,7" => %{"type" => "king", "colour" => "black"},
|
||||||
},
|
},
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
opponent_id: opponent.id,
|
opponent_id: opponent.id,
|
||||||
@ -165,6 +166,7 @@ defmodule Chess.Features.MovesTest do
|
|||||||
"4,0" => %{"type" => "king", "colour" => "white"},
|
"4,0" => %{"type" => "king", "colour" => "white"},
|
||||||
"4,1" => %{"type" => "rook", "colour" => "white"},
|
"4,1" => %{"type" => "rook", "colour" => "white"},
|
||||||
"4,7" => %{"type" => "queen", "colour" => "black"},
|
"4,7" => %{"type" => "queen", "colour" => "black"},
|
||||||
|
"7,7" => %{"type" => "king", "colour" => "black"},
|
||||||
},
|
},
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
opponent_id: opponent.id,
|
opponent_id: opponent.id,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user