How to wait for a click?

Tim Gahnström /Bladerman tim at bladerman.com
Tue Apr 8 03:40:51 EDT 2003


"Bill Mill" <llimllib at f2o.org> wrote in

> In the new structure, a referee class calls the genmove() function
> of a HumanGoPlayer class and expects as a return value a move. Herein
> lies the problem; how do I have genmove() (which has a reference to
> the board) wait for a click and return the move? I know I could have
> it check some variable in the board class every x milliseconds, but
> that's very inelegant. Is there a better way? Am I thinking about the
> problem wrong?

I am not sure I got your problem right but I give it a try anyway.
One way would be to let your genMove() function be really short and dont
expect a returnvalue. Instead it is just used as an indikator so that the
player knows that it is his turn (either the AI or Human player). Then the
player in turn cals a function in the structure callled
structure.hereIsMyMove(move)

Means the player always make a callback to the structre.

Another way would be to completley skip the genMove function and let players
call the structre anytime with a function
structure.hereIsMyMove(move,myId)
Then the structure must always check if I had the right to do the actual
move and if so, make the move.

None of these, I think, are nice looking but they should work and they are
slightly better then polling a variable every so milliseconds.

Good luck.

Tim






More information about the Python-list mailing list