From 734388f090cb6a980a3306d52f1560a3dde928cf Mon Sep 17 00:00:00 2001 From: "rgudwin@gmail.com" Date: Mon, 17 Jun 2019 17:56:10 -0300 Subject: [PATCH] Changes to avoid the deprecated method updateI Changes from MemoryObject to Memory in many points to make easier the introduction of MemoryContainers --- .../java/codelets/behaviors/EatClosestApple.java | 15 ++++++++------- src/main/java/codelets/behaviors/Forage.java | 7 ++++--- .../java/codelets/behaviors/GoToClosestApple.java | 9 +++++---- .../java/codelets/motor/HandsActionCodelet.java | 3 ++- .../java/codelets/motor/LegsActionCodelet.java | 3 ++- .../java/codelets/perception/AppleDetector.java | 5 +++-- .../codelets/perception/ClosestAppleDetector.java | 7 ++++--- src/main/java/codelets/sensors/InnerSense.java | 3 ++- src/main/java/codelets/sensors/Vision.java | 3 ++- src/main/java/support/MindView.java | 8 ++++---- 10 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/main/java/codelets/behaviors/EatClosestApple.java b/src/main/java/codelets/behaviors/EatClosestApple.java index f98417d..e8a6a8f 100644 --- a/src/main/java/codelets/behaviors/EatClosestApple.java +++ b/src/main/java/codelets/behaviors/EatClosestApple.java @@ -26,6 +26,7 @@ import org.json.JSONObject; import br.unicamp.cst.core.entities.Codelet; +import br.unicamp.cst.core.entities.Memory; import br.unicamp.cst.core.entities.MemoryObject; import memory.CreatureInnerSense; import java.util.List; @@ -34,11 +35,11 @@ public class EatClosestApple extends Codelet { - private MemoryObject closestAppleMO; - private MemoryObject innerSenseMO; - private MemoryObject knownMO; + private Memory closestAppleMO; + private Memory innerSenseMO; + private Memory knownMO; private int reachDistance; - private MemoryObject handsMO; + private Memory handsMO; Thing closestApple; CreatureInnerSense cis; List known; @@ -95,10 +96,10 @@ public void proc() { if(distance known; - private MemoryObject legsMO; + private Memory legsMO; /** @@ -53,7 +54,7 @@ public void proc() { JSONObject message=new JSONObject(); try { message.put("ACTION", "FORAGE"); - legsMO.updateI(message.toString()); + legsMO.setI(message.toString()); } catch (JSONException e) { // TODO Auto-generated catch block diff --git a/src/main/java/codelets/behaviors/GoToClosestApple.java b/src/main/java/codelets/behaviors/GoToClosestApple.java index cad6e03..f7edc3d 100644 --- a/src/main/java/codelets/behaviors/GoToClosestApple.java +++ b/src/main/java/codelets/behaviors/GoToClosestApple.java @@ -25,15 +25,16 @@ import org.json.JSONException; import org.json.JSONObject; import br.unicamp.cst.core.entities.Codelet; +import br.unicamp.cst.core.entities.Memory; import br.unicamp.cst.core.entities.MemoryObject; import memory.CreatureInnerSense; import ws3dproxy.model.Thing; public class GoToClosestApple extends Codelet { - private MemoryObject closestAppleMO; - private MemoryObject selfInfoMO; - private MemoryObject legsMO; + private Memory closestAppleMO; + private Memory selfInfoMO; + private Memory legsMO; private int creatureBasicSpeed; private double reachDistance; @@ -94,7 +95,7 @@ public void proc() { message.put("Y", (int)appleY); message.put("SPEED", 0.0); } - legsMO.updateI(message.toString()); + legsMO.setI(message.toString()); } catch (JSONException e) { e.printStackTrace(); } diff --git a/src/main/java/codelets/motor/HandsActionCodelet.java b/src/main/java/codelets/motor/HandsActionCodelet.java index 18f9d7d..2a3d9cc 100644 --- a/src/main/java/codelets/motor/HandsActionCodelet.java +++ b/src/main/java/codelets/motor/HandsActionCodelet.java @@ -24,6 +24,7 @@ import org.json.JSONObject; import br.unicamp.cst.core.entities.Codelet; +import br.unicamp.cst.core.entities.Memory; import br.unicamp.cst.core.entities.MemoryObject; import java.util.Random; import java.util.logging.Logger; @@ -39,7 +40,7 @@ public class HandsActionCodelet extends Codelet{ - private MemoryObject handsMO; + private Memory handsMO; private String previousHandsAction=""; private Creature c; private Random r = new Random(); diff --git a/src/main/java/codelets/motor/LegsActionCodelet.java b/src/main/java/codelets/motor/LegsActionCodelet.java index c63eccd..84fc835 100644 --- a/src/main/java/codelets/motor/LegsActionCodelet.java +++ b/src/main/java/codelets/motor/LegsActionCodelet.java @@ -23,6 +23,7 @@ import org.json.JSONObject; import br.unicamp.cst.core.entities.Codelet; +import br.unicamp.cst.core.entities.Memory; import br.unicamp.cst.core.entities.MemoryObject; import java.util.Random; import java.util.logging.Logger; @@ -38,7 +39,7 @@ public class LegsActionCodelet extends Codelet{ - private MemoryObject legsActionMO; + private Memory legsActionMO; private double previousTargetx=0; private double previousTargety=0; private String previousLegsAction=""; diff --git a/src/main/java/codelets/perception/AppleDetector.java b/src/main/java/codelets/perception/AppleDetector.java index caedfed..69350df 100644 --- a/src/main/java/codelets/perception/AppleDetector.java +++ b/src/main/java/codelets/perception/AppleDetector.java @@ -20,6 +20,7 @@ package codelets.perception; import br.unicamp.cst.core.entities.Codelet; +import br.unicamp.cst.core.entities.Memory; import br.unicamp.cst.core.entities.MemoryObject; import java.util.Collections; import java.util.List; @@ -36,8 +37,8 @@ */ public class AppleDetector extends Codelet { - private MemoryObject visionMO; - private MemoryObject knownApplesMO; + private Memory visionMO; + private Memory knownApplesMO; public AppleDetector(){ diff --git a/src/main/java/codelets/perception/ClosestAppleDetector.java b/src/main/java/codelets/perception/ClosestAppleDetector.java index 6eada8b..5f30005 100644 --- a/src/main/java/codelets/perception/ClosestAppleDetector.java +++ b/src/main/java/codelets/perception/ClosestAppleDetector.java @@ -22,6 +22,7 @@ import br.unicamp.cst.core.entities.Codelet; +import br.unicamp.cst.core.entities.Memory; import br.unicamp.cst.core.entities.MemoryObject; import java.util.Collections; import memory.CreatureInnerSense; @@ -35,9 +36,9 @@ */ public class ClosestAppleDetector extends Codelet { - private MemoryObject knownMO; - private MemoryObject closestAppleMO; - private MemoryObject innerSenseMO; + private Memory knownMO; + private Memory closestAppleMO; + private Memory innerSenseMO; private List known; diff --git a/src/main/java/codelets/sensors/InnerSense.java b/src/main/java/codelets/sensors/InnerSense.java index aa919a1..633e23d 100644 --- a/src/main/java/codelets/sensors/InnerSense.java +++ b/src/main/java/codelets/sensors/InnerSense.java @@ -20,6 +20,7 @@ package codelets.sensors; import br.unicamp.cst.core.entities.Codelet; +import br.unicamp.cst.core.entities.Memory; import br.unicamp.cst.core.entities.MemoryObject; import memory.CreatureInnerSense; import ws3dproxy.model.Creature; @@ -33,7 +34,7 @@ public class InnerSense extends Codelet { - private MemoryObject innerSenseMO; + private Memory innerSenseMO; private Creature c; private CreatureInnerSense cis; diff --git a/src/main/java/codelets/sensors/Vision.java b/src/main/java/codelets/sensors/Vision.java index de03397..e74bd8c 100644 --- a/src/main/java/codelets/sensors/Vision.java +++ b/src/main/java/codelets/sensors/Vision.java @@ -20,6 +20,7 @@ package codelets.sensors; import br.unicamp.cst.core.entities.Codelet; +import br.unicamp.cst.core.entities.Memory; import br.unicamp.cst.core.entities.MemoryObject; import java.util.List; import ws3dproxy.model.Creature; @@ -35,7 +36,7 @@ //TODO How about implementing getvs 0 in Client? public class Vision extends Codelet{ - private MemoryObject visionMO; + private Memory visionMO; private Creature c; diff --git a/src/main/java/support/MindView.java b/src/main/java/support/MindView.java index 78e70b7..0e4e6fc 100644 --- a/src/main/java/support/MindView.java +++ b/src/main/java/support/MindView.java @@ -19,7 +19,7 @@ package support; -import br.unicamp.cst.core.entities.MemoryObject; +import br.unicamp.cst.core.entities.Memory; import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -53,7 +53,7 @@ public void setEnabled(boolean value) { public class MindView extends javax.swing.JFrame { Timer t; - List mol = new ArrayList<>(); + List mol = new ArrayList<>(); int j=0; Random r = new Random(); /** @@ -64,7 +64,7 @@ public MindView(String name) { setTitle(name); } - public void addMO(MemoryObject moi) { + public void addMO(Memory moi) { mol.add(moi); } @@ -77,7 +77,7 @@ public void StartTimer() { public void tick() { String alltext = ""; if (mol.size() != 0) - for (MemoryObject mo : mol) { + for (Memory mo : mol) { if (mo.getI() != null) { //Class cl = mo.getT(); //Object k = cl.cast(mo.getI());