diff TrainingScoreManager.h @ 22:8124f46eda65

pretty much working. ugly though.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Thu, 23 Oct 2014 18:15:46 +0100
parents
children e7af34b1af83
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TrainingScoreManager.h	Thu Oct 23 18:15:46 2014 +0100
@@ -0,0 +1,136 @@
+//
+//  TrainingScoreManager.h
+//  riftathon
+//
+//  Created by Robert Tubb on 23/10/2014.
+//
+//
+
+#ifndef __riftathon__TrainingScoreManager__
+#define __riftathon__TrainingScoreManager__
+
+#include <iostream>
+#include "ofMain.h"
+#include "SequenceController.h"
+#include "algorithms.h"
+#include "globalVariables.h"
+//-------------------------------------------------------------
+
+struct TrainingTestResult{
+    float realDistanceToTarget;
+    int targetBandHit; // eg bullseye = 0 edge = 7
+    float timeAllowed;
+    int score;
+    ofColor colorBand;
+    string displayText;
+};
+
+class TrainingScoreManager{
+    
+    // equiv of score bit of testController
+public:
+    
+    TrainingTestResult getScoreForAnswer(vector<int> targetParams, vector<int> answer, int timeAllowed) const {
+        TrainingTestResult result;
+        stringstream msg;
+        int score = 0;
+        // work out euc distance from actual point
+        //for_each(answer.begin(),answer.end(),printThing<int>());
+        //for_each(targetParams.begin(),targetParams.end(),printThing<int>());
+        float dist = euclideanDistance(targetParams, answer);
+        auto dimComp = sqrt(6.0);
+        int band = -1;
+        if (dist < TARGET_SCORE_CC_BAND*dimComp){
+            score = 50;
+            band = 1;
+            
+            msg << "DOUBLE BULLSEYE!" << endl;
+            
+            
+        }else if (dist < TARGET_SCORE_CC_BAND*2*dimComp){
+            
+            score = 25;
+            band = 2;
+            
+            msg << "SINGLE BULLSEYE!" << endl;
+            
+        }else if (dist < TARGET_SCORE_CC_BAND*3*dimComp){
+            
+            score = 15;
+            band = 3;
+            msg << "CLOSE..." << endl;
+            
+        }else if (dist < TARGET_SCORE_CC_BAND*4*dimComp){
+            score = 5;
+            band = 4;
+            msg << "OK...ISH" << endl;
+            
+        }else if (dist < TARGET_SCORE_CC_BAND*6*dimComp){ // 30
+            score = 2;
+            band = 5;
+            msg << "MEDIOCRE" << endl;
+            
+        }else if (dist < TARGET_SCORE_CC_BAND*9*dimComp){ // 45
+            score = 1;
+            band = 6;
+            msg << "POOR..." << endl;
+            
+        }else{
+            score = 0;
+            band = 7;
+            msg << "MISSED COMPLETELY!" << endl;
+            
+            
+        }
+        msg << "Distance from target: " << dist << endl;
+        msg << "Basic Score: " << score << endl;
+        msg << "-----" << endl;
+        msg << "Time allowed: " << timeAllowed/1000.0 << endl;
+
+        msg << "-----" << endl;
+
+        result.realDistanceToTarget = dist;
+        result.targetBandHit = band; // eg bullseye = 0 edge = 7
+        result.timeAllowed = timeAllowed;
+        result.score = score;
+        result.displayText = msg.str();
+        
+        ofColor c;
+        if(result.targetBandHit == 1){
+            // yellow red blue
+            c = ofColor(255,255,0,255);
+        }else if(result.targetBandHit == 2){
+            c = ofColor(255,0,0,255);
+        }else if(result.targetBandHit == 3){
+            c = ofColor(45,45,255,255);
+        }else if(result.targetBandHit == 4){
+            c = ofColor(0,255,0,255);
+        }else{
+            c = ofColor(150,235,200,255);
+        }
+        result.colorBand = c;
+
+        
+        return result;
+    }
+private:
+    
+    float euclideanDistance(vector<int> v1, vector<int> v2) const{
+        if (v1.size() != v2.size()){
+            cout << "ERROR ERROR: vectors must be same length for Mr Euclid";
+            return 0.;
+        }
+        vector<float> diff;
+        
+        std::transform(v1.begin(), v1.end(), v2.begin(), v1.begin(), difference<float>());
+        // sqr diff
+        
+        std::transform(v1.begin(), v1.end(), v1.begin(),squared<float>());
+        float ans = std::accumulate(v1.begin(),v1.end(),0.0);
+        
+        return sqrt(ans);
+        
+    };
+    
+};
+#endif /* defined(__riftathon__TrainingScoreManager__) */