Play chess against "Greedy Edi".
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
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.
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 (email@example.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
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 (firstname.lastname@example.org).
How did you display everything, e.g. the board, pieces, highlighted areas under the cursor?
Edi is not a good player, but it's fun to play chess.
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)
% 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!!!
I have submitted an update, which has fixed the bug mentioned by Jason. Furthermore there are a couple of new features - Enjoy.
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...
You can move chess pieces using the command line: stopCursor(c2m('d2-d4'))
You can display your game in chess notation with: displayAllMoves (font installation explained in function)
Improved functionality for legal move; added undo move; new change player colour; other minor improvements