-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBogValidator.cpp
More file actions
147 lines (127 loc) · 2.96 KB
/
BogValidator.cpp
File metadata and controls
147 lines (127 loc) · 2.96 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <iostream>
#include <string>
#include <cstdlib>
#include "BogValidator.h"
using namespace std;
//Constructor
BogValidator::BogValidator(){
inputlist = NULL;
}
//Destructor
//Clean up behind yourself
BogValidator::~BogValidator(){
while(inputlist!=NULL){
wordNode*i = inputlist;
inputlist=inputlist->next;
delete i;
}
}
//wordNode Constructor
//Sets empty word, false status, and NULL pointer
wordNode::wordNode(){
word = "";
status = false;
next=NULL;
}
//readDict()
//PRECONDITION: User has list of words to provide solver
//POSTCONDITION: solver has read those contents up til '.'
bool BogValidator::readDict(){
return solver.readDict();
}
//readBoard()
//PRECONDITION: User has Board for solver formatted to assignment
//POSTCONDITION: solver has read board of specificed dimensions
bool BogValidator::readBoard(){
return solver.readBoard();
}
//checkWords()
//PRECONDITION: Dictionary and Board have been read
//POSTCONDITION: The user input 'answers' have been evaluated
// and printed back out.
void BogValidator::checkWords(){
solver.solve();
// solver.listWords();
string y;
cin>>y;
inputlist = new wordNode;
inputlist->word = y;
wordNode* i = inputlist;
cin >> y;
while (!cin.eof( )){
i->next = new wordNode;
i = i->next;
i->word = y;
cin >> y;
}
i = inputlist;
while(i !=NULL ){
i->status = isValid( i->word );
i = i->next;
}
print();
}
//isValid
//PRECONDITION: Function is reading in user answer. solver has solved Board
//POSTCONDITION: bool is returned denoting OK or NO for each user word
bool BogValidator::isValid(string s){
bool result = false;
int wordlength = s.length();
string compare;
int i,j,m;
BogWordList* answerlist = solver.getWords(wordlength);
int numberwords = answerlist->numWords;
for (i=0; i<numberwords; i++){
compare="";
m = wordlength;
for (j=0;j<m;j++){
compare += answerlist->words[i].letts[j].c;
if(answerlist->words[i].letts[j].c=='Q'){
compare+='U';
m--;
}
}
if ((compare == s )&&(!previousCorrect(s))){
result = true;
return result;
}
}
return result;
}
//print
//PRECONDITION: Board has been solved and compared to user answers.
// each answer is OK or NO
//POSTCONDITION: Results are coutted in proper format
void BogValidator::print(){
wordNode* i = inputlist;
int y=0;
while(i!=NULL){
i = i->next;
y++;
}
i = inputlist;
while(i!=NULL){
if(i->status == true )
cout<<"OK ";
else
cout<<"NO ";
cout<<i->word<<endl;
i = i->next;
}
}
//previousCorrect
//PRECONDITION: Answer has been found in Boggle Board. Was it a prev answer?
//POSTCONDITION: Bool returned whether it is a previous answer
bool BogValidator::previousCorrect(string s){
bool result=false;
wordNode*i=inputlist;
while(i!=NULL){
if (i->word==s){
if (i->status==true){
result=true;
}
}
i=i->next;
}
return result;
}