55 #define MAX_PAYOFF (1.)
60 static const int x_moves[] = { 0, +1, +1, +1, 0, -1, -1, -1 };
65 static const int y_moves[] = { -1, -1, 0, +1, +1, +1, 0, -1 };
89 printf(
"unsupported maze state: %c\n", s);
103 FILE *fp = fopen(filename,
"rt");
105 printf(
"could not open %s. %s.\n", filename, strerror(errno));
113 while ((c = fgetc(fp)) != EOF) {
119 env->
maze[y][x] = (char) c;
131 printf(
"EOF error opening %s. %s.\n", filename, strerror(errno));
136 env->
state = malloc(
sizeof(
double) * 8);
191 for (
int y = -1; y < 2; ++y) {
192 for (
int x = -1; x < 2; ++x) {
193 if (x == 0 && y == 0) {
201 const char s = env->
maze[ysense][xsense];
219 if (action < 0 || action > 7) {
220 printf(
"invalid maze action\n");
231 switch (env->
maze[newy][newx]) {
247 printf(
"invalid maze type\n");
bool env_maze_is_done(const struct XCSF *xcsf)
Returns whether the maze is in a terminal state.
void env_maze_free(const struct XCSF *xcsf)
Frees the maze environment.
bool env_maze_multistep(const struct XCSF *xcsf)
Returns whether the environment is a multistep problem.
static double env_maze_sensor(const struct XCSF *xcsf, const char s)
Returns a float encoding of a sensor perception.
double env_maze_execute(const struct XCSF *xcsf, const int action)
Executes the specified action and returns the payoff.
const double * env_maze_get_state(const struct XCSF *xcsf)
Returns the current animat perceptions in the maze.
static const int y_moves[]
Maze y-axis moves.
void env_maze_init(struct XCSF *xcsf, const char *filename)
Initialises a maze environment from a specified file.
static const int x_moves[]
Maze x-axis moves.
void env_maze_reset(const struct XCSF *xcsf)
Resets the animat to a random empty position in the maze.
#define MAX_PAYOFF
The payoff provided at a food position.
double env_maze_maxpayoff(const struct XCSF *xcsf)
Returns the maximum payoff value possible in the maze.
The discrete maze problem environment module.
#define MAX_SIZE
The maximum width/height of a maze.
void param_init(struct XCSF *xcsf, const int x_dim, const int y_dim, const int n_actions)
Initialises default XCSF parameters.
Functions for setting and printing parameters.
Maze environment data structure.
int xsize
Maze size in x dimension.
int ysize
Maze size in y dimension.
bool done
Whether the maze is in a terminal state.
double * state
Current state.
int xpos
Current x position.
int ypos
Current y position.
char maze[(50)][(50)]
Maze.
int rand_uniform_int(const int min, const int max)
Returns a uniform random integer [min,max] not inclusive of max.
Utility functions for random number handling, etc.