public void splice(Actions.ActionChain wrapped) { var test = FindFirst(wrapped.ConcreteAction); if (int.MaxValue == test.Key) { Add(wrapped); return; } var prefix_cache = m_Candidates[test.Key]; var prefix_match = prefix_cache[test.Value]; prefix_cache.RemoveAt(test.Value); if (0 >= prefix_cache.Count) { m_Candidates.Remove(test.Key); } if (!(prefix_match is Actions.ActionChain chain)) { Add(wrapped); return; } var replace = chain.splice(wrapped); if (null != replace) { Add(replace); } }
private static void _add(Dictionary <int, List <Actions.ActionChain> > dest, Actions.ActionChain src) { int cost = (src is Actions.ActionChain chain) ? chain.CumulativeMoveCost() : Map.PathfinderMoveCosts(src); if (dest.TryGetValue(cost, out var cache)) { cache.Add(src); } else { dest.Add(cost, new List <Actions.ActionChain> { src }); } }
private static void _add(Dictionary <int, List <Actions.ActionChain> > dest, Actions.ActionChain src) { int cost = src.CumulativeMoveCost(); if (dest.TryGetValue(cost, out var cache)) { cache.Add(src); } else { dest.Add(cost, new List <Actions.ActionChain> { src }); } }
bool backward_chain() { int act_cost = m_Candidates.Keys.Min(); var cache = m_Candidates[act_cost]; var working = new List <Actions.ActionChain>(); int ub = cache.Count; while (0 <= --ub) { var dest = cache[ub]; var setup = CanBackwardPlan(dest); if (null == setup) { throw new ArgumentNullException(nameof(setup)); // invariant failure } foreach (var x in setup) { var test = new Actions.ActionChain(x, dest); if (!test.IsSemanticParadox()) { working.Add(test); } } cache.RemoveAt(ub); if (0 >= working.Count) { continue; } foreach (var chain in working) { splice(chain); } return(true); } return(false); }