/** Bombs-Must-Detonate: Agent AI Library * Author: Brian Go * * The following structures are used to communicate * with the game engine. * **/ /* * * * * * * * * * * * * * Incoming Information * * * * * * * * * * * * * */ struct point { int x; int y; }; enum moveDirection { Void, //no move North, South, East, West }; struct bomb { point position; bool isMine; moveDirection direction; }; struct bomber { point position; int playerId; int teamId; }; struct bomberStatus { point position; int playerId; int teamId; /* # of frames to be in next tile (for collision/explosion purposes). 2x this number to finish moving in. */ int moveRate; bool hasKick; // kick powerup bool hasDetonate; // detonate powerup int radius; // bomb radius int maxBombs; // max bombs usable at once int deployedBombs;// # bombs placed but not exploded }; enum PowerupType { ExtraBombs, ExtraMoveSpeed, ExtraRadius, Kicking, Detonation }; struct powerup { point position; PowerupType type; }; enum TileType { Unknown, Empty, Brick, Block, RecentExplosion, RecentlyExplodedBrick }; struct environment { TileType array [] array [] map; bomber list visibleBombers; bomb list visibleBombs; powerup list visiblePowerups; bomberStatus playerStatus; }; /* * * * * * * * * * * * * * Outgoing Information * * * * * * * * * * * * * */ struct move { // Note: just-placed bombs do not get detonated bool placeBomb; //place bomb at current position? bool detonate; //remote detonate all bombs? moveDirection direction; }; /* * * * * * * * * * * * * Callback Functions * * * * * * * * * * * * */ // Remotables remotable void on_init (point position); remotable move on_move_request (environment env); remotable void on_teammate_death (); remotable void on_bomb_detonate (point position); remotable void on_death (); /* On Init - Engine gives start position */ (point) -> void __on_init; void on_init (point position) { __on_init (position); } /* On Move Request - Engine gives current environment - Agent responds with a move */ (environment) -> move __on_move_request; move on_move_request (environment env) { return __on_move_request(env); } /* On Teammate Death - Engine notifies agent that teammmate has died */ (void) -> void __on_teammate_death; void on_teammate_death () { __on_teammate_death (); return; } /* On Bomb Detonate - Engine notifies agent that one of their bombs has detonated at the given position */ (point) -> void __on_bomb_detonate; void on_bomb_detonate (point position) { __on_bomb_detonate (position); return; } /* On Death - Engine notifies agent that they have died */ (void) -> void __on_death; void on_death () { __on_death (); return; } /* Callback Registering * * If the user does not register a function, the * VM will catch the errors and take no action for the agent. **/ void registerOnInit ((point) -> void foo) { __on_init = foo; return; } void registerOnMoveRequest ((environment) -> move foo) { __on_move_request = foo; return; } void registerOnTeammateDeath ((void) -> void foo) { __on_teammate_death = foo; return; } void registerOnBombDetonate ((point) -> void foo) { __on_bomb_detonate = foo; return; } void registerOnDeath ((void) -> void foo) { __on_death = foo; return; } //Tracks all callback functions simultaneously struct callbackSet { (point) -> void onInit; (environment) -> move onMoveRequest; (void) -> void onTeammateDeath; (point) -> void onBombDetonate; (void) -> void onDeath; }; void registerCallbackSet (callbackSet set) { !(print("Registering a callback set with onMoveRequest function '")); !(print(set.onMoveRequest)); !(print("'.\n")); registerOnInit(set.onInit); registerOnMoveRequest(set.onMoveRequest); registerOnTeammateDeath(set.onTeammateDeath); registerOnBombDetonate(set.onBombDetonate); registerOnDeath(set.onDeath); }