|
From: <jom...@us...> - 2008-04-27 13:25:42
|
Revision: 1270
http://jason.svn.sourceforge.net/jason/?rev=1270&view=rev
Author: jomifred
Date: 2008-04-27 06:25:39 -0700 (Sun, 27 Apr 2008)
Log Message:
-----------
Jason team: implement some changes as discussed with Rafael
Modified Paths:
--------------
trunk/applications/jason-team/dummies.xml
trunk/applications/jason-team/gauchos.xml
trunk/applications/jason-team/src/asl/dummy.asl
trunk/applications/jason-team/src/asl/exploration.asl
trunk/applications/jason-team/src/asl/gaucho.asl
trunk/applications/jason-team/src/asl/herding.asl
trunk/applications/jason-team/src/java/arch/ACArchitecture.java
trunk/applications/jason-team/src/java/arch/ACProxy.java
trunk/applications/jason-team/src/java/arch/CowboyArch.java
trunk/applications/jason-team/src/java/env/WorldView.java
trunk/applications/jason-team/src/java/jia/Vec.java
trunk/applications/jason-team/src/java/jia/herd_position.java
trunk/applications/jason-team/src/java/test/TestBasicHerding.java
trunk/applications/jason-team/src/team-os.xml
Modified: trunk/applications/jason-team/dummies.xml
===================================================================
--- trunk/applications/jason-team/dummies.xml 2008-04-27 13:24:01 UTC (rev 1269)
+++ trunk/applications/jason-team/dummies.xml 2008-04-27 13:25:39 UTC (rev 1270)
@@ -30,7 +30,6 @@
<target name="user-init">
<copy file="../jason-moise/lib/jmoise.jar" todir="lib" />
<copy file="../jason-moise/lib/moise.jar" todir="lib" />
- <copy file="../jason-moise/src/asl/moise-common.asl" todir="src/asl" />
</target>
<target name="user-end">
</target>
Modified: trunk/applications/jason-team/gauchos.xml
===================================================================
--- trunk/applications/jason-team/gauchos.xml 2008-04-27 13:24:01 UTC (rev 1269)
+++ trunk/applications/jason-team/gauchos.xml 2008-04-27 13:25:39 UTC (rev 1270)
@@ -30,7 +30,6 @@
<target name="user-init">
<copy file="../jason-moise/lib/jmoise.jar" todir="lib" />
<copy file="../jason-moise/lib/moise.jar" todir="lib" />
- <copy file="../jason-moise/src/asl/moise-common.asl" todir="src/asl" />
</target>
<target name="user-end">
</target>
Modified: trunk/applications/jason-team/src/asl/dummy.asl
===================================================================
--- trunk/applications/jason-team/src/asl/dummy.asl 2008-04-27 13:24:01 UTC (rev 1269)
+++ trunk/applications/jason-team/src/asl/dummy.asl 2008-04-27 13:25:39 UTC (rev 1270)
@@ -30,7 +30,8 @@
pos(AgX,AgY,_) &
jia.random(RX,40) & RX > 5 & X = (RX-20)+AgX & X > 0 &
jia.random(RY,40,5) & RY > 5 & Y = (RY-20)+AgY &
- not jia.obstacle(X,Y).
+ not jia.obstacle(X,Y) &
+ not cell(X,Y,_).
/* -- initial goal */
@@ -47,7 +48,7 @@
// revise target each 4 steps
+pos(Step,_,_) // new cycle
- : Step mod 10 == 0
+ : Step mod 6 == 0
<- !decide_target.
@@ -66,7 +67,6 @@
-+target(X,Y).
+!decide_target // chose a new random pos
- : not cell(_,_,cow(_))
<- ?random_pos(NX,NY);
.print("New random target: ",NX,",",NY);
-+goal(search);
Modified: trunk/applications/jason-team/src/asl/exploration.asl
===================================================================
--- trunk/applications/jason-team/src/asl/exploration.asl 2008-04-27 13:24:01 UTC (rev 1269)
+++ trunk/applications/jason-team/src/asl/exploration.asl 2008-04-27 13:25:39 UTC (rev 1270)
@@ -3,11 +3,6 @@
/* -- initial beliefs -- */
-// missions I can commit to depend on the roles I adopt
-desired_mission(explore_sch, explore) :- desired_role(exploration_grp, explorer).
-desired_mission(explore_sch, scout) :- desired_role(exploration_grp, scouter).
-
-
/* -- initial goals -- */
//!test.
@@ -19,11 +14,10 @@
*/
-/* plans for agent 1 */
+/* plans for the team's groups creation */
-+gsize(_Weight,_Height) // new match has started
- : .my_name(gaucho1) // agent 1 is responsible for the team creation
- <- //.print("oooo creating team group");
++!create_team_group
+ <- .print("oooo creating team group");
.if( group(team,Old), {
jmoise.remove_group(Old)
});
@@ -31,13 +25,13 @@
+group(team,GId) // agent 1 is responsible for the creation of exploration groups
: .my_name(gaucho1)
- <- jmoise.create_group(exploration,GId);
- jmoise.create_group(exploration,GId);
- jmoise.create_group(exploration,GId).
-+group(exploration,_) // compute the area of the groups
+ <- jmoise.create_group(exploration_grp,GId);
+ jmoise.create_group(exploration_grp,GId);
+ jmoise.create_group(exploration_grp,GId).
++group(exploration_grp,_) // compute the area of the groups
: .my_name(gaucho1) &
- .findall(GId, group(exploration,GId), LG) &
- LG = [G1,G2,G3] // there are three groups
+ .findall(GId, group(exploration_grp,GId), LG) &
+ LG = [G1,G2,G3] // there are three groups
<- ?gsize(W,H);
X = math.round(((W*H)/3)/H);
+group_area(0, G1, area(0, 0, X, H-1));
@@ -51,24 +45,28 @@
/* plans for agents with odd id */
-+gsize(_,_)
++gsize(_,_) // new match has started
: .my_name(Me) &
agent_id(Me,AgId) &
AgId mod 2 == 1 // I have an odd Id
- <- .print("ooo Recruiting scouters for my explorer group....");
+ <- .if( .my_name(gaucho1), {
+ !create_team_group
+ });
+ .print("ooo Recruiting scouters for my explorer group....");
+
// wait my pos
?pos(MyX,MyY,_);
// wait others pos
- .while( .count(cell(_,_,ally(_)), N) & N < 5, {
+ .while( .count(ally_pos(_,_,_), N) & N < 5, {
.print("ooo waiting others pos ");
- .wait("+cell(_,_,ally(_))", 500, nofail)
+ .wait("+ally_pos(_,_,_)", 500, nofail)
});
// find distance to even agents
.findall(ag_d(D,AgName),
- cell(X,Y,ally(AgName)) & agent_id(AgName,Id) & Id mod 2 == 0 & jia.dist(MyX, MyY, X, Y, D),
+ ally_pos(AgName,X,Y) & agent_id(AgName,Id) & Id mod 2 == 0 & jia.dist(MyX, MyY, X, Y, D),
LOdd);
.sort(LOdd, LSOdd);
@@ -78,15 +76,13 @@
// adopt role explorer in the group
jmoise.adopt_role(explorer,G);
- +desired_role(exploration_grp, explorer); // needed for moise-common plans
- +desired_role(herding_grp, herder); // explorers will also be herders
!find_scouter(LSOdd, G).
+!find_scouter([],_)
<- .print("ooo I did not find a scouter to work with me!").
+!find_scouter([ag_d(_,AgName)|_],GId)
<- .print("ooo Ask ",AgName," to play scouter");
- .send(AgName, achieve, play_role(scouter,GId,exploration_grp));
+ .send(AgName, achieve, play_role(scouter,GId));
.wait("+play(Ag,scouter,GId)",2000).
-!find_scouter([_|LSOdd],GId) // in case the wait fails, try next agent
<- .print("ooo find_scouter failure, try another agent.");
@@ -96,23 +92,9 @@
+play(Ag,explorer,G)
: .my_name(Ag) &
not scheme_group(_,G)
- <- jmoise.create_scheme(exploring, [G]).
+ <- jmoise.create_scheme(explore_sch, [G]).
-/* plans for the others */
-
-+!play_role(Role,Group,Group_Spec)[source(Ag)]
- <- .print("ooo Adopting role ",Role,", asked by ",Ag);
- jmoise.adopt_role(Role, Group);
- +desired_role(Group_Spec, Role).
-
-// to keep plan above generic...
-// scouters will be herdboys
-// and need to tell t
-+desired_role(exploration_grp, scouter)
- <- +desired_role(herding_grp, herdboy).
-
-
/* -- plans for the goals of role explorer -- */
// TODO: make a pattern for organisational maintainance goal
@@ -120,7 +102,7 @@
+!goto_near_unvisited[scheme(Sch)]
<- .print("ooo I should find the nearest unvisited location and go there!");
.my_name(Me);
- ?play(Me,explorer,GroupId); // get the group where I play explorer
+ ?play(Me,explorer,GroupId); // get the group where I play explorer
?group_area(_,GroupId, Area); // get the area of this group
?pos(MeX, MeY, _); // get my location
jia.near_least_visited(MeX, MeY, Area, TargetX, TargetY);
@@ -143,17 +125,3 @@
.wait("+pos(_,_,_)"); // wait next cycle
!!follow_leader[scheme(Sch)].
-/* -- plans for the goals of all roles -- */
-
-+!share_seen_cows[scheme(Sch)]
- <- .print("ooo I should share cows!");
- ?cows_to_inform(C);
- jmoise.broadcast(Sch, tell, C);
- .wait("+pos(_,_,_)"); // wait next cycle
- !!share_seen_cows[scheme(Sch)].
-
-+cell(X,Y,cow(Id))
- <- +cow(Id,X,Y); //Jomi, tu nao vai gostar disso :D
- ?cows_to_inform(C);
- -+cows_to_inform([cow(Id,X,Y)|C]).
-
Modified: trunk/applications/jason-team/src/asl/gaucho.asl
===================================================================
--- trunk/applications/jason-team/src/asl/gaucho.asl 2008-04-27 13:24:01 UTC (rev 1269)
+++ trunk/applications/jason-team/src/asl/gaucho.asl 2008-04-27 13:25:39 UTC (rev 1270)
@@ -44,7 +44,7 @@
+?group_area(Id,G,A) <- .wait("+group_area(Id,G,A)").
+end_of_simulation(_Result)
- <- .abolish(area(_,_,_,_,_,_)).
+ <- .abolish(group_area(_,_,_)).
+!restart
<- .print("*** restart ***");
@@ -53,10 +53,79 @@
// TODO: what to do?
//!decide_target.
+
+/* -- plans for the goals of all roles -- */
+
+// get the list G of participants of the group where I play R
++?my_group_players(G,R)
+ <- .my_name(Me);
+ play(Me,R,Gid);
+ .findall(P, play(P,_,Gid), G).
+
++!play_role(Role,Group)[source(Ag)]
+ : .my_name(Me) & not play(Me,_,_) // I can not play more than one role
+ <- .print("ooo Adopting role ",Role,", asked by ",Ag);
+ jmoise.adopt_role(Role, Group).
++!play_role(Role,Group)[source(Ag)]
+ <- .print("ooo Can NOT adopt role ",Role,", asked by ",Ag).
+
+/*
+
+TODO: use a list given by BUF
+
++!share_seen_cows[scheme(Sch)]
+ <- .print("ooo I should share cows!");
+ ?cows_to_inform(C);
+ jmoise.broadcast(Sch, tell, C);
+ // TODO: limpar -+cows_to_inform([])
+ .wait("+pos(_,_,_)"); // wait next cycle
+ !!share_seen_cows[scheme(Sch)].
+
++?cows_to_inform([]).
+
++cell(X,Y,cow(Id))
+ <- +cow(Id,X,Y); //Jomi, tu nao vai gostar disso :D
+ ?cows_to_inform(C);
+ -+cows_to_inform([cow(Id,X,Y)|C]).
+
+*/
+
++!share_seen_cows.
+
+// simple implementation of share_cows (see TODO above)
++cell(X,Y,cow(_))
+ : .my_name(Me) & play(Me,_,Gr)
+ <- C = cow(X,Y);
+ +C;
+ jmoise.broadcast(Gr, tell, C).
+-cell(X,Y,cow(_))
+ : .my_name(Me) & play(Me,_,Gr)
+ <- C = cow(X,Y);
+ -C;
+ jmoise.broadcast(Gr, untell, C).
+
+
+
+/* -- general organisational plans -- */
+
+// when I have an obligation or permission to a mission, commit to it
++obligation(Sch, Mission)
+ <- jmoise.commit_mission(Mission,Sch).
++permission(Sch, Mission)
+ <- jmoise.commit_mission(Mission,Sch).
+
+// if some scheme is finished, drop all intentions related to it.
+-scheme(_Spec,Id)
+ <- .drop_desire(_[scheme(Id)]).
+
++error(M)[source(orgManager)]
+ <- .print("Error in organisational action: ",M); -error(M)[source(orgManager)].
+
+
/* -- includes -- */
{ include("goto.asl") } // include plans for moving around
{ include("exploration.asl") } // include plans for exploration
{ include("herding.asl") } // include plans for herding
-{ include("moise-common.asl") } // include common plans for MOISE+ agents
+// { include("moise-common.asl") } // include common plans for MOISE+ agents
Modified: trunk/applications/jason-team/src/asl/herding.asl
===================================================================
--- trunk/applications/jason-team/src/asl/herding.asl 2008-04-27 13:24:01 UTC (rev 1269)
+++ trunk/applications/jason-team/src/asl/herding.asl 2008-04-27 13:25:39 UTC (rev 1270)
@@ -2,11 +2,7 @@
/* -- initial beliefs -- */
-// missions I can commit to
-desired_mission(herd_sch, herd) :- desired_role(herding_grp, herder).
-desired_mission(herd_sch, help_herder) :- desired_role(herding_grp, herdboy).
-
/* -- plans for the goals of role herder -- */
+!recruit[scheme(Sch)]
@@ -26,15 +22,6 @@
.wait("+pos(_,_,_)"); // wait next cycle
!!define_formation[scheme(Sch)].
-// get the list G of participants of the group where I play R
-+?my_group(G,R)
- <- .my_name(Me);
- play(Me,R,Gid);
- .findall(P, play(P,_,Gid), G);
- +my_group(G,R).
-// TODO, IMPORTANT: Quando tiver mudanca no grupo, apagar essa crenca
-// pra deixar esse plano rodar de novo.
-
+!alloc_all([],LA).
+!alloc_all([HA|TA],LA)
<- !find_closest(HA,LA,pos(X,Y),NLA);
@@ -42,21 +29,20 @@
-+alloc_target(HA,Alloc);
!alloc_all(TA,NLA).
-+!find_closest(Ag, List, Alloc, Rest)
- <- ?alloc_target(Ag,pos(X,Y));
++!find_closest(Ag, List, Alloc, Rest) // rule
+ <- ?ally_pos(Ag,XY);
!closest(List,[],Sorted,pos(X,Y),9999);
Sorted = [Alloc|Rest];
.print("FIND CLOSEST: ",Sorted).
-
+// TODO: use min
+!closest([],S,S,P,D).
+!closest([pos(XH,YH)|T],Aux,S,pos(XP,YP),LD)
- : jia.dist(XH,YH,XP,YP,D) & D < LD
+ : jia.dist(XH,YH,XP,YP,D) & D < LD // usar A*
<- !closest(T,[pos(XH,YH)|Aux],S,pos(XP,YP),D).
+!closest([pos(XH,YH)|T],Aux,S,pos(XP,YP),LD)
<- .concat(Aux,[pos(XH,YH)],Aux2);
!closest(T,Aux2,S,pos(XP,YP),LD).
-+?alloc_target(Ag,X,Y) <- .send(Ag, askOne, pos(X,Y,_), pos(X,Y,_)).
/* -- plans for the goals of all roles (herder and herdboy) -- */
Modified: trunk/applications/jason-team/src/java/arch/ACArchitecture.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/ACArchitecture.java 2008-04-27 13:24:01 UTC (rev 1269)
+++ trunk/applications/jason-team/src/java/arch/ACArchitecture.java 2008-04-27 13:25:39 UTC (rev 1270)
@@ -46,15 +46,15 @@
String password = stts.getUserParameter("password");
if (password.startsWith("\"")) password = password.substring(1,password.length()-1);
+ waitSleepThread = new WaitSleep();
+ waitSleepThread.start();
+
proxy = new ACProxy( this,
stts.getUserParameter("host"),
Integer.parseInt(stts.getUserParameter("port")),
username,
password);
new Thread(proxy,"AgentProxy"+username).start();
-
- waitSleepThread = new WaitSleep();
- waitSleepThread.start();
}
Modified: trunk/applications/jason-team/src/java/arch/ACProxy.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/ACProxy.java 2008-04-27 13:24:01 UTC (rev 1269)
+++ trunk/applications/jason-team/src/java/arch/ACProxy.java 2008-04-27 13:25:39 UTC (rev 1270)
@@ -152,9 +152,7 @@
// add location in perception
Literal lpos = new Literal("pos");
- lpos.addTerm(new NumberTermImpl(agx));
- lpos.addTerm(new NumberTermImpl(agy));
- lpos.addTerm(new NumberTermImpl(step));
+ lpos.addTerms(new NumberTermImpl(agx), new NumberTermImpl(agy), new NumberTermImpl(step));
percepts.add(lpos);
arq.initKnownCows();
Modified: trunk/applications/jason-team/src/java/arch/CowboyArch.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/CowboyArch.java 2008-04-27 13:24:01 UTC (rev 1269)
+++ trunk/applications/jason-team/src/java/arch/CowboyArch.java 2008-04-27 13:25:39 UTC (rev 1270)
@@ -9,7 +9,6 @@
import jason.asSyntax.Literal;
import jason.asSyntax.NumberTerm;
import jason.asSyntax.NumberTermImpl;
-import jason.asSyntax.Structure;
import jason.asSyntax.Term;
import jason.environment.grid.Location;
import jason.mas2j.ClassParameters;
@@ -237,9 +236,9 @@
public static Literal createCellPerception(int x, int y, Term obj) {
Literal l = new Literal("cell");
- l.addTerm(new NumberTermImpl(x));
- l.addTerm(new NumberTermImpl(y));
- l.addTerm(obj);
+ l.addTerms(new NumberTermImpl(x),
+ new NumberTermImpl(y),
+ obj);
return l;
}
@@ -358,9 +357,9 @@
if (acView != null) acView.getModel().setAgPos(agid, x, y);
model.incVisited(x, y);
//getTS().getAg().getLogger().info("ag pos "+getMinerId(m.getSender())+" = "+x+","+y);
- Structure tAlly = new Structure("ally");
- tAlly.addTerm(new Atom(m.getSender()));
- getTS().getAg().addBel( createCellPerception(x, y, tAlly));
+ Literal tAlly = new Literal("ally_pos");
+ tAlly.addTerms(new Atom(m.getSender()), new NumberTermImpl(x), new NumberTermImpl(y));
+ getTS().getAg().addBel( tAlly );
} catch (Exception e) {
e.printStackTrace();
}
Modified: trunk/applications/jason-team/src/java/env/WorldView.java
===================================================================
--- trunk/applications/jason-team/src/java/env/WorldView.java 2008-04-27 13:24:01 UTC (rev 1269)
+++ trunk/applications/jason-team/src/java/env/WorldView.java 2008-04-27 13:25:39 UTC (rev 1270)
@@ -6,6 +6,8 @@
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionListener;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
@@ -27,7 +29,7 @@
JLabel jCycle;
JLabel jCowsC;
- //JLabel jlMouseLoc;
+ JLabel jlMouseLoc;
//JComboBox scenarios;
//JSlider jSpeed;
@@ -96,16 +98,15 @@
msg.setBorder(BorderFactory.createEtchedBorder());
+ JPanel pmoise = new JPanel(new FlowLayout(FlowLayout.CENTER));
+ //p.add(new JLabel("Click on the cells to add new pieces of gold."));
+ //pmoise.add(new JLabel(" (mouse at:"));
+ jlMouseLoc = new JLabel("0,0");
+ pmoise.add(jlMouseLoc);
+ pmoise.setBorder(BorderFactory.createEtchedBorder());
+ //msg.add(p);
+
JPanel p = new JPanel(new FlowLayout(FlowLayout.CENTER));
- /*
- p.add(new JLabel("Click on the cells to add new pieces of gold."));
- p.add(new JLabel(" (mouse at:"));
- jlMouseLoc = new JLabel("0,0)");
- p.add(jlMouseLoc);
- msg.add(p);
- */
-
- p = new JPanel(new FlowLayout(FlowLayout.CENTER));
p.add(new JLabel("Cycle:"));
jCycle = new JLabel("0");
p.add(jCycle);
@@ -119,6 +120,7 @@
JPanel s = new JPanel(new BorderLayout());
s.add(BorderLayout.WEST, args);
s.add(BorderLayout.CENTER, msg);
+ s.add(BorderLayout.EAST, pmoise);
getContentPane().add(BorderLayout.SOUTH, s);
// Events handling
@@ -160,18 +162,16 @@
});
*/
- /*
getCanvas().addMouseMotionListener(new MouseMotionListener() {
public void mouseDragged(MouseEvent e) { }
public void mouseMoved(MouseEvent e) {
int col = e.getX() / cellSizeW;
int lin = e.getY() / cellSizeH;
if (col >= 0 && lin >= 0 && col < getModel().getWidth() && lin < getModel().getHeight()) {
- jlMouseLoc.setText(col+","+lin+")");
+ jlMouseLoc.setText(col+","+lin);
}
}
});
- */
}
/*
Modified: trunk/applications/jason-team/src/java/jia/Vec.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/Vec.java 2008-04-27 13:24:01 UTC (rev 1269)
+++ trunk/applications/jason-team/src/java/jia/Vec.java 2008-04-27 13:25:39 UTC (rev 1270)
@@ -54,6 +54,16 @@
while (t < 0) t = t + PI2;
return new Vec(r*Math.cos(t), r*Math.sin(t));
}
+
+ /** turn the vec to 90 degrees clockwise */
+ public Vec turn90CW() {
+ return new Vec(y, -x);
+ }
+ /** turn the vec to 90 degrees anticlockwise */
+ public Vec turn90ACW() {
+ return new Vec(-y, x);
+ }
+
public Vec newMagnitude(double r) {
return new Vec(r*Math.cos(t), r*Math.sin(t));
}
Modified: trunk/applications/jason-team/src/java/jia/herd_position.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/herd_position.java 2008-04-27 13:24:01 UTC (rev 1269)
+++ trunk/applications/jason-team/src/java/jia/herd_position.java 2008-04-27 13:25:39 UTC (rev 1270)
@@ -83,8 +83,7 @@
ListTerm tail = r;
for (Location l: locs) {
Structure p = new Structure("pos",2);
- p.addTerm(new NumberTermImpl(l.x));
- p.addTerm(new NumberTermImpl(l.y));
+ p.addTerms(new NumberTermImpl(l.x), new NumberTermImpl(l.y));
tail = tail.append(p);
}
return un.unifies(args[1], r);
@@ -103,9 +102,10 @@
List<Location> locs = formationPlaces(model, formation);
if (locs != null) {
for (Location l : locs) {
- r = l;
if (ag.equals(l) || // I am there
- !model.hasObject(WorldModel.AGENT, l)) { // no one else is there
+ //model.countObjInArea(WorldModel.AGENT, l, 1) == 0) { // no one else is there
+ !model.hasObject(WorldModel.AGENT, l)) {
+ r = l;
break;
}
}
@@ -153,14 +153,20 @@
int initAgTS = 1;
for (int dist: formation.getDistances()) { // 2, -2, 6, -6, ....
Vec agTarget = agsTarget;
- Location l = agTarget.add(mean).getLocation(model);
+ //Location l = agTarget.add(mean).getLocation(model);
- //System.out.println("....... "+dist+" antes angle "+agTarget);
+ System.out.println("....... "+dist+" antes angle "+agTarget);
if (dist >= 0)
- agTarget = new Vec( -agTarget.y, agTarget.x);
+ agTarget = agTarget.turn90CW();
else
- agTarget = new Vec( agTarget.y, -agTarget.x);
+ agTarget = agTarget.turn90ACW();
+ Location l = findFirstFreeLocTowardsTarget(agTarget, mean.add(agsTarget), initAgTS, dist, model);
+ System.out.println(" = "+dist+" result "+l);
+ if (l != null)
+ r.add(pathToNearCow(model, l));
+
+ /*
Location lastloc = null;
boolean uselast = false;
for (int agTargetSize = initAgTS; agTargetSize <= Math.abs(dist); agTargetSize++) {
@@ -175,13 +181,29 @@
}
if (!uselast)
r.add(pathToNearCow(model, l));
+ */
+
if (dist < 0)
initAgTS = Math.abs(dist)+1;
}
- //System.out.println("all places "+r);
+ System.out.println("all places "+r);
return r;
}
+ private Location findFirstFreeLocTowardsTarget(Vec target, Vec ref, int initialSize, int maxSize, LocalWorldModel model) {
+ Location lastloc = null;
+ maxSize = Math.abs(maxSize);
+ Location l = ref.getLocation(model);;
+ for (int s = initialSize; s <= maxSize; s++) {
+ l = target.newMagnitude(s).add(ref).getLocation(model);
+ System.out.println("pos angle "+s+" = "+l);
+ if ( (!model.inGrid(l) || model.hasObject(WorldModel.OBSTACLE, l)) && lastloc != null)
+ return lastloc;
+ lastloc = l;
+ }
+ return l; //ref.getLocation(model); //target.add(ref).getLocation(model);
+ }
+
private Location pathToNearCow(LocalWorldModel model, Location t) {
Location near = null;
for (Location c: model.getCows()) {
@@ -194,7 +216,7 @@
//System.out.println("Near cow to "+t+" is "+near+" vec = "+dircow);
for (int s = 1; s <= 20; s++) {
Location l = dircow.newMagnitude(s).add(nearcv).getLocation(model);
- if (model.isFree(l))
+ if (!model.hasObject(WorldModel.COW,l))
return l;
}
}
Modified: trunk/applications/jason-team/src/java/test/TestBasicHerding.java
===================================================================
--- trunk/applications/jason-team/src/java/test/TestBasicHerding.java 2008-04-27 13:24:01 UTC (rev 1269)
+++ trunk/applications/jason-team/src/java/test/TestBasicHerding.java 2008-04-27 13:25:39 UTC (rev 1270)
@@ -152,17 +152,32 @@
assertEquals(new Location(6,38), byIA);
byIA = new herd_position().getAgTarget(model, Formation.six, cowboy.getLocation(model));
- assertEquals(new Location(5,38), byIA);
+ assertEquals(new Location(6,39), byIA);
+ // add an agent in 6,39
+ model.add(WorldModel.AGENT, 6,39);
+ byIA = new herd_position().getAgTarget(model, Formation.six, cowboy.getLocation(model));
+ assertEquals(new Location(5,38), byIA);
+
// add an agent in 5,38
model.add(WorldModel.AGENT, 5,38);
- byIA = new herd_position().getAgTarget(model, Formation.six, cowboy.getLocation(model));
+ byIA = new herd_position().getAgTarget(model, Formation.six,cowboy.getLocation(model));
assertEquals(new Location(7,42), byIA);
- // add an agent in 7,42
+ // add an agent in 7,42
model.add(WorldModel.AGENT, 7,42);
byIA = new herd_position().getAgTarget(model, Formation.six,cowboy.getLocation(model));
- assertEquals(new Location(8,42), byIA);
+ assertEquals(new Location(4,38), byIA);
+
+ // add an agent in 4,38
+ model.add(WorldModel.AGENT, 4,38);
+ byIA = new herd_position().getAgTarget(model, Formation.six,cowboy.getLocation(model));
+ assertEquals(null, byIA);
+
+ // add an agent in 5,37
+ //model.add(WorldModel.AGENT, 5,37);
+ //byIA = new herd_position().getAgTarget(model, Formation.six,cowboy.getLocation(model));
+ //assertEquals(new Location(5,37), byIA);
}
@Test
Modified: trunk/applications/jason-team/src/team-os.xml
===================================================================
--- trunk/applications/jason-team/src/team-os.xml 2008-04-27 13:24:01 UTC (rev 1269)
+++ trunk/applications/jason-team/src/team-os.xml 2008-04-27 13:25:39 UTC (rev 1270)
@@ -108,10 +108,10 @@
</functional-specification>
<deontic-specification>
- <deontic-relation type="obligation" role="explorer" mission="mexplore" />
- <deontic-relation type="obligation" role="scouter" mission="mscout" />
- <deontic-relation type="obligation" role="herder" mission="mherd" />
- <deontic-relation type="obligation" role="herdboy" mission="mhelp_herder" />
+ <deontic-relation type="obligation" role="explorer" mission="explore" />
+ <deontic-relation type="obligation" role="scouter" mission="scout" />
+ <deontic-relation type="obligation" role="herder" mission="herd" />
+ <deontic-relation type="obligation" role="herdboy" mission="help_herder" />
</deontic-specification>
</organisational-specification>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|