From a9ac6157bb7abe992c18354dae89bf65e4d6a861 Mon Sep 17 00:00:00 2001 From: PtrMan <robertw89@googlemail.com> Date: Mon, 11 Mar 2019 18:17:21 +0100 Subject: [PATCH] Update: Pong: fixed counting of hits/misses --- .../java/org/opennars/lab/microworld/Pong.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/opennars/lab/microworld/Pong.java b/src/main/java/org/opennars/lab/microworld/Pong.java index 6f0360477..b65e0fbe5 100755 --- a/src/main/java/org/opennars/lab/microworld/Pong.java +++ b/src/main/java/org/opennars/lab/microworld/Pong.java @@ -259,8 +259,6 @@ public class Pong extends Frame { if(Math.abs(agent.x - ball.x) < middle_distance) { //touching the ball? if(Math.abs(agent.x - ball.x) < middle_distance && ball.y < 120) { //same here - ballHits++; - String s = "<{SELF} --> [good]>. :|:"; if(!s.equals(this.LastInput)) { if (verbose) { @@ -278,8 +276,6 @@ public class Pong extends Frame { this.LastInput = s; } } else { - ballMisses++; - if(agent.x < ball.x) { String s = "<{right} --> [on]>. :|:"; if(!s.equals(this.LastInput)) { @@ -522,6 +518,18 @@ public class Pong extends Frame { { oi.y = 0; oi.VY = -oi.VY; + + // ball changed direction on top of the bat - figure out if scored or not + float middle_distance = 40.0f; //approximately the drawing size of paddle plus ball radius + + float diffAbs = Math.abs(agent.x - ball.x); + + if(diffAbs < middle_distance) { + ballHits++; + } + else { + ballMisses++; + } } oi.x += oi.VX; oi.y += oi.VY; @@ -550,7 +558,7 @@ public class Pong extends Frame { } void hrend_DrawBegin() { - label1.text="opti index:"+((float)goods)/((float)bads)+ "FPS:"+frameRate; + label1.text="hits=" + ballHits + " misses=" + ballMisses + " opti index="+((float)ballHits)/((float)ballMisses)+ " FPS="+frameRate; fill(138,138,128); pushMatrix(); if(hamlib.Mode==hamlib.Hamlib3DMode) -- GitLab