-
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.
feat(otherwise): Added otherwise expression for null value handling
- Loading branch information
Showing
9 changed files
with
103 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"type":"Program","body":[{"type":"ObjectDeclaration","identifier":"person","count":30,"body":[{"type":"VariableDeclaration","variableType":"Const","identifier":"speed","value":{"type":"NumericLiteral","value":4}},{"type":"VariableDeclaration","variableType":"Property","identifier":"angle","value":{"type":"BinaryExpression","left":{"type":"Identifier","identifier":"angle"},"right":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"choice"},"args":[{"type":"UnaryExpression","operator":"-","value":{"type":"NumericLiteral","value":0.1}},{"type":"NumericLiteral","value":0.1}]},"operator":"+"},"default":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"random"},"args":[{"type":"NumericLiteral","value":0},{"type":"BinaryExpression","left":{"type":"NumericLiteral","value":2},"right":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"pi"},"args":[]},"operator":"*"}]}},{"type":"VariableDeclaration","variableType":"Property","identifier":"shouldStay","value":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"prob"},"args":[{"type":"NumericLiteral","value":0.5}]}},{"type":"VariableDeclaration","variableType":"Property","identifier":"xNew","value":{"type":"BinaryExpression","left":{"type":"BinaryExpression","left":{"type":"Identifier","identifier":"x"},"right":{"type":"BinaryExpression","left":{"type":"Identifier","identifier":"speed"},"right":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"cos"},"args":[{"type":"Identifier","identifier":"angle"}]},"operator":"*"},"operator":"+"},"right":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"width"},"args":[]},"operator":"%"},"default":{"type":"NumericLiteral","value":0}},{"type":"VariableDeclaration","variableType":"Property","identifier":"yNew","value":{"type":"BinaryExpression","left":{"type":"BinaryExpression","left":{"type":"Identifier","identifier":"y"},"right":{"type":"BinaryExpression","left":{"type":"Identifier","identifier":"speed"},"right":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"sin"},"args":[{"type":"Identifier","identifier":"angle"}]},"operator":"*"},"operator":"+"},"right":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"height"},"args":[]},"operator":"%"},"default":{"type":"NumericLiteral","value":0}},{"type":"VariableDeclaration","variableType":"Property","identifier":"x","value":{"type":"ConditionalExpression","condition":{"type":"Identifier","identifier":"shouldStay"},"consequent":{"type":"Identifier","identifier":"x"},"alternate":{"type":"Identifier","identifier":"xNew"}},"default":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"random"},"args":[{"type":"NumericLiteral","value":50},{"type":"BinaryExpression","left":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"width"},"args":[]},"right":{"type":"NumericLiteral","value":50},"operator":"-"}]}},{"type":"VariableDeclaration","variableType":"Property","identifier":"y","value":{"type":"ConditionalExpression","condition":{"type":"Identifier","identifier":"shouldStay"},"consequent":{"type":"Identifier","identifier":"y"},"alternate":{"type":"Identifier","identifier":"yNew"}},"default":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"random"},"args":[{"type":"NumericLiteral","value":50},{"type":"BinaryExpression","left":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"height"},"args":[]},"right":{"type":"NumericLiteral","value":50},"operator":"-"}]}},{"type":"VariableDeclaration","variableType":"Const","identifier":"distance","value":{"type":"NumericLiteral","value":20}},{"type":"VariableDeclaration","variableType":"Property","identifier":"people","value":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"agents"},"args":[{"type":"Identifier","identifier":"person"}]}},{"type":"VariableDeclaration","variableType":"Property","identifier":"closePeople","value":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"filter"},"args":[{"type":"LambdaExpression","base":{"type":"Identifier","identifier":"people"},"param":"p","value":{"type":"BinaryExpression","left":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"sqrt"},"args":[{"type":"BinaryExpression","left":{"type":"BinaryExpression","left":{"type":"BinaryExpression","left":{"type":"MemberExpression","caller":{"type":"Identifier","identifier":"p"},"value":{"type":"Identifier","identifier":"x"}},"right":{"type":"Identifier","identifier":"x"},"operator":"-"},"right":{"type":"BinaryExpression","left":{"type":"MemberExpression","caller":{"type":"Identifier","identifier":"p"},"value":{"type":"Identifier","identifier":"x"}},"right":{"type":"Identifier","identifier":"x"},"operator":"-"},"operator":"*"},"right":{"type":"BinaryExpression","left":{"type":"BinaryExpression","left":{"type":"MemberExpression","caller":{"type":"Identifier","identifier":"p"},"value":{"type":"Identifier","identifier":"y"}},"right":{"type":"Identifier","identifier":"y"},"operator":"-"},"right":{"type":"BinaryExpression","left":{"type":"MemberExpression","caller":{"type":"Identifier","identifier":"p"},"value":{"type":"Identifier","identifier":"y"}},"right":{"type":"Identifier","identifier":"y"},"operator":"-"},"operator":"*"},"operator":"+"}]},"right":{"type":"Identifier","identifier":"distance"},"operator":"<="}}]}},{"type":"VariableDeclaration","variableType":"Property","identifier":"closeInfected","value":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"filter"},"args":[{"type":"LambdaExpression","base":{"type":"Identifier","identifier":"closePeople"},"param":"c","value":{"type":"BinaryExpression","left":{"type":"MemberExpression","caller":{"type":"Identifier","identifier":"c"},"value":{"type":"Identifier","identifier":"infected"}},"right":{"type":"BooleanLiteral","value":true},"operator":"=="}}]}},{"type":"VariableDeclaration","variableType":"Const","identifier":"timespan","value":{"type":"NumericLiteral","value":200}},{"type":"VariableDeclaration","variableType":"Property","identifier":"remaining","value":{"type":"ConditionalExpression","condition":{"type":"Identifier","identifier":"infected"},"consequent":{"type":"BinaryExpression","left":{"type":"Identifier","identifier":"remaining"},"right":{"type":"NumericLiteral","value":1},"operator":"-"},"alternate":{"type":"Identifier","identifier":"timespan"}},"default":{"type":"Identifier","identifier":"timespan"}},{"type":"VariableDeclaration","variableType":"Property","identifier":"shouldInfect","value":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"prob"},"args":[{"type":"NumericLiteral","value":0.4}]}},{"type":"VariableDeclaration","variableType":"Property","identifier":"infected","value":{"type":"LogicalExpression","left":{"type":"LogicalExpression","left":{"type":"Identifier","identifier":"infected"},"right":{"type":"BinaryExpression","left":{"type":"Identifier","identifier":"remaining"},"right":{"type":"NumericLiteral","value":0},"operator":">"},"operator":"and"},"right":{"type":"LogicalExpression","left":{"type":"BinaryExpression","left":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"count"},"args":[{"type":"Identifier","identifier":"closeInfected"}]},"right":{"type":"NumericLiteral","value":0},"operator":">"},"right":{"type":"Identifier","identifier":"shouldInfect"},"operator":"and"},"operator":"or"},"default":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"prob"},"args":[{"type":"NumericLiteral","value":0.5}]}},{"type":"VariableDeclaration","variableType":"Property","identifier":"coloured","value":{"type":"Identifier","identifier":"infected"},"default":{"type":"BooleanLiteral","value":false}}]}]} | ||
{"type":"Program","body":[{"type":"ObjectDeclaration","identifier":"person","count":10,"body":[{"type":"VariableDeclaration","variableType":"Const","identifier":"x","value":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"random"},"args":[{"type":"NumericLiteral","value":0},{"type":"CallExpression","caller":{"type":"Identifier","identifier":"width"},"args":[]}]}},{"type":"VariableDeclaration","variableType":"Const","identifier":"y","value":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"random"},"args":[{"type":"NumericLiteral","value":0},{"type":"CallExpression","caller":{"type":"Identifier","identifier":"height"},"args":[]}]}},{"type":"VariableDeclaration","variableType":"Property","identifier":"close","value":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"filter"},"args":[{"type":"LambdaExpression","base":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"agents"},"args":[{"type":"Identifier","identifier":"person"}]},"param":"p","value":{"type":"LogicalExpression","left":{"type":"BinaryExpression","left":{"type":"MemberExpression","caller":{"type":"Identifier","identifier":"p"},"value":{"type":"Identifier","identifier":"x"}},"right":{"type":"NumericLiteral","value":0},"operator":">="},"right":{"type":"BinaryExpression","left":{"type":"MemberExpression","caller":{"type":"Identifier","identifier":"p"},"value":{"type":"Identifier","identifier":"x"}},"right":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"width"},"args":[]},"operator":"<="},"operator":"and"}}]}},{"type":"VariableDeclaration","variableType":"Property","identifier":"closest","value":{"type":"CallExpression","caller":{"type":"Identifier","identifier":"min"},"args":[{"type":"LambdaExpression","base":{"type":"Identifier","identifier":"close"},"param":"c","value":{"type":"MemberExpression","caller":{"type":"Identifier","identifier":"c"},"value":{"type":"Identifier","identifier":"x"}}}]}},{"type":"VariableDeclaration","variableType":"Property","identifier":"color","value":{"type":"BooleanLiteral","value":true}},{"type":"VariableDeclaration","variableType":"Property","identifier":"coloured","value":{"type":"OtherwiseExpression","left":{"type":"MemberExpression","caller":{"type":"Identifier","identifier":"closest"},"value":{"type":"Identifier","identifier":"color"}},"right":{"type":"BooleanLiteral","value":false}}}]}]} |
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,26 +1,12 @@ | ||
agent person 30 { | ||
const speed = 4; | ||
property angle: random(0, 2 * pi()) = angle + choice(-0.1, 0.1); | ||
|
||
property shouldStay = prob(0.5); | ||
|
||
property xNew: 0 = (x + speed * cos(angle)) % width(); | ||
property yNew: 0 = (y + speed * sin(angle)) % height(); | ||
|
||
property x: random(50, width() - 50) = if shouldStay then x else xNew; | ||
property y: random(50, height() - 50) = if shouldStay then y else yNew; | ||
|
||
const distance = 20; | ||
|
||
property people = agents(person); | ||
property closePeople = filter(people => p => sqrt((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y)) <= distance); | ||
property closeInfected = filter(closePeople => c => c.infected == true); | ||
|
||
const timespan = 200; | ||
property remaining: timespan = if infected then remaining - 1 else timespan; | ||
|
||
property shouldInfect = prob(0.4); | ||
property infected: prob(0.5) = (infected and remaining > 0) or (count(closeInfected) > 0 and shouldInfect); | ||
|
||
property coloured: false = infected; | ||
|
||
agent person 10 { | ||
const x = random(0, width()); | ||
const y = random(0, height()); | ||
|
||
property close = filter(agents(person) => p => p.x >= 0 and p.x <= width()); | ||
property closest = min(close => c => c.x); | ||
|
||
property color = true; | ||
|
||
property coloured = closest.color otherwise false; | ||
} |
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
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
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
Oops, something went wrong.