Skip to content

Commit

Permalink
update: less chaos, pong by default
Browse files Browse the repository at this point in the history
  • Loading branch information
PtrMan committed Apr 14, 2020
1 parent cfbe084 commit dec2640
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
24 changes: 18 additions & 6 deletions src/main/java/ptrman/exp/NarConSimpleWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@ public class NarConSimpleWorld extends PApplet {
// scene to choose
// "pong" pong
// "shootemup" for alien invasion thingy
public static String scene = "shootemup";
public static String scene = "pong";//"shootemup";


// SHOOTEMUP

// TODO< alien >

public static List<Proj> projectiles = new ArrayList<>();

static class Proj {
Expand Down Expand Up @@ -98,14 +96,15 @@ public Proj(float x, float y, float velX, float velY) {
public static boolean useRngAgent = false; // use random action agent? used for testing

public static boolean verboseAgent = true;
public static boolean verboseDscnExp = true;

// helper to send string to ONA
public static void sendText(String str, boolean silent) {
if (useRngAgent) {
return; // don't send anything to NARS if we use dummy agent
}

if (!silent) {
if (false && !silent) {
System.out.println(""+str);
}

Expand All @@ -123,7 +122,7 @@ public static void sendText(String str, boolean silent) {

// helper to let NAR perform inference steps
public void narInferenceSteps(int steps) {
sendText(""+steps, true);
sendText(""+steps, false);

if (!useRngAgent) {
try {
Expand Down Expand Up @@ -189,6 +188,10 @@ public void narInferenceSteps(int steps) {
if(verboseAgent) System.out.println(iLine);
}

if (verboseDscnExp && iLine.contains("decision expectation ")) {
System.out.println(iLine);
}

if(iLine.contains("executed with args")) {
int here = 5;
}
Expand Down Expand Up @@ -447,6 +450,7 @@ else if(scene.equals("shootemup")) {

if (dist < 10) { // did projectile hit alien?
// hit bat -> good NAR
System.out.println("hit");
sendText("good_nar. :|:", false);
hits++;

Expand All @@ -456,18 +460,25 @@ else if(scene.equals("shootemup")) {
// respawn alien to make it more complicated
Random rng = new Random();
ballX = rng.nextFloat()*110.0f;
if (rng.nextFloat() < 0.5) {
ballVelX = (float)Math.abs(ballVelX);
}
else {
ballVelX = -(float)Math.abs(ballVelX);
}
}
}


/*
//change direction randomly to make it more complicated
Random rng = new Random();
if (rng.nextFloat() < 0.5) {
ballVelX = (float)Math.abs(ballVelX);
}
else {
ballVelX = -(float)Math.abs(ballVelX);
}
}*/

// alien reflects on sides of screen
if (ballX < 10) {
Expand All @@ -486,6 +497,7 @@ else if(scene.equals("shootemup")) {
for(int idx=0;idx<projectiles.size();idx++) {
if (projectiles.get(idx).y < 0) { // is projectile outside of screen
misses++;
System.out.println("miss");
projectiles.remove(idx);
idx--;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,10 @@ else if(i.getValue().size() < classificationCandidatesWithLowestMemberCount.size
// scalable way// String n = "< ( {"+(relY)+"} * < ( {"+iClassfcnWithLowestCount.category+"} * {"+iClasfcnOther.category+"} ) --> h > ) --> relY >. :|:";

// not scalable way, will xplode for more complicated scenes
String n = "< ( {"+(relY)+"} * {"+iClassfcnWithLowestCount.category+"_"+iClasfcnOther.category+"} ) --> relY >. :|:";
String n = "< ( {"+(relY)+"} * {"+iClassfcnWithLowestCount.category+"D"+iClasfcnOther.category+"} ) --> relY >. :|:";
relByNarsese.put(n, true); // store in set

n = "< ( {"+(relX)+"} * {"+iClassfcnWithLowestCount.category+"_"+iClasfcnOther.category+"} ) --> relX >. :|:";
n = "< ( {"+(relX)+"} * {"+iClassfcnWithLowestCount.category+"D"+iClasfcnOther.category+"} ) --> relX >. :|:";
relByNarsese.put(n, true); // store in set
}
}
Expand Down

0 comments on commit dec2640

Please sign in to comment.