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

📄 has_moved.m

📁 国际象棋程序,解压到当前目录,在matlab窗口输入chess即可应用
💻 M
字号:
function answer = has_moved(from)
% has_moved  whether the figure was moved once
% Whether the figure was moved once or whether there was any activity on 
% that field.
% 
% This function is required to determine whether the castling is still
% possible.
%
% Inputs:
% * from ... whether a figure has moved "from" that field.
% * global history ... the game history
%
% Outputs:
% * answer ... Boolean answer (true if the figure was moved once).
%
% Example
% Assume you like to do the castling. The the kings method |'possible'|
% will call |has_moved([8 8])|.
%
% See also: King, Chess
%
%% Signature
% Author: W.Garn
% E-Mail: wgarn@yahoo.com
% Date: 2006/03/23 12:00:00 
% 
% Copyright 2006 W.Garn
%
global history
answer = 0;

% white did not move from or to that field!?
k=1;
while ~answer && k<=size(history.white_pos,1)
   if sum(history.white_pos{k,1} == from)==2 || ...
      sum(history.white_pos{k,2} == from)==2
        answer = 1; % has moved
   end
   k=k+1;
end
   
if ~answer
    % black did not move from or to that field!?
    k=1;
    while ~answer && k<=size(history.black_pos,1)
        if sum(history.black_pos{k,1} == from)==2 || ...
           sum(history.black_pos{k,2} == from)==2
               answer = 1; % has moved
        end
       k=k+1;
    end
end

⌨️ 快捷键说明

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