Somewhat better path finding

This commit is contained in:
Balazs Toldi 2022-05-26 19:03:34 +02:00
parent 694936bb11
commit 800188cfaa
Signed by: Bazsalanszky
GPG key ID: 6C7D440036F99D58
3 changed files with 11 additions and 11 deletions

View file

@ -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
+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).
// if I am around the bottom-right corner, move to upper-left corner
+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).
// if I am around the right side, move to left side two lines bellow
+around(X2,Y) : quadrant(X1,Y1,X2,Y2) & free
<- ?calc_new_y(Y,Y2,YF);
.print("in Q2 to ",X1,"x",YF);
//.print("in Q2 to ",X1,"x",YF);
!prep_around(X1,YF).
// if I am around the left side, move to right side two lines bellow
+around(X1,Y) : quadrant(X1,Y1,X2,Y2) & free
<- ?calc_new_y(Y,Y2,YF);
.print("in Q3 to ", X2, "x", YF);
//.print("in Q3 to ", X2, "x", YF);
!prep_around(X2,YF).
// 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
<- .print("in no Q, going to X1");
<- //.print("in no Q, going to X1");
!prep_around(X1,Y).
+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).
+around(X,Y) : quadrant(X1,Y1,X2,Y2)

View file

@ -99,15 +99,15 @@ public class WorldModel extends GridWorldModel {
result = pickLocation(ag, new Location(l.x + 1, l.y));
if (!result)
result = pickLocation(ag, new Location(l.x + 1, l.y + 1));
if(!result)
System.out.println("Na itt baj van....");
return result;
}
public boolean pickLocation(int ag, Location l) {
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);
agPos[agentWithPos] = new Location(34,34);
agWithVictim.add(ag);
return true;
}

View file

@ -38,9 +38,9 @@ public class get_direction extends DefaultInternalAction {
}else if (to_x > agent_x && model.isFree(agent_x+1,agent_y)){
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";
} 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";
}
}