1
0
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:
Daniel Barber 2018-05-12 13:20:47 -04:00
parent 659f748ada
commit fff2c342ff
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
4 changed files with 16 additions and 4 deletions

View File

@ -38,6 +38,10 @@ defmodule Chess.GameState do
|> Board.search(%{"type" => "king", "colour" => colour})
|> List.first
if king == nil do
raise "There is no #{colour} king!"
end
board
|> Piece.attacked?(king)
end

View File

@ -3,7 +3,13 @@ defmodule ChessWeb.PageController do
use ChessWeb, :controller
import Chess.Auth, only: [current_user: 1]
def index(conn, _params) do
render(conn, "index.html")
if current_user(conn) != nil do
conn |> redirect(to: game_path(conn, :index)) |> halt()
else
render(conn, "index.html")
end
end
end

View File

@ -29,7 +29,7 @@ defmodule Chess.Features.GamesTest do
|> click(button("Create game"))
session
|> assert_has(css("h2", text: "Game with Zelda"))
|> assert_has(css("p", text: "Playing Zelda"))
|> assert_has(css(".board"))
end
@ -65,7 +65,7 @@ defmodule Chess.Features.GamesTest do
|> click(link("New game"))
|> select("game[opponent_id]", option: "Urbosa")
|> click(button("Create game"))
|> click(link("Back to games"))
|> click(link("Chess"))
session
|> assert_has(css(".table tr", count: 1))
@ -96,6 +96,6 @@ defmodule Chess.Features.GamesTest do
|> click(link("Game with Zelda"))
session
|> assert_has(css("h2", text: "Game with Zelda"))
|> assert_has(css("p", text: "Playing Zelda"))
end
end

View File

@ -130,6 +130,7 @@ defmodule Chess.Features.MovesTest do
board: %{
"4,0" => %{"type" => "king", "colour" => "white"},
"3,7" => %{"type" => "queen", "colour" => "black"},
"7,7" => %{"type" => "king", "colour" => "black"},
},
user_id: user.id,
opponent_id: opponent.id,
@ -165,6 +166,7 @@ defmodule Chess.Features.MovesTest do
"4,0" => %{"type" => "king", "colour" => "white"},
"4,1" => %{"type" => "rook", "colour" => "white"},
"4,7" => %{"type" => "queen", "colour" => "black"},
"7,7" => %{"type" => "king", "colour" => "black"},
},
user_id: user.id,
opponent_id: opponent.id,