On 13/05/06, Beni Cherniavsky <[EMAIL PROTECTED]> wrote:
I can demonstrate using Python for solving combinatorial constraint puzzles
like 8 Queens, Suduko, and Minesweeper.  I feel especially eager to show it
after having written 2 days ago a minsweeper that does all the simple
bookkeeping of flags recursively - with pygtk interface in 220 lines.

Since we got other lectures this month, here is a spoiler:

http://cben-hacks.sf.net/python/smartsweeper.py
http://svn.sf.net/viewcvs.cgi/cben-hacks/python/smartsweeper.py?view=markup

Try it -- much fun!  It let's one concentrate on the interesting
calculations and the guessing.  But now the guessing is not so
annoying (you don't lose much work) and turns out it's an art of it's
own -- you can usually do much better than 50/50.

Note that being able to continue playing after you lose is a feature.
It started out as a bug but I liked it ;-).  Took some time to make
sure flag accounting wasn't confused by open mines (eventually I just
decided they are not really open, only shown open).

It's only 175 lines of code after some clean-up.  I say that's rather
impressive for what it does.  A large part of the saving was due to
heavy use of sets (things like `` self.neighbours[xy] - self.open -
self.flags``).

--
Beni Cherniavsky <[EMAIL PROTECTED]>, who can only read email on weekends.

לענות