Skip to content

Commit

Permalink
Implement practice-bound agents
Browse files Browse the repository at this point in the history
...to be used for drama management and the like
  • Loading branch information
mkremins committed Apr 19, 2023
1 parent 19d5104 commit 4729b0c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 6 deletions.
12 changes: 10 additions & 2 deletions praxish.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,18 @@ function tick(praxishState) {
// Get all possible actions for the current actor.
const possibleActions = getAllPossibleActions(praxishState, actor.name);
// Figure out what action to perform.
// Actors with goals should select actions that seem to advance their goals;
// Practice-bound actors should perform random available actions from their practice;
// actors with goals should select actions that seem to advance their goals;
// actors without goals can do whatever.
let actionToPerform = null;
if (actor.goals && possibleActions.length > 0) {
if (actor.boundToPractice) {
// Filter possible actions to just those from the bound practice.
// FIXME We should probably move this logic into `getAllPossibleActions`
// so that we don't waste time generating actions that will never be performed.
const practiceActions = possibleActions.filter(pa => pa.practiceID === actor.boundToPractice);
actionToPerform = randNth(practiceActions);
}
else if (actor.goals && possibleActions.length > 0) {
// Speculatively perform each possible action
// and score the outcome according to the actor's goals.
for (const possibleAction of possibleActions) {
Expand Down
65 changes: 61 additions & 4 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,55 @@ const greetPractice = {
]
};

const jukeboxPractice = {
// TODO Add themes for different song parts,
// an action for reflecting on themes of the currently playing song part,
// maybe agent preferences for specific songs?
id: "jukebox",
name: "A jukebox is here",
data: [
"song.closingStar",
"songPart.prebeginning!beginning",
"songPart.beginning!middle",
"songPart.middle!end"
],
roles: ["JukeboxGhost"],
actions: [
{
name: "[Actor]: Queue up [Song] on the jukebox",
conditions: [
"not practice.jukebox.JukeboxGhost.playing",
"practiceData.jukebox.song.Song",
"neq Actor JukeboxGhost"
],
outcomes: [
"insert practice.jukebox.JukeboxGhost.playing!Song!prebeginning"
]
},
{
name: "[Actor]: Play [Part] of [Song]",
conditions: [
"eq Actor JukeboxGhost",
"practice.jukebox.JukeboxGhost.playing!Song!PrevPart",
"practiceData.jukebox.songPart.PrevPart!Part"
],
outcomes: [
"insert practice.jukebox.JukeboxGhost.playing!Song!Part"
]
},
{
name: "[Actor]: Finish playing [Song]",
conditions: [
"eq Actor JukeboxGhost",
"practice.jukebox.JukeboxGhost.playing!Song!end"
],
outcomes: [
"delete practice.jukebox.JukeboxGhost.playing"
]
}
]
};

const tendBarPractice = {
id: "tendBar",
name: "[Bartender] is tending bar",
Expand Down Expand Up @@ -382,7 +431,6 @@ const ticTacToePractice = {
};

// TODO Implement more practices:
// - jukebox
// - knowitalls
// - darthVader

Expand Down Expand Up @@ -435,21 +483,30 @@ testPraxishState.allChars = [
conditions: ["not practice.tendBar.Bartender.customer.nic!order"]
}
]
},
{
name: "jukebox",
boundToPractice: "jukebox"
}
];
// First test with just the `greet` practice
console.log("PRACTICE TEST: greet");
definePractice(testPraxishState, greetPractice);
performOutcome(testPraxishState, "insert practice.greet.max.isaac");
performOutcome(testPraxishState, "insert practice.greet.nic.max");
doTicks(testPraxishState, 3);
doTicks(testPraxishState, 4);
// Then introduce and test with the `tendBar` practice
console.log("PRACTICE TEST: tendBar");
definePractice(testPraxishState, tendBarPractice);
performOutcome(testPraxishState, "insert practice.tendBar.isaac");
doTicks(testPraxishState, 12);
// And now test `ticTacToe` concurrently with the bar practice
doTicks(testPraxishState, 16);
// Then test `ticTacToe` concurrently with the bar practice
console.log("PRACTICE TEST: ticTacToe");
definePractice(testPraxishState, ticTacToePractice);
performOutcome(testPraxishState, "insert practice.ticTacToe.max.nic");
doTicks(testPraxishState, 32);
// Then test `jukebox` concurrently with the others
console.log("PRACTICE TEST: jukebox");
definePractice(testPraxishState, jukeboxPractice);
performOutcome(testPraxishState, "insert practice.jukebox.jukebox");
doTicks(testPraxishState, 24);

0 comments on commit 4729b0c

Please sign in to comment.