File Exchange

image thumbnail

Chess Master

version 1.4 (144 KB) by

Simple logic, easy to understand code, well commented 4 beginners, must try once.

39 Downloads

Updated

View License

Its a two player game, i am working on developing artificial intelligence based computer player.
American Chess rules are applied.
A 2D array is updated by the position of the chess pieces which are numbered (each piece corresponding to a number)
As the player selects a piece the corresponding number is checked for all possible places where it can move, then the program waits for the second place where it has to be moved.
After each turn the program calls the function "wholoses.m" which will see whether the king is there or not. I am working to change this logic as it should check for CHECK MATE also.

The main function to run is CHESS_on_MATLAB.m
that will call its fig itself
the main m file just calls function "playerturn.m" as the input is given by the user.
this function then calls different functions to check the position of the piece, win loss, etc
"checkfp.m" checks whether the position desired is possible or not, and gives the message if not possible.
Currently the winner has to kill the king while i realized that it should not be the case, it should detect the checkmate condition, so dont worry i am gonna update this in few coming days.

Comments and Ratings (11)

Hi, i have a question!
how does it work the line in code that say "rc=h.r*10+h.c".
I don't understand of all, for example, if i want a move the blacknight in r=1 and c=2
then rc=13. This move the piece at side of blacknight and no that i want, and so
i really confused with this part. Can you help me?
Thanks

Thanks for your code!! It was very useful since I could not understand well how to make the handling in the plays.

ACLNM

ACLNM (view profile)

very nice work

good work....

Suleman Shafqat

first issue can be solved by writing
h.plrmark=1;
in opening function of the main function that is:
write "h.plrmark=1;" in line number "162" in "CHESS_on_MATLAB.m"

2nd Issue (En_passant) will be solved in next version of CHESS MASTER

thanks for ur feedback

* Black plays first!
* Clicking on the opposite side causes an error to throw in the console (MATLAB 2011b)
* En passsant is not implemented and is claimed as a wrong move.(http://en.wikipedia.org/wiki/En_passant).

Suleman Shafqat

@Newell: The aim is to understand how things work. You can reproduce code as per your OS's requirements.

Suleman Shafqat

The code included is commented for better understanding as well as future work for improvement, if you find any block elusive feel free to ask.

Andrew Newell

I'm eager to try this, but it's not compatible with a Unix-based system because it uses '\' for a file separator. It shouldn't take long to replace this by "filesep" wherever it occurs.

Jason

Jason (view profile)

Thanks, gonna try it later. Looks interesting!

Updates

1.4

Description

1.1

Summary
Description
Tags

MATLAB Release
MATLAB 7.9 (R2009b)

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

» Watch video