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