Home /Modules/gameplay/GameMove.sleela

GameMove.sleela

lib/gameplay/GameMove.sleela · 125 line(s) · sleela

<< lib/gameplay/GameMove.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines GameMove, the base contract for the three moves a Player
     may make on a turn: (a) create a help index / friend, (b) ask for help or
     new routes, (c) create a new desire. A developer adds a move by subclassing
     GameMove and overriding resolve(), which rolls the dice and returns a
     MoveOutcome. The base owns identity, the shared context, and the module
     contract — exactly the base/subclass pattern used by lib/compiler.
   
   GameMove is a NATURAL / LOADABLE MODULE sharing the common module contract
   (load / loaded / moduleName / describe). A move is handed the shared engine
   and roller through bind(); resolve() does the rest.
   
   Family: gameplay. >>
#sleela 2.5
material;
< Unified SLeeLa SDK front-end object. >
class GameMove {
  < ---- 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 = 10317;
  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 = "GameMove";

  < The three move choices a turn offers. >
  < (a) create a help index / friend >
  static final int CHOICE_HELP_INDEX = 1;
  < (b) ask for help or new routes >
  static final int CHOICE_ASK_HELP   = 2;
  < (c) create a new desire >
  static final int CHOICE_NEW_DESIRE = 3;

  int loadedFlag;
  < human-readable move name >
  String moveName;
  < one of CHOICE_* >
  int choice;
  < the shared roller for this turn >
  DiceRoll dice;
  < the shared modeler for this turn >
  InferenceEngine engine;
  < which turn this move is being played on >
  int turnNumber;

  < --- loadable-module contract ------------------------------------------ >
  void load() {
    loadedFlag = 1;
    moveName = "GameMove";
    choice = 0;
    dice = null;
    engine = null;
    turnNumber = 0;
  }
  boolean loaded() { return loadedFlag == 1; }
  String moduleName() { return MODULE; }

  < A subclass calls this to declare its identity. >
  void declare(String name, int whichChoice) {
    moveName = name;
    choice = whichChoice;
  }

  < Bind the shared turn context before resolve(). >
  void bind(DiceRoll roller, InferenceEngine inf, int turn) {
    dice = roller;
    engine = inf;
    turnNumber = turn;
  }

  < Overridable: run the move and return its outcome. The base move does >
  < nothing and reports failure, so an un-overridden move is honest. >
  MoveOutcome resolve(Player p) {
    MoveOutcome out = new MoveOutcome();
    out.begin(moveName);
    out.say("Base move does nothing.");
    return out;
  }

  String name() { return moveName; }
  int choiceKind() { return choice; }

  String describe() {
    return MODULE + "/" + moveName + " choice=" + choice
         + " turn=" + turnNumber;
  }
}