Home /Modules/gameplay/GameTurn.sleela

GameTurn.sleela

lib/gameplay/GameTurn.sleela · 118 line(s) · sleela

<< lib/gameplay/GameTurn.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines GameTurn, the orchestrator that runs one turn of the
     gameplay package. It holds the shared DiceRoll and InferenceEngine, offers
     the Player a choice of the three moves — (a) help index / friend, (b) ask
     for help / new routes, (c) create a new desire — binds the chosen move to
     the turn context, resolves it, and applies the resulting MoveOutcome to the
     Player.
   
   GameTurn is a NATURAL / LOADABLE MODULE sharing the common module contract
   (load / loaded / moduleName / describe). One GameTurn can be reused across
   many turns; it increments its own turn counter each time play() runs.
   
   Family: gameplay. >>
#sleela 2.5
material;
< Unified SLeeLa SDK front-end object. >
class GameTurn {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 10318;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-10-16";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-07";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 9;
  < metaNationalSchedule: a real, citable instrument or "none" >
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }

  static final String MODULE = "GameTurn";

  int loadedFlag;
  DiceRoll dice;
  InferenceEngine engine;
  int turnNumber;
  MoveOutcome lastOutcome;

  < --- loadable-module contract ------------------------------------------ >
  void load() {
    loadedFlag = 1;
    dice = new DiceRoll();
    dice.load();
    dice.seed(1);
    engine = new InferenceEngine();
    engine.load();
    turnNumber = 0;
    lastOutcome = null;
  }
  boolean loaded() { return loadedFlag == 1; }
  String moduleName() { return MODULE; }

  < Configure the shared roller seed and the custom game's target turn. >
  void configure(int seed, int targetTurn) {
    dice.seed(seed);
    engine.setTarget(targetTurn);
    turnNumber = 0;
  }

  < Play one turn: bind the chosen move, resolve it, apply it to the player. >
  < The move is any GameMove subclass, already set up by the caller. >
  MoveOutcome play(Player p, GameMove move) {
    turnNumber = turnNumber + 1;
    if (p == null || move == null) {
      MoveOutcome empty = new MoveOutcome();
      empty.begin("none");
      empty.say("No player or move supplied.");
      lastOutcome = empty;
      return empty;
    }
    move.bind(dice, engine, turnNumber);
    MoveOutcome out = move.resolve(p);
    out.applyTo(p);
    lastOutcome = out;
    return out;
  }

  int turn() { return turnNumber; }
  DiceRoll roller() { return dice; }
  InferenceEngine inference() { return engine; }
  MoveOutcome latest() { return lastOutcome; }

  String describe() {
    return MODULE + " turn=" + turnNumber + "; " + dice.describe()
         + "; " + engine.describe();
  }
}