Add stub for "call" judge action.

This commit is contained in:
2023-06-02 18:20:20 +08:00
parent d5ba09cbea
commit 832facdf5b
2 changed files with 61 additions and 13 deletions

View File

@@ -5,11 +5,18 @@ using System.Collections.Generic;
using System.Linq;
namespace Cryville.Crtr {
internal struct JudgeActionResult {
public bool BreakExecution;
public bool PreventRecycle;
}
public abstract class JudgeAction {
public static JudgeAction Construct(HashSet<string> a, string k) {
if (a.Remove("pass")) {
return new Pass(a, from i in k.Split(',') select new Identifier(i.Trim()));
}
else if (a.Remove("call")) {
return new Call(a, new Identifier(k));
}
else if (a.Remove("score")) {
return new Score(a, k);
}
@@ -20,14 +27,24 @@ namespace Cryville.Crtr {
annotations = a.ToHashSet();
}
public virtual void Optimize(PdtEvaluatorBase etor, PdtExpression value) { etor.Optimize(value); }
internal abstract bool Execute(IJudge judge, JudgeEvent ev, float time, PdtExpression exp, int depth);
internal abstract JudgeActionResult Execute(IJudge judge, JudgeEvent ev, float time, PdtExpression exp, bool onMiss, int depth, int index);
public class Call : JudgeAction {
readonly Identifier _target;
public Call(IEnumerable<string> a, Identifier k) : base(a) {
_target = k;
}
internal override JudgeActionResult Execute(IJudge judge, JudgeEvent ev, float time, PdtExpression exp, bool onMiss, int depth, int index) {
judge.Call(ev, time, _target, onMiss, index);
return new JudgeActionResult { BreakExecution = true, PreventRecycle = true };
}
}
public class Pass : JudgeAction {
readonly Identifier[] _targets;
public Pass(IEnumerable<string> a, IEnumerable<Identifier> k) : base(a) {
_targets = k.ToArray();
}
internal override bool Execute(IJudge judge, JudgeEvent ev, float time, PdtExpression exp, int depth) {
return judge.Pass(ev, time, _targets, depth);
internal override JudgeActionResult Execute(IJudge judge, JudgeEvent ev, float time, PdtExpression exp, bool onMiss, int depth, int index) {
return new JudgeActionResult { BreakExecution = judge.Pass(ev, time, _targets, depth) };
}
}
public class Score : JudgeAction {
@@ -42,9 +59,9 @@ namespace Cryville.Crtr {
base.Optimize(etor, value);
if (_op.op != default(Identifier)) PdtExpression.PatchCompound(_op.name.Key, _op.op.Key, value);
}
internal override bool Execute(IJudge judge, JudgeEvent ev, float time, PdtExpression exp, int depth) {
internal override JudgeActionResult Execute(IJudge judge, JudgeEvent ev, float time, PdtExpression exp, bool onMiss, int depth, int index) {
judge.UpdateScore(_op, exp);
return false;
return new JudgeActionResult();
}
}
}