gnugo-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gnugo-devel] Patch: new cache


From: Arend Bayer
Subject: Re: [gnugo-devel] Patch: new cache
Date: Tue, 5 Aug 2003 15:43:16 +0200 (CEST)

On Sun, 3 Aug 2003, Inge Wallin wrote:

> Here is the next version of the new cache, a traditional transposition table.
> I have written so much about the implementation before that I won't go into
> that very much here.

I've spotted another problem that I missed before: (in hash.c)

static Hashvalue_ng  komaster_hash[4]; /* EMPTY, BLACK, WHITE, GRAY */
static Hashvalue_ng  routine_hash[NUM_ROUTINES];

The first one is a bug, as (unless I missed s.th.) our current komaster
scheme uses more than 4 states. The second isn't nice because it means
that hash.c has to include cache.h (where NUM_ROUTINES is defined).
(Which currently happens by including liberty.h.)

Just changing the 4 above to 7 is of course not a solution, as this
will certainly get overlooked in case someone changed the komaster
scheme once again.

What I suggest to do is the following (I saw this in the gcc sources):

We should create a new file defs.h. This should collect a load of
stuff that is currently scattered over the code in the following form:

#ifndef DEFINE_CACHE_ROUTINE
#define DEFINE_CACHE_ROUTINE(id, name)
#endif

DEFINE_CACHE_ROUTINE(OWL_ATTACK, "owl_attack")
DEFINE_CACHE_ROUTINE(OWL_DEFEND, "owl_defend")
...

Similar for persistent cache routines, group status, safety values, ...

This can then be used as follows:

#define DEFINE_CACHE_ROUTINE(id, name) id,

enum cache_routine_nr {
#include defs.h
  NUM_ROUTINES
};

#undef DEFINE_CACHE_ROUTINE

This generates the type enum cache_routine_nr. And it allows the above
array to be defined as
static Hashvalue_ng  routine_hash[(int) NUM_ROUTINES];

To write a function cache_routine_nr_to_string, one can do the
following:

#define DEFINE_CACHE_ROUTINE(id, name) name,

const char * cache_routine_names = {
#include defs.h
  ""
};

And the function just becomes:

const char* cache_routine_nr_to_string(enum cache_routine_nr nr)
{
  return cache_routine_names[(int) nr];
}

The ..._to_string functions we have in the code have most of the time
been out of date, because the #define of the id's and the translation
into names happen at different places in the code.

This would also give type safety to avoid confusion of safety values
with dragon status' etc.

(Even the most often used safety value->string translation in
show_dragons() only got fixed only very shortly before 3.4 by Gunnar,
on July 15 to be precise.)

Arend









reply via email to

[Prev in Thread] Current Thread [Next in Thread]