File tree Expand file tree Collapse file tree 1 file changed +32
-3
lines changed
src/bin/chessmarkable/scene Expand file tree Collapse file tree 1 file changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -886,9 +886,38 @@ impl Scene for GameScene {
886886 self . selected_square = None ;
887887 self . clear_move_hints ( ) ;
888888 } else {
889- // Move
890- self . redraw_squares . insert ( new_square. clone ( ) ) ;
891- self . on_user_move ( last_selected_square, new_square) ;
889+ // Attempt to move from last_selected_square to new_square if move is
890+ // in self.possible_moves. Otherwise just select the piece on new_square.
891+ // See https://github.com/LinusCDE/chessmarkable/issues/14
892+ let is_possible_move = self
893+ . possible_moves
894+ . iter ( )
895+ . any ( |( possible_src, possible_dest) | {
896+ possible_src == & last_selected_square
897+ && possible_dest == & new_square
898+ } ) ;
899+ if is_possible_move {
900+ // Move
901+ self . redraw_squares . insert ( new_square. clone ( ) ) ;
902+ self . on_user_move (
903+ last_selected_square,
904+ new_square,
905+ ) ;
906+ } else {
907+ // Select new_square as new selected piece
908+ if self . board . piece_at_sq ( * new_square)
909+ != Piece :: None
910+ {
911+ self . selected_square = Some ( new_square) ;
912+ self . redraw_squares
913+ . insert ( new_square. clone ( ) ) ;
914+ self . set_move_hints ( new_square) ;
915+ } else {
916+ // Clear selection
917+ self . selected_square = None ;
918+ self . clear_move_hints ( ) ;
919+ }
920+ }
892921 }
893922 } else {
894923 let finger_down_square = self
You can’t perform that action at this time.
0 commit comments