public function answer(KnowledgeState $state) { $state_value = $state->value($this->name); foreach ($this->answers as $answer) { $answer_value = $answer->value; // If this is the default option, return it always. if ($answer_value === null) { return $answer; } // If the value is a variable, try to resolve it. if (KnowledgeState::is_variable($answer_value)) { $answer_value = $state->resolve($answer_value); } if ($state_value == $answer_value) { return $answer; } } // We didn't find an appropriate answer :O return null; }
private function createNewState() { $state = $this->readState($this->kb_file); if (!empty($_GET['goals'])) { foreach (explode(',', $_GET['goals']) as $goal) { $state->goalStack->push($goal); } } else { foreach ($state->goals as $goal) { $state->goalStack->push($goal->name); // Also push any answer values that are variables as goals // to be solved. foreach ($goal->answers as $answer) { if (KnowledgeState::is_variable($answer->value)) { $state->goalStack->push(substr($answer->value, 1)); } } } } return $state; }