-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7974db6
commit d656625
Showing
4 changed files
with
46 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,16 @@ | ||
|
||
import {clone} from "@benev/slate" | ||
|
||
import {ref} from "../../tools/ref.js" | ||
import {Agent} from "../../logic/agent.js" | ||
import {Choice} from "../../logic/state.js" | ||
import {Proposer} from "../../logic/simulation/proposer.js" | ||
|
||
/** helps us preview the effects of a proposed turn */ | ||
export class PreviewAgent extends Agent { | ||
proposer: Proposer | ||
readonly #choices = ref<Choice.Any[]>([]) | ||
|
||
constructor(public baseAgent: Agent) { | ||
super(clone(baseAgent.state)) | ||
this.proposer = new Proposer(this) | ||
} | ||
|
||
reset() { | ||
this.state = clone(this.baseAgent.state) | ||
this.#choices.value = [] | ||
this.proposer = new Proposer(this) | ||
} | ||
export function setupPreviewAgent(baseAgent: Agent, onReset: () => void) { | ||
const agent = new Agent(clone(baseAgent.state)) | ||
const dispose = baseAgent.stateRef.on(reset) | ||
|
||
get choices() { | ||
return this.#choices.value | ||
function reset() { | ||
agent.state = clone(baseAgent.state) | ||
onReset() | ||
} | ||
|
||
addChoice(choice: Choice.Any) { | ||
this.#choices.value = [...this.#choices.value, choice] | ||
} | ||
return {agent, reset, dispose} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters