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".

c2m(chessMove)
function matrixMove = c2m(chessMove)
% c2m converts a chess move (e.g. d2-d4 to a matrix move)
%
% Inputs:
% * chessMove ... chess move (e.g. 'd2-d4')
%
% Outputs:
% * matrixMove ... move in matrix notation, BUT is a cell array (e.g. 'd2-d4' becomes {[7 4],[5 4]})
%
% Example
% Transform a chess move to a matrix move
%+ ca = c2m('d2-d4') % i.e. ca{1}=[7,4] and ca{2}=[5,4]
%
% Note: this function is pretty robust allows 'D7-e1', ' d  3-  D4' or 'e2e4' 
% Application: Can be used to move chess figures using the stopCursor function, 
%   for instance stopCursor( c2m('d2-d4') )
%
% See also: matrix2xy, xy2matrix, chess2matrix, matrix2chess, stopCursor
%
%% Signature
% Author: W.Garn
% E-Mail: wgarn@yahoo.com
% Date: 2010/11/11 12:00:00 
% 
% Copyright 2010 W.Garn
%
chessMove = strrep(strtrim(lower(chessMove)),' ',''); % quite a bit of preprocessing
from = chessMove(1:2);
to = strrep(chessMove(3:end),'-','');
[row, col] = chess2matrix(from);
matrixMove{1} = [row, col];
[row, col] = chess2matrix(to);
matrixMove{2} = [row, col];

Contact us