Merge default changeset on all status
This commit is contained in:
parent
118e62e760
commit
06411cc442
@ -294,39 +294,41 @@ defmodule Chessh.SSH.Client.Game do
|
|||||||
attempted_move
|
attempted_move
|
||||||
) do
|
) do
|
||||||
{:ok, status} ->
|
{:ok, status} ->
|
||||||
case status do
|
|
||||||
:continue ->
|
|
||||||
{:ok, fen} = :binbo.get_fen(binbo_pid)
|
{:ok, fen} = :binbo.get_fen(binbo_pid)
|
||||||
|
|
||||||
{:ok, _new_game} =
|
default_changeset = %{
|
||||||
Game.changeset(
|
|
||||||
game,
|
|
||||||
%{
|
|
||||||
fen: fen,
|
fen: fen,
|
||||||
moves: game.moves + 1,
|
moves: game.moves + 1,
|
||||||
turn: if(game.turn == :dark, do: :light, else: :dark)
|
turn: if(game.turn == :dark, do: :light, else: :dark)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case status do
|
||||||
|
:continue ->
|
||||||
|
{:ok, _new_game} =
|
||||||
|
Game.changeset(
|
||||||
|
game,
|
||||||
|
default_changeset
|
||||||
)
|
)
|
||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
|
|
||||||
{:draw, _} ->
|
{:draw, _} ->
|
||||||
Game.changeset(
|
Game.changeset(
|
||||||
game,
|
game,
|
||||||
%{status: :draw}
|
Map.merge(default_changeset, %{status: :draw})
|
||||||
)
|
)
|
||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
|
|
||||||
{:checkmate, :white_wins} ->
|
{:checkmate, :white_wins} ->
|
||||||
Game.changeset(
|
Game.changeset(
|
||||||
game,
|
game,
|
||||||
%{status: :winner, winner: :light}
|
Map.merge(default_changeset, %{status: :winner, winner: :light})
|
||||||
)
|
)
|
||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
|
|
||||||
{:checkmate, :black_wins} ->
|
{:checkmate, :black_wins} ->
|
||||||
Game.changeset(
|
Game.changeset(
|
||||||
game,
|
game,
|
||||||
%{status: :winner, winner: :dark}
|
Map.merge(default_changeset, %{status: :winner, winner: :dark})
|
||||||
)
|
)
|
||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user