/************************************************************************************/ /**** javajess.java *******************************************************/ /************************************************************************************/ package equips; import java.io.*; import EDU.gatech.cc.is.util.Vec2; import EDU.gatech.cc.is.abstractrobot.*; import jess.*; public class javajess extends ControlSystemSS { public void Configure() { } public int TakeStep() { Vec2 result,ball,jug0=new Vec2(0,0),jug1=new Vec2(); Vec2 array[]; long curr_time = abstract_robot.getTime(); NullDisplay nd = new NullDisplay(); // posicio de la pilota ball = abstract_robot.getBall(curr_time); // posicio dels jugadors array=abstract_robot.getTeammates(curr_time); if (array.length>0) jug1=array[0]; try { Rete jess_engine=new Rete(nd); FileInputStream clp=new FileInputStream("decisio.clp"); Jesp parser=new Jesp(clp,jess_engine); // passo les dades jess_engine.store("pilotax",new Value(ball.x, RU.FLOAT)); jess_engine.store("pilotay",new Value(ball.y, RU.FLOAT)); jess_engine.store("jugador0x",new Value(jug0.x,RU.FLOAT)); jess_engine.store("jugador0y",new Value(jug0.y,RU.FLOAT)); jess_engine.store("jugador1x",new Value(jug1.x,RU.FLOAT)); jess_engine.store("jugador1y",new Value(jug1.y,RU.FLOAT)); // executo el fitxer decisio.clp do { parser.parse(false); } while (clp.available()>0); // segons la decisio presa executo una accio o altra if (jess_engine.fetch("ir").intValue()==0) { // fem que el robot apunti a la pilota abstract_robot.setSteerHeading(curr_time, ball.t); // que vagi corren abstract_robot.setSpeed(curr_time, 1.0); // que xuti si pot if (abstract_robot.canKick(curr_time)) abstract_robot.kick(curr_time); } else { // fem que el robot apunti a la porteria abstract_robot.setSteerHeading(curr_time, abstract_robot.getOurGoal(curr_time).t); // que vagi corren abstract_robot.setSpeed(curr_time, 1.0); } } catch (ReteException re) { re.printStackTrace(nd.stderr()); } catch (FileNotFoundException fnf) { } catch (IOException ioe) { } // tell the parent we're OK return(CSSTAT_OK); } } /************************************************************************************/ /**** decisio.clp *******************************************************/ /************************************************************************************/ (deffacts inicio (fet obtenir_posicions) ) (defrule qui_pilota ?pos<-(fet obtenir_posicions) => (assert (x0 (fetch "jugador0x"))) (assert (y0 (fetch "jugador0y"))) (assert (x1 (fetch "jugador1x"))) (assert (y1 (fetch "jugador1y"))) (assert (px (fetch "pilotax"))) (assert (py (fetch "pilotay"))) ) (defrule calculadist ?a<-(x0 ?x0) ?b<-(y0 ?y0) ?c<-(x1 ?x1) ?d<-(y1 ?y1) ?e<-(px ?px) ?f<-(py ?py) => (bind ?dist0 (+ (* (- ?x0 ?px) (- ?x0 ?px)) (*(- ?y0 ?py) (- ?y0 ?py)))) (bind ?dist1 (+ (* (- ?x1 ?px) (- ?x1 ?px)) (*(- ?y1 ?py) (- ?y1 ?py)))) (retract ?a ?b ?c ?d ?e ?f) (assert (dist0 ?dist0)) (assert (dist1 ?dist1)) ) (defrule si_jug0 ?a<-(dist0 ?d0) ?b<-(dist1 ?d1&:(> ?d1 ?d0)) => (retract ?a ?b) (store "ir" 0) ) (defrule si_jug1 ?a<-(dist0 ?d0) ?b<-(dist1 ?d1&:(<= ?d1 ?d0)) => (retract ?a ?b) (store "ir" 1) ) (reset) (run) /************************************************************************************/ /**** robocup.dsc *******************************************************/ /************************************************************************************/ // This description file specifies the environment for a RoboCup // soccer game simulation in the JavaBotSim simulator. //====== // SIMULATION BOUNDARY //====== // // bounds left right bottom top // // bounds statements set the bounds of the visible "playing field" in // meters for a simulation. If the aspect ratio of the bounds are not // the same as the graphical area set aside by the simulation, then // the robots may wander off the screen. This will be fixed (eventually!) // These are the bounds of a RoboCup field "base." The actual field walls // are a little bit smaller, but we reserve all this space so the complete // field can be drawn bounds -1.47 1.47 -.8625 .8625 //====== // SEED //====== // // seed number // // The seed statement sets the random number seed. The default is // -1 seed 3 //====== // TIME //====== // // time accel_rate // // The time statement sets the rate at which simulation time progresses // with respect to real time. "time 0.5" will cause the simulation to // run at half speed, "time 1.0" will cause it to run at real time, // while "time 4.0" will run at 4 times normal speed. Be careful // about too high of a value though because the simulation will // lose fidelity. In fact, for slow computers, values less than 1.0 // may be necessary. Here, we run faster than real time: time 1.0 // go 2x real time //====== // TIMEOUT //====== // // timeout time // // The timeout statement indicates when the simulation will terminate in // milliseconds. The program automatically terminates when this time // is reached. If no timeout statement is given, the default is no // termination. // // timeout 10000 // ten seconds //====== // MAX TIME STEP //====== // // maxtimestep milliseconds // // maxtimestep statements set the maximum time (in milliseconds) that can // transpire between discrete simulation steps. This will keep the simulation // from getting jumpy on slow machines, or when/if your process gets // swapped out. maxtimestep 50 // 1/10th of a second //====== // BACKGROUND COLOR //====== // // background color // // A background statement sets the background color for the simulation. // The color must be given in hex format as "xRRGGBB" where RR indicates // the red component (00 for none, FF for full), GG is the green component, // and BB is the blue. For soccer, we use dark green. background x009000 //====== // OBJECTS //====== // // object objecttype x y theta forecolor backcolor visionclass // // Object statements cause a simulated object to be instantiated // in the simulation. Be sure to include the full class name for the // object. The x y and theta parameters set the initial position of // object in the field. Forecolor and backcolor are the foreground // and background colors of the object as drawn. The visionclass // parameter is used to put each kind of object into it's own perceptual // class. That way when the simulated sensors of robots look for things // they can be sorted by this identifier. // // SocFieldSmallSim is a special object that draws the field. It // has no physical interactions with the robots or the ball. It // is instantiated first so it will be drawn first and not // on top of the robots or the ball. object EDU.gatech.cc.is.simulation.SocFieldSmallSim 0 0 0 0 x009000 x000000 0 // To simulate the corner panels, we use invisible 1 meter diameter // obstacles whose centers are outside the playing field object EDU.gatech.cc.is.simulation.ObstacleInvisibleSim 2.047 1.4396 0 1.0 x000000 x000000 0 object EDU.gatech.cc.is.simulation.ObstacleInvisibleSim -2.047 1.4396 0 1.0 x000000 x000000 0 object EDU.gatech.cc.is.simulation.ObstacleInvisibleSim 2.047 -1.4396 0 1.0 x000000 x000000 0 object EDU.gatech.cc.is.simulation.ObstacleInvisibleSim -2.047 -1.4396 0 1.0 x000000 x000000 0 // The ball object EDU.gatech.cc.is.simulation.GolfBallNoiseSim 0 0 0 0.02 xF0B000 x000000 3 //====== // ROBOTS //====== // // robot robottype controlsystem x y theta forecolor backcolor // visionclass // // Robot statements cause a robot with a control system to be instantiated // in the simulation. Be sure to include the full class name for the // abstract robot type and your control system. The y and theta // parameters are actually ignored for soccer robots because they // have pre-assigned initial locations. The x parameter indicates // whether the robot is on the east (positive) or west (negative). // You can used different colors to tell your team or individual // robots apart from one another. The robots are assigned their player // numbers according to the order in which they are listed here. //======WEST TEAM====== robot EDU.gatech.cc.is.abstractrobot.SocSmallSim equips.javajess -1.2 0 0 xEAEA00 xFFFFFF 2 robot EDU.gatech.cc.is.abstractrobot.SocSmallSim equips.javajess -.5 0 0 xEAEA00 xFFFFFF 2 //======EAST TEAM====== robot EDU.gatech.cc.is.abstractrobot.SocSmallSim JavaSoccer.teams.SchemaDemo 1.2 0 0 xFF0000 x0000FF 1 robot EDU.gatech.cc.is.abstractrobot.SocSmallSim JavaSoccer.teams.SchemaDemo .5 0 0 xFF0000 x0000FF 1