Skip to content
shb9019 edited this page Jan 8, 2020 · 6 revisions

Simulator Design

/* Main Interfaces */
interface IUpdatable {
    virtual Update();
}

// Interface for an object that takes game state changing calls
// Useful for state syncer to mock state
interface ICommandTaker {
    MoveBot();
    ConvertBot();
    BlastBot();
}

// Can give commands to a command taker
interface ICommandGiver {
    RunCommands(ICommandTaker* state, PlayerState* player_state);
}

/* State */
// Main state, takes commands as a CommandTaker
class State implements ICommandTaker, IUpdatable {
    IMap map;
    IScore score;
    IPathPlanner path_planner; // Under planning
    List<Bot> bots;
    List<Tower> towers;

    int interestingness;
    int interest_threshold;

    @Override MoveBot();
    @Override BlastBot();
    @Override ConvertBot();
    @Override Update();
}

class MapElement {
    TerrainType terrain_type;
    // Valid if terrain_type is tower
    PlayerId occupied_player;
    Boolean is_flag;
}

class Map {
    int map_size;
    List<List<MapElement>> map;
    int GetMapSize();
    MapElement GetElementTypeByPosition();
}

enum TerrainType {
    LAND,
    WATER,
    TOWER
}

class IScore {
    AddScore(PlayerId player, int score);
    ReduceScore(PlayerId player, int score);
    GetScores();
}

// Score is just the number of player units inside flag
// Score doesn't implement IScore. It should right?
class Score implements IScore {
    int scores[2];
    @override AddScore(PlayerId player, int score);
    @override ReduceScore(PlayerId player, int score);
    @override GetScores();
}

// Takes a player_state, and passes it to a CommandTaker, an intermediate betwen the driver and state
// Note that PlayerState will probably mean a list of PlayerState objects (one per player)
interface IStateSyncer {
    UpdateMainState();
    UpdatePlayerState(PlayerState player_state);
    int getInterestingness();
}

class StateSyncer implements IStateSyncer {
    ICommandTaker state;
    ICommandGiver command_giver;
    // Call the command taker
    @Override UpdateMainState(PlayerState player_states);
    // Build the new player states from state
    @Override UpdatePlayerState(PlayerState player_state);
    // Get interestingness of the match
    @Override int getInterestingness();
}

class CommandGiver implements ICommandGiver {
    // Make calls to the corresponding command taker methods
    @Override RunCommands(ICommandTaker state, PlayerState player_state);
}

interface IPathPlanner {
    GetNextPosition(Vector source, Vector destination);
}

class PathPlanner implements IPathPlanner {...}

/* Actors */
class Actor implements IUpdatable {
    int hp;
    Vector position;
}

class Bot extends Actor {
    IPathPlanner path_planner;
    BotState state;
    int speed;
    int blast_range;
    boolean blastBot;
    boolean transformBot;
    PathPlanner GetPathPlanner();
    static BotBuilder Builder() { return new BotBuilder(); }
    @override Update();
}

class Tower extends Actor {
    TowerState state;
    boolean blastTower;
    static TowerBuilder Builder() { return new TowerBuilder(); }
    @override Update();
}

/* Actor States */
interface IActorState {
    void Enter();
    IActorState Update();
    void Exit();
}

class BotState implements IActorState { Bot* bot; ... }
class BotIdleState extends BotState {...};
class BotMoveState extends BotState {...};
class BotTransformState extends BotState {...};
class BotBlastState extends BotState {...};
class BotDeadState extends BotState {...};

class TowerState implements IActorState { Tower* tower; ... }
class TowerIdleState extends TowerState {...};
class TowerSuicideState extends TowerState {...};
class TowerDeadState extends TowerState {...};

Program flow

As a follow up, a brief overview of flow of program control from main driver to updation of player state and main state would be helpful here.

Clone this wiki locally