[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-gnubg] The match and game data structure
From: |
Øystein Johansen |
Subject: |
Re: [Bug-gnubg] The match and game data structure |
Date: |
Fri, 30 Jun 2006 14:48:43 +0200 |
> Perhaps I've coded too much C++...
> I think a better exercise is to separate the logic
> from the data and think more in terms of
> modules/interfaces and let this drive the data structures.
mmmhhmm...
> In practice this would mean calling functions to
> work with matches and games rather than using
> globals/structs throughout the code.
Yes! Exactly!
> As an example look at this code from show.c:
>
> for( pl = lMatch.plNext; pl != &lMatch; pl = pl->plNext, ++n )
{
> pmr = (moverecord *) ( (list *) pl->p )->plNext->p;
> pmgi = &pmr->g;
> assert( pmr->mt == MOVE_GAMEINFO );
> ...
> It's pretty hard to work out what the code in this
> example does, which kind of says something...
Yes, you're pinpointing the problem with this example code.
> Anyway it could look something like:
>
> for (i = 1; i < getNumGames(); i++)
> {
> game *g = getGame(i);
> pmgi = getGameInfo(g);
> ...
Here's my (first) suggestion:
GList game = match->games;
for ( ; game ; game = game->next ){
GList move = game->moves;
for ( ; move ; move = move->next )
analyse(move); /* or do something else */
}
and a data structure for game and match like in the attached file.
-Øystein
game.h
Description: Text document