#define INTRANSITIVE -1 /* illegal object number */
#define SPECIALBASE 300 /* base umber of special rooms */
-typedef struct lcg_state
-{
- unsigned long a, c, m, x;
-} lcg_state;
-
typedef long token_t; /* word token - someday this will be char[TOKLEN+1] */
typedef long vocab_t; /* index into a vocabulary array */
struct game_t {
+ unsigned long lcg_a, lcg_c, lcg_m, lcg_x;
long abbnum;
long blklin;
long bonus;
extern const char advent_to_ascii[];
extern FILE *logfp;
extern bool oldstyle, editline, prompt;
-extern lcg_state lcgstate;
/* b is not needed for POSIX but harmless */
#define READ_MODE "rb"
bool oldstyle = false;
bool editline = true;
bool prompt = true;
-lcg_state lcgstate;
extern void initialise();
extern void score(long);
/* Initialize our LCG PRNG with parameters tested against
* Knuth vol. 2. by the original authors */
- lcgstate.a = 1093;
- lcgstate.c = 221587;
- lcgstate.m = 1048576;
+ game.lcg_a = 1093;
+ game.lcg_c = 221587;
+ game.lcg_m = 1048576;
srand(time(NULL));
long seedval = (long)rand();
set_seed(seedval);
void set_seed(long seedval)
/* Set the LCG seed */
{
- lcgstate.x = (unsigned long) seedval % lcgstate.m;
+ game.lcg_x = (unsigned long) seedval % game.lcg_m;
}
unsigned long get_next_lcg_value(void)
/* Return the LCG's current value, and then iterate it. */
{
- unsigned long old_x = lcgstate.x;
- lcgstate.x = (lcgstate.a * lcgstate.x + lcgstate.c) % lcgstate.m;
+ unsigned long old_x = game.lcg_x;
+ game.lcg_x = (game.lcg_a * game.lcg_x + game.lcg_c) % game.lcg_m;
return old_x;
}
long randrange(long range)
/* Return a random integer from [0, range). */
{
- return range * get_next_lcg_value() / lcgstate.m;
+ return range * get_next_lcg_value() / game.lcg_m;
}
long RNDVOC(long second, long force)
We don't need whatever minor performance gains this might collect,
and the choice to refrain will make forward translation into future
languages easier.
-
* There are a few gotos left that resist restructuring; all of these
are in the principal command interpreter function implementing its
state machine.