63 lines
1.9 KiB
PHP
63 lines
1.9 KiB
PHP
<?php
|
|
|
|
require_once "LogicTaskBase.php";
|
|
|
|
class LogicFunctionTask extends LogicTaskBase
|
|
{
|
|
private float $missing_minterm_score = -1.0; // score for a missing minterm
|
|
public function __construct(array $a = null)
|
|
{
|
|
parent::__construct("logicfunction", $a);
|
|
|
|
$this->missing_minterm_score = $a["missing_minterm_score"] ?? -1.0;
|
|
|
|
if (!$this->hasFlag("dnf")) {
|
|
$this->setCorrectAnswer($this->getLogicFunction()->getExpression());
|
|
} else {
|
|
$dnf = $this->getLogicFunction()->toDNF();
|
|
if ($dnf === "") {
|
|
$dnf = "0";
|
|
}
|
|
$this->setCorrectAnswer($dnf);
|
|
}
|
|
}
|
|
|
|
public function toArray(string $mode = "all"): array
|
|
{
|
|
$a = parent::toArray($mode);
|
|
|
|
if ($this->hasFlag("attachtruthtable")) {
|
|
$a["truthtable"] = $this->getTruthtable();
|
|
}
|
|
|
|
if ($mode == "all") {
|
|
$a["missing_minterm_score"] = $this->missing_minterm_score;
|
|
}
|
|
|
|
return $a;
|
|
}
|
|
|
|
public function getMissingMintermScore(): float
|
|
{
|
|
return $this->missing_minterm_score;
|
|
}
|
|
|
|
public function setMissingMintermScore(float $missing_minterm_score): void
|
|
{
|
|
$this->missing_minterm_score = $missing_minterm_score;
|
|
}
|
|
|
|
protected function staticCheck(): void
|
|
{
|
|
$mark = 0.0;
|
|
$pa = $this->player_answer ?? "";
|
|
$iv = $this->getLogicFunction()->getInputVars();
|
|
$palf = new LogicFunction($pa, $iv);
|
|
if ($palf->isValid() && ((!$this->hasFlag("dnf")) || LogicFunction::isCorrectDNF($iv, $pa))) { // if the function is valid AND (if enabled) it is a correct DNF
|
|
$patt = $palf->getTruthTable();
|
|
$errs = $this->getTTDiffCntToCA($patt);
|
|
$mark = $this->getMaxMark() + $errs * $this->getMissingMintermScore();
|
|
}
|
|
$this->setMark($mark);
|
|
}
|
|
} |