summaryrefslogtreecommitdiff
path: root/lib/chessh/ssh/client/game/game.ex
diff options
context:
space:
mode:
authorSimponic <loganhunt@simponic.xyz>2023-02-01 17:36:39 -0700
committerGitHub <noreply@github.com>2023-02-01 17:36:39 -0700
commita26256700d93392dfc92bfc6dc6842dac842cc15 (patch)
treeb4a298d080dc13ed839f9152f8ad3f8ec6d58d32 /lib/chessh/ssh/client/game/game.ex
parente05a6d36bb62dae878be254416e7652995e94602 (diff)
downloadchessh-a26256700d93392dfc92bfc6dc6842dac842cc15.tar.gz
chessh-a26256700d93392dfc92bfc6dc6842dac842cc15.zip
Do not send notifications when game is over & fix promotion screen (#15)
Diffstat (limited to 'lib/chessh/ssh/client/game/game.ex')
-rw-r--r--lib/chessh/ssh/client/game/game.ex26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/chessh/ssh/client/game/game.ex b/lib/chessh/ssh/client/game/game.ex
index fc48d6f..d6b0b5b 100644
--- a/lib/chessh/ssh/client/game/game.ex
+++ b/lib/chessh/ssh/client/game/game.ex
@@ -262,22 +262,21 @@ defmodule Chessh.SSH.Client.Game do
do: Renderer.flip({new_cursor.y, new_cursor.x}),
else: {new_cursor.y, new_cursor.x}
- piece_type =
- :binbo_position.get_piece(
- :binbo_board.notation_to_index(Renderer.to_chess_coord(maybe_flipped_cursor_tup)),
- :binbo.game_state(binbo_pid)
- )
-
{new_move_from, move_to} =
if action == :return do
coords = {new_cursor.y, new_cursor.x}
case move_from do
nil ->
- if piece_type != 0 do
- {coords, nil}
- else
+ if :binbo_position.get_piece(
+ :binbo_board.notation_to_index(
+ Renderer.to_chess_coord(maybe_flipped_cursor_tup)
+ ),
+ :binbo.game_state(binbo_pid)
+ ) == 0 do
{move_from, nil}
+ else
+ {coords, nil}
end
_ ->
@@ -307,10 +306,15 @@ defmodule Chessh.SSH.Client.Game do
})
if move_from && move_to do
- maybe_flipped_to = if flipped, do: Renderer.flip(move_to), else: move_to
+ [maybe_flipped_to, maybe_flipped_from] =
+ [move_to, move_from]
+ |> Enum.map(fn coord -> if flipped, do: Renderer.flip(coord), else: coord end)
promotion_possible =
- case piece_type do
+ case :binbo_position.get_piece(
+ :binbo_board.notation_to_index(Renderer.to_chess_coord(maybe_flipped_from)),
+ :binbo.game_state(binbo_pid)
+ ) do
1 ->
# Light pawn
{y, _} = maybe_flipped_to