Chess with "Greedy Edi"
07 Nov 2009
(Updated 24 Jan 2012)
Play chess against "Greedy Edi".
function answer = general_legal_move(from, to)
% Confirms wheter a move is legal.
% This means that no figures are in between and no check will occur
% * from ... figure from field, a figure must be on the board!
% * to ... figure to field
% * answer ... 0=not a legal move; 1...legal move
% get Figure
fig = board.figures(from(1),from(2));
[value, handle_chess_figure] = getFigureName(fig);
% See whether figure can be moved
P = handle_chess_figure( 'possible', from );
I = find( sum((P == ones(size(P,1),1)*to),2) == 2, 1 );
if isempty(I), can_be_moved=0; % not legal
else can_be_moved = 1; % legal move
% Examine whether King will be in check
if can_be_moved && ~is_in_check (from, to) % make sure King is not in check
answer = 1; % legal move
answer = 0; % not a legal move