Skip to content

Commit

Permalink
feat(agent): Added agent property value update functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasBoda committed Jan 17, 2024
1 parent f05c4ff commit b4805f3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/interpreter/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,8 @@ export class Interpreter {

return heightFunction;
}

public updateAgentValue(agentIndex: number, propertyIdentifier: string, value: number): void {
this.runtime?.updateAgentValue(agentIndex, propertyIdentifier, value);
}
}
2 changes: 1 addition & 1 deletion src/parser/parser-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class ParserUtil {
const objectDeclaration = ast as ObjectDeclaration;

const identifier = objectDeclaration.identifier;
const count = objectDeclaration.count;
const count = ParserUtil.astToCode(objectDeclaration.count);

code += `agent ${identifier} ${count} {\n`;
code += objectDeclaration.body.map(declaration => `\t${ParserUtil.astToCode(declaration)}`).join("\n");
Expand Down
5 changes: 5 additions & 0 deletions src/runtime/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export class Runtime {
this.output = { type: ValueType.Output, step: 0, agents: [] };
}

// update specific agent variable value
public updateAgentValue(agentIndex: number, propertyIdentifier: string, value: number): void {
this.previousAgents[agentIndex].variables.set(propertyIdentifier, { type: ValueType.Number, value } as NumberValue);
}

private evaluateProgram(program: Program): RuntimeValue {
for (const statement of program.body) {
switch (statement.type) {
Expand Down

0 comments on commit b4805f3

Please sign in to comment.