private void FindNextActionAndExecute() { if (currentPlan.Count == 0) { Action next = GetNextAction(worldState); if (next.isMethod) { //we dont have a state after taking out //we dont have a state after trading //we have a state before executing method //we have a state after executing method //need a state at all points because of the thief //IDDEA: stash take out dont retake out StashAll stash = new StashAll(worldState); stash.IsValid(); TransferOUT transfer = new TransferOUT(stash.postConditions, next); //condition gets copied next.postConditions = transfer.postConditions.DeepCopy(); next.IsValid(); currentPlan.Enqueue(stash); currentPlan.Enqueue(transfer); currentPlan.Enqueue(next); } else { currentPlan.Enqueue(next); } } nextAction = currentPlan.Dequeue(); nextAction.Execute(this); DisplayActionUI(); /////////////////////////////////////// //counter++; //Debug.Log(counter); //Debug.Log("Executing : " + nextAction.toString()); /////////////////////////////////////// executingAction = true; }
private Action GetNextAction(State currentState) { List <Action> actions = new List <Action>(); Action[] trades = new Action[8] { new TradeWith_1(currentState), new TradeWith_2(currentState), new TradeWith_3(currentState), new TradeWith_4(currentState), new TradeWith_5(currentState), new TradeWith_6(currentState), new TradeWith_7(currentState), new TradeWith_8(currentState) }; for (int i = 0; i < trades.Length; i++) { //if preconditions are met, it's a possible action if (trades[i].IsValid()) { actions.Add(trades[i]); //Debug.Log("Possible : " + trades[i].toString()); } } //backpack is full && no more usefull trades to do if (actions.Count == 0) { //return stash function StashAll stash = new StashAll(currentState); stash.IsValid(); return(stash); } else { actions.Sort(); //Debug.Log("Out of : " + actions.Count); return(actions[actions.Count - 1]); //get last } }