File Exchange

image thumbnail

Chess with "Greedy Edi"

version 1.2 (553 KB) by

Play chess against "Greedy Edi".

5 Downloads

Updated

View License

Play chess against "Greedy Edi".

Get started...
1. extract zip file
2. change current directory to the new "chess" directory
3. Run "Chess" (optionally for text figures run Chess(2))

Some help ...
a) How to move the chess pieces ...
1. Position the mouse over the figure you like to move
2. Press the mouse button and keep it pressed
3. Move the mouse over the desired field and relase the mouse button
b) How to play chess ...
If you don't know anything about chess. I have included a little chess
tutorial (ChessTutorial.pdf).

c) Help about the functions
If you like to change the program or if you like to know more about the
implementation, then check out the html folder for help descriptions on
the functions. The "index.html" file gives an overview of all the functions
used. This help files were generated by using the "wg_publish_dir"
function, which can be found at the Central File Exchange Depot.
(http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=9687&objectType=FILE)


What I still intend to do...
- let "Greedy Edi" realize, when he is checked, that he can do
something else beside running away.
Additional Edi characters
a) Careful Edi ... which looks out, whether he will be eaten
b) Happy Edi ... looking tow and a half move ahead
c) Smart Edi ... knowing strategy, tricks and learning on its own

How could you help me...
1. By testing this program and telling me any wrong moves (wgarn@yahoo.com)
x2. There is a transparency issue, which I could not figure out ...
A transparent image with a patch as background colour???
I have include a m-script (TransparencyProblem.m), illustrating the problem.
-> Thank's to Jérôme. This problem is solved.
Add 2nd axes and send them to the back :)
3. Finding other chess sets
4. Other constructive comments and contributions ;)

I am proud of the following...
1. a kind of Matlab object orientated alternative concept ...
The chess figures m-functions represent objects. Of course I know that
Matlab offers OO programming. But, I do not like copying everything. Hence
I came out with the "persistent" structure idea.
For instance, let us have a look at the knights.
First we have only the "empty" function, which I call class.
When calling the function "Knight('init',...)", an instance is derived from
the class (actually: into the class). Assume you like to have a second
knight, just call the "method" again. The function "findPos" is sufficient
to identify the required instance (which is done internally).

2. the usage of function pointers
The usage of function pointers (@Knight, @Queen,...) saved me a lot of work.

3. the cursor events
I have never really used this Mouse events before, but it worked out pretty
good.

Comments and Ratings (8)

Wolfgang Garn

Wolfgang Garn (view profile)

To "display everything" (images and patches) - you need to overlay axes.
1) Display chess pieces (images) using axis (ax) [see Chess.m - line 114)
2) Display patches using axis (axx) - note: sequence and sending axx to the bottom of the uistack (line 163) - "this is the really tricky part"
3) Display cursor [see displayCursor.m] a bit of colouring and setting the transparency

There is also a file called "TransparencyProblem.m", which you might find useful. If you have any questions please feel free to ask or send me an email (wgarn@yahoo.com).

chris

chris (view profile)

How did you display everything, e.g. the board, pieces, highlighted areas under the cursor?

Bojan

Bojan (view profile)

Edi is not a good player, but it's fun to play chess.

Fabián

I discovered and fixed a bug in your Greedy EDI program that prevents it from running in UNIX environments. The culprit is a line of code near line 82 of show.m where you hard-code path delimiters as \

MATLAB provides the fullfile function for constructing platform-appropriate paths. Below is the code with some original lines commented that should work on all platforms and resolve this issue:

if fig ~='x'
% directory = 'images\basic\';
name = '120px-Chess_tile_';
ext = '.png';
if color %white (attention - transparency issues)
color_letter='l';
else
color_letter='d';
end
% file_name = [directory name lower(fig) color_letter ext];
file_name = fullfile('images','basic',[name lower(fig) color_letter ext]);
[X, map, alpha] = imread(file_name);
%handle = image(pos(2)-1+[0 1],8-pos(1)+[0 1],mirrorImage(X),'AlphaData',mirrorImage(alpha));
handle = image(pos(2)-1+[.1 .9],rows-pos(1)+[.1 .9],mirrorImage(X),'AlphaData',mirrorImage(alpha));

% There are some major transparency issues!!!
set(handle,'AlphaDataMapping','direct');
end

Joachim

it's fun

James Gün

Wolfgang Garn

Wolfgang Garn (view profile)

I have submitted an update, which has fixed the bug mentioned by Jason. Furthermore there are a couple of new features - Enjoy.

Jason Miller

I like this! It's a fun program and good for learning programming in MATLAB.

Having said that it isn't perfect; I've seen the program reveal check on itself (make a move that leaves its King in check, which is illegal) and confuse check with checkmate...

Updates

1.2

You can move chess pieces using the command line: stopCursor(c2m('d2-d4'))
Edi's move can be queried with: [from, to]=lastHalfMove

You can display your game in chess notation with: displayAllMoves (font installation explained in function)

1.1

Improved functionality for legal move; added undo move; new change player colour; other minor improvements

MATLAB Release
MATLAB 7.9 (R2009b)
Acknowledgements

Inspired: ChessPeace

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video