OO style advice

Sean Ross sross at connectmail.carleton.ca
Mon Feb 16 19:42:42 CET 2004

"DomF" <fidtz at clara#spam#.co.uk> wrote in message
news:1076943278.22567.0 at echo.uk.clara.net...
> I have been putting together a little text chess program and have run into
> style issue when integrating my chess clock with my chessboard generator.
> Basically, I would like to be able to manipulate the clock independently
> the board but also want the clock time as displayed by the board to change
> automatically.

My first thought is to make a Clock object that has a time attribute and
start() and stop() methods

Then have one instance of Clock for each player (and perhaps an independent
one for the board?)

If you have Player objects, perhaps they could have a clock instance. In
that way
you could do something like:

# suppose the players are maintained by the board in a list
# and you have a turn variable for accessing the player whose turn it is to
while board.state != STALEMATE and board.state != CHECKMATE:
    player = player[turn]
    turn.next()   # adjust turn index to let other player move next round

you could even have player.clock.start() and player.clock.stop() at the
and end of the inside of player.move() so your code looks more like this

while board.state != STALEMATE and board.state != CHECKMATE:

Just an idea,

More information about the Python-list mailing list