[Grok-dev] Re: Me Grok Play Chess!
Philipp von Weitershausen
philipp at weitershausen.de
Sun Apr 15 10:58:40 EDT 2007
Maurits van Rees wrote:
> Grok already had a club to hunt mammoths with. Now he also has a
> chess club! ;-)
Yay, awesome!
> You can see a demo game here:
>
> http://chess.vanrees.org:15080/game
As with anything in the vanrees.org domain, I unfortunately don't have
access to this site from my home office ISP. It's a route thing, I think...
> https://svn.vanrees.org/svn/opensource/grokchess/trunk
>
> I am not too clear on that buildout thingie, but if you use
> grokproject you can create a new project and then put this code into
> the src/ dir.
>
> The chess program itself is in the chessmind directory. You can run
> its unit tests by running ./__init__.py. Add '-v' if you want to see
> what is being tested.
I have a few comments that are mostly motivated by aesthetics, but do
represent some of the common patterns that we're trying to promote with
Grok:
* It looks like you're (ab)using relative imports to get to the
chessmind package which in itself seems like an independent library.
It's your code so you can do whatever you want with it, but I would've
split this up:
- a top-level 'chessmind' package that's independently reusable
- a top-level 'grokchess' package that requires the installation of
'chessmind' (e.g. via setuptools dependencies).
* I saw you added a lot of methods on the Index view for access from the
template.
Some of them are a bit non-sensical because they only publish
attributes of the view itself:
- start_square
- target_square
- errors,
- promotion (that one is even faulty, I believe, since it returns the
method object itself)
- ...
Other methodsexpose data from the context object. This is good because
it keeps templates simple since they don't have to reach into content
space. Writing lots of methods for that if the data is needed either
seems like a lot of work and a lot of typing. It also significantly
adds to the lenght of the module, making it harder to grasp at first.
Why not set attributes in update() that you can then access from the
template? E.g.::
def update(self):
...
self.checkmate = self.context.game.board.isCheckMate()
self.stalemate = self.context.game.board.isStaleMate()
etc.
> The Grok part of the application is basically just a browser view. It
> has no tests whatsoever. Sorry. When I was building the chess engine
> I wondered what a good way would be to make a user interface. Since I
> am working daily with Zope and Plone I thought it would be nice to try
> out Grok for this. I was right! :-D
This is a nice perception. I had hoped Grok made an good platform for
writing web UIs for Python libraries. It's good to see it worked well
for you.
--
http://worldcookery.com -- Professional Zope documentation and training
More information about the Grok-dev
mailing list