⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 legal_move.m

📁 国际象棋程序,解压到当前目录,在matlab窗口输入chess即可应用
💻 M
字号:
function answer = legal_move
% legal_move  checks whether a move is legal.
% It is checked whether a chess figures move (stored in global structure
% cursor) is legal or not.
%
% Note: That this function calls the chess figure class identified by the
% figure which is on the "from" field.
% This function is called from the stopCursor event-function.
%
% Inputs:
% * global cursor ... cursor information (contains the move "from" "to")
% * global board ... chess board and related information 
%
% Outputs:
% * answer ... Boolean answer (1... legal move, 0 ... not allowed)
%
% Example
% Assume there is a global board information, describing the chess board
% and a global cursor structure. The cursor structure contains the fields
% from and to. The function |legal_move| will check whether the move
% "cursor.from" to "cursor.to" is legal.
%
% See also: King, Queen, Knight, Bishop, Rook, Pawn, stopCursor
%
%% Signature
% Author: W.Garn
% E-Mail: wgarn@yahoo.com
% Date: 2006/03/23 12:00:00 
% 
% Copyright 2006 W.Garn
%
global cursor
global board
answer = 0;
% determine color and figure of originating move
if ~isempty(cursor.from)
    f = board.figures(cursor.from(1),cursor.from(2));
    %color = getColor( cursor.from );
    [name, handle_chess_figure] = getFigureName(f);
    if ~isempty(handle_chess_figure)
        answer = handle_chess_figure('legal_move',cursor.from, cursor.to);
    else
        answer = 0;
    end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -