-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathgagrader.cpp
More file actions
63 lines (52 loc) · 1.52 KB
/
gagrader.cpp
File metadata and controls
63 lines (52 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "gagrader.h"
#include "goodasm.h"
#include "galanguage.h"
#include "gamnemonic.h"
#include "gainstruction.h"
GAGrader::GAGrader() {}
GAGraderGrade::GAGraderGrade(GAGrader *grader, GALanguage *lang, int64_t score){
this->grader=grader;
this->lang=lang;
this->score=score;
}
// Which lang the most likely?
QString GAGrader::mostValid(GoodASM *goodasm){
uint64_t bestscore=0;
QString bestlang="";
foreach(auto l, goodasm->languages){
goodasm->setLanguage(l->name);
uint64_t score=isValid(goodasm);
if(score>bestscore){ // Update the best score.
bestscore=score;
bestlang=l->name;
}
}
return bestlang;
}
// Score the result.
GAGraderGrade GAGrader::score(GoodASM *goodasm){
bool valid=isValid(goodasm);
int64_t score=valid?100:0;
GAGraderGrade grade(this, goodasm->lang, score);
grade.valid=valid;
return grade;
}
//Static sorting function to put the highest scores first.
static bool above(GAGraderGrade top, GAGraderGrade bottom){
return (top.score > bottom.score);
}
//Score all languages.
QVector<GAGraderGrade> GAGrader::scores(GoodASM *goodasm){
QVector<GAGraderGrade> v;
//Score each compatible language.
foreach(auto l, goodasm->languages){
if(isCompatible(l)){
goodasm->setLanguage(l->name);
GAGraderGrade grade=score(goodasm);
if(grade.score>0) v.append(grade);
}
}
//Sort the scores.
std::sort(v.begin(), v.end(), above);
return v;
}