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

📄 findpos.m

📁 国际象棋程序,解压到当前目录,在matlab窗口输入chess即可应用
💻 M
字号:
function p = findPos(from, pos)
% findPos  returns the first index, where 'pos' was found in 'from'
% The first index of "pos" within "from" is returned.
% Note: this function was originally designed to return the index set.
%
% This function is central to all chess figures. It helps identifying the
% instance within the figure class.
%
% Inputs:
% * from ... array of positions
% * pos ... the position to find
%
% Outputs:
% * p ... returns the first index, where 'pos' was found in 'from'
%
% Example
% Given are four positions, we want to know the first occurence of [3 4].
%+ p = findPos([[1 2];[3 4]; [4 4]; [3 4]],  [3 4])
%
% See also: King, Queen, Knight, Bishop, Rook, Pawn
%
%% Signature
% Author: W.Garn
% E-Mail: wgarn@yahoo.com
% Date: 2006/03/23 12:00:00 
% 
% Copyright 2006 W.Garn
%
I=[];
for j=1:size(from,1)
    if pos(1)==from(j,1) && pos(2)==from(j,2)
        I=[I j];
    end
end
if ~isempty(I)
    p = I(1);
else
    p=[];
end

⌨️ 快捷键说明

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