rt300@22
|
1 //
|
rt300@22
|
2 // TrainingScoreManager.h
|
rt300@22
|
3 // riftathon
|
rt300@22
|
4 //
|
rt300@22
|
5 // Created by Robert Tubb on 23/10/2014.
|
rt300@22
|
6 //
|
rt300@22
|
7 //
|
rt300@22
|
8
|
rt300@22
|
9 #ifndef __riftathon__TrainingScoreManager__
|
rt300@22
|
10 #define __riftathon__TrainingScoreManager__
|
rt300@22
|
11
|
rt300@22
|
12 #include <iostream>
|
rt300@22
|
13 #include "ofMain.h"
|
rt300@22
|
14 #include "SequenceController.h"
|
rt300@22
|
15 #include "algorithms.h"
|
rt300@22
|
16 #include "globalVariables.h"
|
rt300@22
|
17 //-------------------------------------------------------------
|
rt300@22
|
18
|
rt300@22
|
19 struct TrainingTestResult{
|
rt300@22
|
20 float realDistanceToTarget;
|
rt300@22
|
21 int targetBandHit; // eg bullseye = 0 edge = 7
|
rt300@22
|
22 float timeAllowed;
|
rt300@22
|
23 int score;
|
rt300@22
|
24 ofColor colorBand;
|
rt300@22
|
25 string displayText;
|
rt300@22
|
26 };
|
rt300@22
|
27
|
rt300@22
|
28 class TrainingScoreManager{
|
rt300@22
|
29
|
rt300@22
|
30 // equiv of score bit of testController
|
rt300@22
|
31 public:
|
rt300@22
|
32
|
rt300@22
|
33 TrainingTestResult getScoreForAnswer(vector<int> targetParams, vector<int> answer, int timeAllowed) const {
|
rt300@22
|
34 TrainingTestResult result;
|
rt300@22
|
35 stringstream msg;
|
rt300@22
|
36 int score = 0;
|
rt300@22
|
37 // work out euc distance from actual point
|
rt300@22
|
38 //for_each(answer.begin(),answer.end(),printThing<int>());
|
rt300@22
|
39 //for_each(targetParams.begin(),targetParams.end(),printThing<int>());
|
rt300@22
|
40 float dist = euclideanDistance(targetParams, answer);
|
rt300@22
|
41 auto dimComp = sqrt(6.0);
|
rt300@22
|
42 int band = -1;
|
rt300@22
|
43 if (dist < TARGET_SCORE_CC_BAND*dimComp){
|
rt300@22
|
44 score = 50;
|
rt300@22
|
45 band = 1;
|
rt300@22
|
46
|
rt300@22
|
47 msg << "DOUBLE BULLSEYE!" << endl;
|
rt300@22
|
48
|
rt300@22
|
49
|
rt300@22
|
50 }else if (dist < TARGET_SCORE_CC_BAND*2*dimComp){
|
rt300@22
|
51
|
rt300@22
|
52 score = 25;
|
rt300@22
|
53 band = 2;
|
rt300@22
|
54
|
rt300@22
|
55 msg << "SINGLE BULLSEYE!" << endl;
|
rt300@22
|
56
|
rt300@22
|
57 }else if (dist < TARGET_SCORE_CC_BAND*3*dimComp){
|
rt300@22
|
58
|
rt300@22
|
59 score = 15;
|
rt300@22
|
60 band = 3;
|
rt300@22
|
61 msg << "CLOSE..." << endl;
|
rt300@22
|
62
|
rt300@22
|
63 }else if (dist < TARGET_SCORE_CC_BAND*4*dimComp){
|
rt300@22
|
64 score = 5;
|
rt300@22
|
65 band = 4;
|
rt300@22
|
66 msg << "OK...ISH" << endl;
|
rt300@22
|
67
|
rt300@22
|
68 }else if (dist < TARGET_SCORE_CC_BAND*6*dimComp){ // 30
|
rt300@22
|
69 score = 2;
|
rt300@22
|
70 band = 5;
|
rt300@22
|
71 msg << "MEDIOCRE" << endl;
|
rt300@22
|
72
|
rt300@22
|
73 }else if (dist < TARGET_SCORE_CC_BAND*9*dimComp){ // 45
|
rt300@22
|
74 score = 1;
|
rt300@22
|
75 band = 6;
|
rt300@22
|
76 msg << "POOR..." << endl;
|
rt300@22
|
77
|
rt300@22
|
78 }else{
|
rt300@22
|
79 score = 0;
|
rt300@22
|
80 band = 7;
|
rt300@22
|
81 msg << "MISSED COMPLETELY!" << endl;
|
rt300@22
|
82
|
rt300@22
|
83
|
rt300@22
|
84 }
|
rt300@22
|
85 msg << "Distance from target: " << dist << endl;
|
rt300@22
|
86 msg << "Basic Score: " << score << endl;
|
rt300@22
|
87 msg << "-----" << endl;
|
rt300@22
|
88 msg << "Time allowed: " << timeAllowed/1000.0 << endl;
|
rt300@22
|
89
|
rt300@22
|
90 msg << "-----" << endl;
|
rt300@22
|
91
|
rt300@22
|
92 result.realDistanceToTarget = dist;
|
rt300@22
|
93 result.targetBandHit = band; // eg bullseye = 0 edge = 7
|
rt300@22
|
94 result.timeAllowed = timeAllowed;
|
rt300@22
|
95 result.score = score;
|
rt300@22
|
96 result.displayText = msg.str();
|
rt300@22
|
97
|
rt300@22
|
98 ofColor c;
|
rt300@22
|
99 if(result.targetBandHit == 1){
|
rt300@22
|
100 // yellow red blue
|
rt300@22
|
101 c = ofColor(255,255,0,255);
|
rt300@22
|
102 }else if(result.targetBandHit == 2){
|
rt300@22
|
103 c = ofColor(255,0,0,255);
|
rt300@22
|
104 }else if(result.targetBandHit == 3){
|
rt300@22
|
105 c = ofColor(45,45,255,255);
|
rt300@22
|
106 }else if(result.targetBandHit == 4){
|
rt300@22
|
107 c = ofColor(0,255,0,255);
|
rt300@22
|
108 }else{
|
rt300@22
|
109 c = ofColor(150,235,200,255);
|
rt300@22
|
110 }
|
rt300@22
|
111 result.colorBand = c;
|
rt300@22
|
112
|
rt300@22
|
113
|
rt300@22
|
114 return result;
|
rt300@22
|
115 }
|
rt300@22
|
116 private:
|
rt300@22
|
117
|
rt300@22
|
118 float euclideanDistance(vector<int> v1, vector<int> v2) const{
|
rt300@22
|
119 if (v1.size() != v2.size()){
|
rt300@22
|
120 cout << "ERROR ERROR: vectors must be same length for Mr Euclid";
|
rt300@22
|
121 return 0.;
|
rt300@22
|
122 }
|
rt300@22
|
123 vector<float> diff;
|
rt300@22
|
124
|
rt300@22
|
125 std::transform(v1.begin(), v1.end(), v2.begin(), v1.begin(), difference<float>());
|
rt300@22
|
126 // sqr diff
|
rt300@22
|
127
|
rt300@22
|
128 std::transform(v1.begin(), v1.end(), v1.begin(),squared<float>());
|
rt300@22
|
129 float ans = std::accumulate(v1.begin(),v1.end(),0.0);
|
rt300@22
|
130
|
rt300@22
|
131 return sqrt(ans);
|
rt300@22
|
132
|
rt300@22
|
133 };
|
rt300@22
|
134
|
rt300@22
|
135 };
|
rt300@22
|
136 #endif /* defined(__riftathon__TrainingScoreManager__) */
|