Somewhat better path finding
This commit is contained in:
parent
694936bb11
commit
800188cfaa
3 changed files with 11 additions and 11 deletions
|
@ -39,32 +39,32 @@ calc_new_y(AgY,_,Y) :- Y = AgY+2.
|
||||||
|
|
||||||
// if I am around the upper-left corner, move to upper-right corner
|
// if I am around the upper-left corner, move to upper-right corner
|
||||||
+around(X1,Y1) : quadrant(X1,Y1,X2,Y2) & free
|
+around(X1,Y1) : quadrant(X1,Y1,X2,Y2) & free
|
||||||
<- .print("in Q1 to ",X2,"x",Y1);
|
<- //.print("in Q1 to ",X2,"x",Y1);
|
||||||
!prep_around(X2,Y1).
|
!prep_around(X2,Y1).
|
||||||
|
|
||||||
// if I am around the bottom-right corner, move to upper-left corner
|
// if I am around the bottom-right corner, move to upper-left corner
|
||||||
+around(X2,Y2) : quadrant(X1,Y1,X2,Y2) & free
|
+around(X2,Y2) : quadrant(X1,Y1,X2,Y2) & free
|
||||||
<- .print("in Q4 to ",X1,"x",Y1);
|
<- //.print("in Q4 to ",X1,"x",Y1);
|
||||||
!prep_around(X1,Y1).
|
!prep_around(X1,Y1).
|
||||||
|
|
||||||
// if I am around the right side, move to left side two lines bellow
|
// if I am around the right side, move to left side two lines bellow
|
||||||
+around(X2,Y) : quadrant(X1,Y1,X2,Y2) & free
|
+around(X2,Y) : quadrant(X1,Y1,X2,Y2) & free
|
||||||
<- ?calc_new_y(Y,Y2,YF);
|
<- ?calc_new_y(Y,Y2,YF);
|
||||||
.print("in Q2 to ",X1,"x",YF);
|
//.print("in Q2 to ",X1,"x",YF);
|
||||||
!prep_around(X1,YF).
|
!prep_around(X1,YF).
|
||||||
|
|
||||||
// if I am around the left side, move to right side two lines bellow
|
// if I am around the left side, move to right side two lines bellow
|
||||||
+around(X1,Y) : quadrant(X1,Y1,X2,Y2) & free
|
+around(X1,Y) : quadrant(X1,Y1,X2,Y2) & free
|
||||||
<- ?calc_new_y(Y,Y2,YF);
|
<- ?calc_new_y(Y,Y2,YF);
|
||||||
.print("in Q3 to ", X2, "x", YF);
|
//.print("in Q3 to ", X2, "x", YF);
|
||||||
!prep_around(X2,YF).
|
!prep_around(X2,YF).
|
||||||
|
|
||||||
// last "around" was none of the above, go back to my quadrant
|
// last "around" was none of the above, go back to my quadrant
|
||||||
+around(X,Y) : quadrant(X1,Y1,X2,Y2) & free & Y <= Y2 & Y >= Y1
|
+around(X,Y) : quadrant(X1,Y1,X2,Y2) & free & Y <= Y2 & Y >= Y1
|
||||||
<- .print("in no Q, going to X1");
|
<- //.print("in no Q, going to X1");
|
||||||
!prep_around(X1,Y).
|
!prep_around(X1,Y).
|
||||||
+around(X,Y) : quadrant(X1,Y1,X2,Y2) & free & X <= X2 & X >= X1
|
+around(X,Y) : quadrant(X1,Y1,X2,Y2) & free & X <= X2 & X >= X1
|
||||||
<- .print("in no Q, going to Y1");
|
<- //.print("in no Q, going to Y1");
|
||||||
!prep_around(X,Y1).
|
!prep_around(X,Y1).
|
||||||
|
|
||||||
+around(X,Y) : quadrant(X1,Y1,X2,Y2)
|
+around(X,Y) : quadrant(X1,Y1,X2,Y2)
|
||||||
|
|
|
@ -99,15 +99,15 @@ public class WorldModel extends GridWorldModel {
|
||||||
result = pickLocation(ag, new Location(l.x + 1, l.y));
|
result = pickLocation(ag, new Location(l.x + 1, l.y));
|
||||||
if (!result)
|
if (!result)
|
||||||
result = pickLocation(ag, new Location(l.x + 1, l.y + 1));
|
result = pickLocation(ag, new Location(l.x + 1, l.y + 1));
|
||||||
if(!result)
|
|
||||||
System.out.println("Na itt baj van....");
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean pickLocation(int ag, Location l) {
|
public boolean pickLocation(int ag, Location l) {
|
||||||
if (hasObject(WorldModel.AGENT, l.x, l.y)) {
|
if (hasObject(WorldModel.AGENT, l.x, l.y)) {
|
||||||
if (!agWithVictim.contains(ag) && getAgentIdByLocation(l) < Constants.victimCount) {
|
int agentWithPos = getAgentIdByLocation(l);
|
||||||
|
if (!agWithVictim.contains(ag) && agentWithPos < Constants.victimCount) {
|
||||||
remove(WorldModel.AGENT, l.x, l.y);
|
remove(WorldModel.AGENT, l.x, l.y);
|
||||||
|
agPos[agentWithPos] = new Location(34,34);
|
||||||
agWithVictim.add(ag);
|
agWithVictim.add(ag);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,9 +38,9 @@ public class get_direction extends DefaultInternalAction {
|
||||||
}else if (to_x > agent_x && model.isFree(agent_x+1,agent_y)){
|
}else if (to_x > agent_x && model.isFree(agent_x+1,agent_y)){
|
||||||
sAction = "right";
|
sAction = "right";
|
||||||
}
|
}
|
||||||
if (to_y > agent_y && model.isFree(agent_x,agent_y+1)) {
|
if (to_y > agent_y && model.isFree(agent_x,agent_y+1) || sAction.equals("skip") && model.isFree(agent_x,agent_y+1)) {
|
||||||
sAction = "down";
|
sAction = "down";
|
||||||
} else if (to_y < agent_y && model.isFree(agent_x,agent_y-1)){
|
} else if (to_y < agent_y && model.isFree(agent_x,agent_y-1) || sAction.equals("skip") && model.isFree(agent_x,agent_y-1)){
|
||||||
sAction = "up";
|
sAction = "up";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue