Small code changes
This commit is contained in:
@@ -48,7 +48,7 @@ public class AI_Agent : MonoBehaviour
|
|||||||
actionInvoked = false;
|
actionInvoked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDrawGizmos()
|
private void OnDrawGizmosSelected()
|
||||||
{
|
{
|
||||||
Gizmos.color = Color.yellow;
|
Gizmos.color = Color.yellow;
|
||||||
Gizmos.DrawWireSphere(transform.position, taskRange);
|
Gizmos.DrawWireSphere(transform.position, taskRange);
|
||||||
|
|||||||
@@ -25,16 +25,19 @@ public class PlanNode
|
|||||||
states = new Dictionary<string, int>(allStates);
|
states = new Dictionary<string, int>(allStates);
|
||||||
|
|
||||||
foreach(KeyValuePair<string, int> state in agentStates)
|
foreach(KeyValuePair<string, int> state in agentStates)
|
||||||
|
{
|
||||||
if (!states.ContainsKey(state.Key))
|
if (!states.ContainsKey(state.Key))
|
||||||
|
{
|
||||||
states.Add(state.Key, state.Value);
|
states.Add(state.Key, state.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
this.action = action;
|
this.action = action;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AI_Planner
|
public class AI_Planner
|
||||||
{
|
{
|
||||||
private string planDescription;
|
private string m_PlanDescription;
|
||||||
|
|
||||||
public Queue<AI_Action> Plan(List<AI_Action> actions, Dictionary<string, int> goal, AIStates agentStates)
|
public Queue<AI_Action> Plan(List<AI_Action> actions, Dictionary<string, int> goal, AIStates agentStates)
|
||||||
{
|
{
|
||||||
@@ -58,7 +61,7 @@ public class AI_Planner
|
|||||||
}
|
}
|
||||||
|
|
||||||
PlanNode cheapest = null;
|
PlanNode cheapest = null;
|
||||||
foreach (PlanNode leaf in leaves)
|
foreach (var leaf in leaves)
|
||||||
{
|
{
|
||||||
if (cheapest == null)
|
if (cheapest == null)
|
||||||
cheapest = leaf;
|
cheapest = leaf;
|
||||||
@@ -66,8 +69,8 @@ public class AI_Planner
|
|||||||
cheapest = leaf;
|
cheapest = leaf;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<AI_Action> result = new List<AI_Action>();
|
var result = new List<AI_Action>();
|
||||||
PlanNode n = cheapest;
|
var n = cheapest;
|
||||||
while (n != null)
|
while (n != null)
|
||||||
{
|
{
|
||||||
if(n.action != null)
|
if(n.action != null)
|
||||||
@@ -77,17 +80,17 @@ public class AI_Planner
|
|||||||
n = n.parent;
|
n = n.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
Queue<AI_Action> queue = new Queue<AI_Action>();
|
var queue = new Queue<AI_Action>();
|
||||||
foreach(AI_Action action in result)
|
foreach(var action in result)
|
||||||
{
|
{
|
||||||
queue.Enqueue(action);
|
queue.Enqueue(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
planDescription = "";
|
m_PlanDescription = "";
|
||||||
int index = 0;
|
int index = 0;
|
||||||
foreach(AI_Action action in queue)
|
foreach(AI_Action action in queue)
|
||||||
{
|
{
|
||||||
planDescription += index + ": " + action.actionName + "\n";
|
m_PlanDescription += index + ": " + action.actionName + "\n";
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,6 +152,6 @@ public class AI_Planner
|
|||||||
|
|
||||||
public string GetPlanDescription()
|
public string GetPlanDescription()
|
||||||
{
|
{
|
||||||
return planDescription;
|
return m_PlanDescription;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,6 @@ namespace Scrips
|
|||||||
{
|
{
|
||||||
if (_currentStatePrint != null && planner != null)
|
if (_currentStatePrint != null && planner != null)
|
||||||
{
|
{
|
||||||
// _currentStatePrint.text = "Nurse 1 Action: " + currentAction.actionName + "\n" + planner.GetPlanString();
|
|
||||||
_currentStatePrint.text = "Patient 1 Action: " + currentAction.actionName + "\n";
|
_currentStatePrint.text = "Patient 1 Action: " + currentAction.actionName + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ public class Robot : AI_Agent {
|
|||||||
{
|
{
|
||||||
if (_currentStatePrint != null && planner != null && currentAction != null)
|
if (_currentStatePrint != null && planner != null && currentAction != null)
|
||||||
{
|
{
|
||||||
// _currentStatePrint.text = "Nurse 1 Action: " + currentAction.actionName + "\n" + planner.GetPlanString();
|
|
||||||
_currentStatePrint.text =
|
_currentStatePrint.text =
|
||||||
"Nurse 1 Action: " + currentAction.actionName + "\n" + planner.GetPlanDescription();
|
"Nurse 1 Action: " + currentAction.actionName + "\n" + planner.GetPlanDescription();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user