Created
August 25, 2018 10:53
-
-
Save brecert/4bba973d36525ac09255c34679b5e41b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
parent_node : a node with no input | |
child_node : a node decending from another node | |
final_node : a node with no output | |
AST::GLOBALS = | |
MAX = 100 | |
NON = 0 | |
MIn = -100 | |
battery < node | |
not < gate | |
or < gate | |
and < gate | |
print < final_node | |
Array.max = (array): | |
return Math.max.apply(Math, array) | |
Array.min = (array): | |
return Math.min.apply(Math, array) | |
def isActive (number): | |
if number > AST::GLOBALS.NON | |
return true | |
else: | |
return false | |
traverse(parent_nodes) | |
traverse(node : AST::NODES::Battery): | |
node.outputs[0] = node.properties.percentage | |
traverse(node.connections) | |
traverse(node : AST::GATE::Not): | |
node.outputs[0] = -node.input[0] | |
traverse(node.connections) | |
traverse(node : AST::GATE::Or): | |
largestInput = node.inputs.max() | |
if isActive(largestInput): | |
node.output[0] = largestInput | |
else: | |
node.output[0] = AST::GLOBALS.NON | |
traverse(node.connections) | |
traverse(node : AST::GATE::And): | |
if node.inputs.every(input => isActive(input)): | |
node.output[0] = node.outputs.min() | |
else: | |
node.output[0] = AST::GLOBALS.NON | |
traverse(node.connections) | |
traverse(node : AST::OutputNode::Print): | |
if isActive(node.inputs[0]): | |
console.log(node.properties.text) | |
traverse(nodes : Array(AST::Node)): | |
for node in nodes: | |
traverse(node.connections) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment