Skip to content

Commit

Permalink
Changes to avoid the deprecated method updateI
Browse files Browse the repository at this point in the history
Changes from MemoryObject to Memory in many points to make easier the introduction of MemoryContainers
  • Loading branch information
[email protected] committed Jun 17, 2019
1 parent 6726961 commit 734388f
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 27 deletions.
15 changes: 8 additions & 7 deletions src/main/java/codelets/behaviors/EatClosestApple.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Thing> known;
Expand Down Expand Up @@ -95,10 +96,10 @@ public void proc() {
if(distance<reachDistance){ //eat it
message.put("OBJECT", appleName);
message.put("ACTION", "EATIT");
handsMO.updateI(message.toString());
handsMO.setI(message.toString());
DestroyClosestApple();
}else{
handsMO.updateI(""); //nothing
handsMO.setI(""); //nothing
}

// System.out.println(message);
Expand All @@ -107,7 +108,7 @@ public void proc() {
e.printStackTrace();
}
}else{
handsMO.updateI(""); //nothing
handsMO.setI(""); //nothing
}
//System.out.println("Before: "+known.size()+ " "+known);

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/codelets/behaviors/Forage.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package codelets.behaviors;

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 org.json.JSONException;
Expand All @@ -35,9 +36,9 @@

public class Forage extends Codelet {

private MemoryObject knownMO;
private Memory knownMO;
private List<Thing> known;
private MemoryObject legsMO;
private Memory legsMO;


/**
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/codelets/behaviors/GoToClosestApple.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/codelets/motor/HandsActionCodelet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/codelets/motor/LegsActionCodelet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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="";
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/codelets/perception/AppleDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,8 +37,8 @@
*/
public class AppleDetector extends Codelet {

private MemoryObject visionMO;
private MemoryObject knownApplesMO;
private Memory visionMO;
private Memory knownApplesMO;

public AppleDetector(){

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/codelets/perception/ClosestAppleDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Thing> known;

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/codelets/sensors/InnerSense.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,7 +34,7 @@

public class InnerSense extends Codelet {

private MemoryObject innerSenseMO;
private Memory innerSenseMO;
private Creature c;
private CreatureInnerSense cis;

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/codelets/sensors/Vision.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;


Expand Down
8 changes: 4 additions & 4 deletions src/main/java/support/MindView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,7 +53,7 @@ public void setEnabled(boolean value) {
public class MindView extends javax.swing.JFrame {

Timer t;
List<MemoryObject> mol = new ArrayList<>();
List<Memory> mol = new ArrayList<>();
int j=0;
Random r = new Random();
/**
Expand All @@ -64,7 +64,7 @@ public MindView(String name) {
setTitle(name);
}

public void addMO(MemoryObject moi) {
public void addMO(Memory moi) {
mol.add(moi);
}

Expand All @@ -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());
Expand Down

0 comments on commit 734388f

Please sign in to comment.