[Tutor] Looking for suggestions for improving chessTimer.py code

Dick Moores rdm at rcblue.com
Mon Oct 29 23:14:28 CET 2007

I've developed chessTimer a bit further:

I'm still hoping for some constructive criticism. But I also thought
I'd mention again the points I have doubts about:

1. Is wrapping the long lines where I have done so OK?
2. I've used 1 for White player, -1 for Black player, and (-1)*player
to alternate players. Is there a better way?
3. I've used a lot of variables. Too Many?
4. Should more of the code be in functions?
5. Is there a way to collapse lines 130-137?:
if player == 1: # player is White
                 whiteMoveCounter += 1
                 print "Black to make move %d" % (blackMoveCounter)
                 remainingWhiteTime -= timeUsedThisMove
elif player == -1: # player is Black
                 blackMoveCounter += 1
                 print "White to make move %d" % (whiteMoveCounter)
                 remainingBlackTime -= timeUsedThisMove

6. I thought I had a way to make this script useable on unix as well 
as Windows. Thus the section with the 3 classes. But it won't run on 
unix, because it was necessary to import msvcrt outside of the 
classes--it wouldn't compile otherwise, and because of the need for 
the line  'if msvcrt.kbhit():'  (line 116).  I hope I'm wrong about 
this, and someone can show me how to fix it so that the unix people 
can give me some criticism/advice as well.


Dick Moores

More information about the Tutor mailing list