No BSD License  

Highlights from
Chess clock

5.0

5.0 | 2 ratings Rate this file 6 Downloads (last 30 days) File Size: 4.38 KB File ID: #17715
image thumbnail

Chess clock

by Mathias Benedek

 

25 Nov 2007 (Updated 21 Jan 2008)

Digital chess clock with variable time limit and optional extra time per move

| Watch this File

File Information
Description

You have a chess board but no chess clock is at hand?

This simple function displays the remaining time for each player as well as the actual round. The currently active timer is indicated by its bold font.
You can set variable time limits per player and an optional extra time per move.
Press the space bar to switch the active timer.
Press Escape to pause or exit.

It will not give you the feeling of punching a real chess clock, but it may serve as a substitute if needed
- and my opponents usually insist to use one when playing with me...

MATLAB release MATLAB 7.2 (R2006a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
26 Nov 2007 John D'Errico

One minor point - If the FIRST line of the help is a useful one line description of your function, including reasonable keywords, then the function lookfor will be able to search for your code. In this case, the author has a blank comment line in the help as the first line. Then he has a good descriptive line. But this means that lookfor no longer works on this file. For example, if I removed that blank line, then the command "lookfor chess" finds this file.

Another issue of note - the author uses globals in the code. Yes, perhaps the code works. But just imagine that you have some other code that uses the global variables "turn" or "status". Yep - your code may possibly no longer run properly if you use this clock!

The point is that global variables are dangerous, and simply not necessary to pass information around. Better approaches to the problem might have been to use nested functions for the callbacks, or guidata, or even persistent variables. At the very least, use names that are less likely to step on something else!

As for the clock itself, I like it. Its a nice idea. The help seems reasonable, as is the code, except for the use of globals. I might have added internal comments to the code - they are invaluable for the future when you will want to debug your own code if a problem comes up, or if you want to modify your code to add a new capability.

One downside to this clock - while I'm no longer a speed chess player (and an old nickname of mine, "Father Time", indicates I never really was a speed chess player) there is a certain satisfaction to smashing down the button on a chess clock after a particularly good move or sequence of moves. Will you get that same feeling when you hit the space bar on your keyboard?

05 Dec 2007 John D'Errico

Nicely cleaned up. One minor problem - the initial dialog box to set the clock times has a cancel button on it. But if you click on the cancel button, then you get an error message:

??? Index exceeds matrix dimensions.

Error in ==> chess_clock at 32
    timelimits = str2double(timeset(1:2)) * 60; %total time per player [sec]

I'd suggest that canceling out of the dialog box should close the clock instead of causing an error. If it does not close the clock, then there should be a way provided to restart the clock if you do click cancel.

I'll rate this clock as a 5 anyway, since the other issues I noted were all fixed cleanly, and assume the author will fix this one too.

Please login to add a comment or rating.
Updates
03 Dec 2007

Reviewer suggestions are now implemented: No globals, first line of help contains useful description, more comments to the code.
Minor debugging: e.g. extra time is added at the beginning of the move (and not at the end)

21 Jan 2008

A bug was fixed.

Tag Activity for this File
Tag Applied By Date/Time
games Mathias Benedek 22 Oct 2008 09:36:36
chess Mathias Benedek 22 Oct 2008 09:36:37
fischer Mathias Benedek 22 Oct 2008 09:36:37
clock Mathias Benedek 22 Oct 2008 09:36:37
game Mathias Benedek 22 Oct 2008 09:36:37

Contact us at files@mathworks.com