/*
   File:        wrld.h
   Author:      Andrew W. Moore
   Created:     Sat Sep 19 11:29:32 EDT 1992
   Description: Header for Spec. of the World Control problem

   Copyright (C) 1992, Andrew W. Moore
*/

typedef struct worst_struct
{
  int mode;
  float nstate[MAX_DIM];
} worst;

typedef struct mtrans_struct
{
  region *region;
  worst *next_worst;
  struct mtrans_struct *next;
} mtrans;

typedef struct space_spec_struct
{
  int dim;
  hype *bound;
} space_spec;

typedef struct mode_spec_struct
{
  char *name;
  space_spec state;
  space_spec action;
  float *middle;
  float *scales;
  bool *splittable_attributes;
  mtrans *mode_transitions;

  void (*next_worst)();         /* (wld,wst,wac,next_wst) */
  void (*local_control)();      /* (wld,wst,goal_wst,wac) */
  void (*draw_worst)();         /* (gp,wld,wst) */
  bool (*is_stuck)();           /* (wld,whist) whists defined in whis.h */
                                /* is_stuck may be NULL, meaning always stuck
                                   is_stuck function may assume all modes in
                                   whist are the same.
                                */
  bool (*should_remove_trans)();/* (wld,msp,hype_me,hype_neigh)
                                   World knowledge may tell us that some
                                   potential transitions are hopeless. This
                                   is what we use.
                                   NULL => don't remove a sausage.
                                */
  char *data;
} mode_spec;

/* A word about mode transitions. There are some mode transitions known
   in advance, without needing learning. These are specified by mode
   transitions. Some world-states automatically, and immediately, lead to
   other states in other modes. This is specified thus:

     worst (m,x) ---> worst (m',x') as a mode transition 
       iff
     m's mode transitions include the member
       (m,R) where x is in region R, AND there are no earlier mode transitions
       in the mode transition list which are applicable to (m,x), and (m,R)'s
       next_worst is (m',x').

   Note that the careless mode transition designer could create an infinite
   loop of mode transitions.
*/

typedef mode_spec *mode_spec_ptr;

typedef struct world_struct
{
  char *name;
  int number_modes;
  mode_spec_ptr *modes;
  worst *goal;
  void (*draw_structure)();        /* (gp,wld,wst) */
} world;

extern worst *create_worst();                 /* (mode,size) */
extern void free_worst();                     /* (wst) */
extern void copy_worst();                     /* (wst1,wst2,size) */
extern mtrans *add_to_mtrans();               /* (reg,next_worst,mts) */
extern mode_spec *create_empty_mode_spec();   /* (sdim,adim) */
extern mode_spec *mode_ref();                 /* (wld,mode) */
extern int state_dim();                       /* (wld,mode) */
extern void fprintf_worst();                  /* (s,m1,wst,wld,m2) */
extern void fprint_mode();                    /* (s,m,md,wld) */
extern void fprint_world();                   /* (s,m,wld) */
extern void init_empty_mode_spec_array();     /* (wld,size) */
extern void step_world();                     /* (wld,wst,goal_wst) */
extern void run_world();                      /* (wld,wst,goal_wst,steps) */
extern int mode_number_called();              /* (wld,name) */
extern void world_draw_worst();               /* (gp,wld,wst) */
extern bool is_scaled_worst_dist_below();     /* (wld,w1,w2,epsilon) */

extern int gp_worst_from_mouse();             /* (gp,wld,start_wst,wst) */
extern void normalize_to_legality();          /* (wld,mode,wac) */
extern void start_worst_from_args();          /* (wld,start_worst,argc,argv) */


/* The following function is from loader.c */

extern void load_world();                     /* (wld,wname,argc,argv) */



  

