Code covered by the BSD License  

Highlights from
Chess with "Greedy Edi"

image thumbnail

Chess with "Greedy Edi"

by

 

07 Nov 2009 (Updated )

Play chess against "Greedy Edi".

general_legal_move(from, to)
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
%
% Input
% * from ... figure from field, a figure must be on the board!
% * to ... figure to field
% 
% Output
% * answer ... 0=not a legal move; 1...legal move
%

% get Figure
global board;
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
end

% 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
 else
     answer = 0; % not a legal move
 end

Contact us