private void StartPlanning(IEnumerable <Item> everything, List <GOAPAction> actions, GOAPState goal) { var typeDict = new Dictionary <string, ItemType>() { { "mine", ItemType.Mine } , { "defense", ItemType.Defense } , { "cannon", ItemType.Cannon } , { "core", ItemType.Core } , { "workTable", ItemType.WorkTable } , { "waitZone", ItemType.WaitZone } }; var actDict = new Dictionary <string, IAAction>() { { "Pickup", IAAction.PickUp } , { "Create", IAAction.Create } , { "Upgrade", IAAction.Upgrade } , { "Attack", IAAction.Attack } , { "Wait", IAAction.Wait } , { "SuperAttack", IAAction.SuperAttack } }; var plan = GoapMiniTest.GoapRun(initial, goal, actions, true); if (plan == null) { print("Couldn't plan"); } else { var li = plan.Select(x => x.name).ToList(); print(li); _ia.SetPlan( plan .Select(pa => pa.name) .Select(a => { var i2 = everything.FirstOrDefault(i => typeDict.Any(kv => a.EndsWith(kv.Key)) ? i.type == typeDict.First(kv => a.EndsWith(kv.Key)).Value : false); if (actDict.Any(kv => a.StartsWith(kv.Key)) && i2 != null) { return(Tuple.Create(actDict.First(kv => a.StartsWith(kv.Key)).Value, i2)); } else { return(null); } }).Where(a => a != null) .ToList() ); if (firstTime) { firstTime = false; _ia.NextStep(); } } }
public List <Tuple <IAAction, Item> > RecalculatePlan(GOAPState curState) { var observedState = new Dictionary <string, bool>(); var nav = Navigation.instance; var everything = nav.AllItems(_ent.ownerType).Union(nav.AllInventories(_ent.ownerType)); List <GOAPAction> actions = CreatePossibleActionsList(); GOAPState goal = new GOAPState(); SetGoals(goal); var typeDict = new Dictionary <string, ItemType>() { { "mine", ItemType.Mine } , { "defense", ItemType.Defense } , { "cannon", ItemType.Cannon } , { "core", ItemType.Core } , { "workTable", ItemType.WorkTable } , { "waitZone", ItemType.WaitZone } }; var actDict = new Dictionary <string, IAAction>() { { "Pickup", IAAction.PickUp } , { "Create", IAAction.Create } , { "Upgrade", IAAction.Upgrade } , { "Attack", IAAction.Attack } , { "Wait", IAAction.Wait } , { "SuperAttack", IAAction.SuperAttack } }; var plan = GoapMiniTest.GoapRun(curState, goal, actions, aggressivePlan?true:false); return(plan .Select(pa => pa.name) .Select(a => { var i2 = everything.FirstOrDefault(i => typeDict.Any(kv => a.EndsWith(kv.Key)) ? i.type == typeDict.First(kv => a.EndsWith(kv.Key)).Value : false); if (actDict.Any(kv => a.StartsWith(kv.Key)) && i2 != null) { return Tuple.Create(actDict.First(kv => a.StartsWith(kv.Key)).Value, i2); } else { return null; } }).Where(a => a != null) .ToList()); }