| 1 |
#pragma warning(disable:4786) |
|---|
| 2 |
|
|---|
| 3 |
#include <sstream> |
|---|
| 4 |
#include <string> |
|---|
| 5 |
#include <vector> |
|---|
| 6 |
#include <sstream> |
|---|
| 7 |
#include <iostream> |
|---|
| 8 |
|
|---|
| 9 |
using namespace std; |
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
int CheckValidOps(string str, int x, int y); |
|---|
| 14 |
|
|---|
| 15 |
int IsInt(string s); |
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
int CheckValidOps(string str, int x, int y) |
|---|
| 29 |
{ |
|---|
| 30 |
|
|---|
| 31 |
vector<string> attributes(7); |
|---|
| 32 |
vector<int> size(7); |
|---|
| 33 |
attributes[0]="Hunger"; size[0]=100; |
|---|
| 34 |
attributes[1]="Occupation"; size[1]=20; |
|---|
| 35 |
attributes[2]="Drunk"; size[2]=100; |
|---|
| 36 |
attributes[3]="Thirst"; size[3]=10; |
|---|
| 37 |
attributes[4]="Money"; size[4]=10000; |
|---|
| 38 |
attributes[5]="Morality"; size[5]=10; |
|---|
| 39 |
attributes[6]="Fatigue"; size[6]=10; |
|---|
| 40 |
|
|---|
| 41 |
if(x==0) |
|---|
| 42 |
{ |
|---|
| 43 |
if(str=="npc") |
|---|
| 44 |
return 1; |
|---|
| 45 |
else |
|---|
| 46 |
return 0; |
|---|
| 47 |
} |
|---|
| 48 |
int i,num,value_int; |
|---|
| 49 |
int xloc, yloc, groupval_int, liking; |
|---|
| 50 |
string xstr, ystr; |
|---|
| 51 |
char c; |
|---|
| 52 |
string attrib,snum,value, ineq, groupname, groupval; |
|---|
| 53 |
if(str=="") |
|---|
| 54 |
return 0; |
|---|
| 55 |
istringstream iss(str); |
|---|
| 56 |
iss>>attrib; |
|---|
| 57 |
for(i=0; i<7; i++) |
|---|
| 58 |
{ |
|---|
| 59 |
if(attrib==attributes[i]) |
|---|
| 60 |
break; |
|---|
| 61 |
} |
|---|
| 62 |
if(attrib=="rel") |
|---|
| 63 |
{ |
|---|
| 64 |
|
|---|
| 65 |
iss>>snum; |
|---|
| 66 |
if(!IsInt(snum)) |
|---|
| 67 |
return 0; |
|---|
| 68 |
num=atoi(snum.c_str()); |
|---|
| 69 |
for(int k=0; k<num+1; k++) |
|---|
| 70 |
{ |
|---|
| 71 |
iss>>groupname; |
|---|
| 72 |
for(i=0; i<7; i++) |
|---|
| 73 |
{ |
|---|
| 74 |
if(groupname==attributes[i]) |
|---|
| 75 |
break; |
|---|
| 76 |
} |
|---|
| 77 |
if(i==7) |
|---|
| 78 |
return 0; |
|---|
| 79 |
iss>>groupval; |
|---|
| 80 |
if(!IsInt(groupval)) |
|---|
| 81 |
return 0; |
|---|
| 82 |
groupval_int=atoi(groupval.c_str()); |
|---|
| 83 |
if(groupval_int > size[i] || groupval_int < 0) |
|---|
| 84 |
return 0; |
|---|
| 85 |
iss>>groupval; |
|---|
| 86 |
if(!IsInt(groupval)) |
|---|
| 87 |
return 0; |
|---|
| 88 |
liking=atoi(groupval.c_str()); |
|---|
| 89 |
if(liking > 50 || liking < -50) |
|---|
| 90 |
return 0; |
|---|
| 91 |
iss>>c; |
|---|
| 92 |
if(k==num) |
|---|
| 93 |
return 1; |
|---|
| 94 |
else if(c!=',') |
|---|
| 95 |
return 0; |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
} |
|---|
| 99 |
else if(attrib=="loc") |
|---|
| 100 |
{ |
|---|
| 101 |
iss>>snum; |
|---|
| 102 |
if(!IsInt(snum)) |
|---|
| 103 |
{ |
|---|
| 104 |
|
|---|
| 105 |
return 0; |
|---|
| 106 |
} |
|---|
| 107 |
num=atoi(snum.c_str()); |
|---|
| 108 |
|
|---|
| 109 |
for(int k=0; k<num+1; k++) |
|---|
| 110 |
{ |
|---|
| 111 |
|
|---|
| 112 |
iss>>xstr; |
|---|
| 113 |
iss>>ystr; |
|---|
| 114 |
|
|---|
| 115 |
if(!IsInt(xstr) || !IsInt(ystr)) |
|---|
| 116 |
return 0; |
|---|
| 117 |
|
|---|
| 118 |
xloc=atoi(xstr.c_str()); |
|---|
| 119 |
yloc=atoi(ystr.c_str()); |
|---|
| 120 |
if(!(xloc>=0 && yloc>=0 && xloc<=300 && yloc<=300)) |
|---|
| 121 |
return 0; |
|---|
| 122 |
iss>>c; |
|---|
| 123 |
if(k==num) |
|---|
| 124 |
return 1; |
|---|
| 125 |
else if(c!=',') |
|---|
| 126 |
return 0; |
|---|
| 127 |
} |
|---|
| 128 |
return 1; |
|---|
| 129 |
} |
|---|
| 130 |
if(i==7) |
|---|
| 131 |
return 0; |
|---|
| 132 |
iss>>snum; |
|---|
| 133 |
if(!IsInt(snum)) |
|---|
| 134 |
return 0; |
|---|
| 135 |
num=atoi(snum.c_str()); |
|---|
| 136 |
if(num<0) |
|---|
| 137 |
return 0; |
|---|
| 138 |
else |
|---|
| 139 |
{ |
|---|
| 140 |
for(int k=0; k<num+1; k++) |
|---|
| 141 |
{ |
|---|
| 142 |
iss>>ineq; |
|---|
| 143 |
if(ineq=="==" || ineq=="!=" || ineq==">=" || ineq=="<=" || ineq==">" || ineq=="<") |
|---|
| 144 |
{ |
|---|
| 145 |
iss>>value; |
|---|
| 146 |
if(IsInt(value)) |
|---|
| 147 |
{ |
|---|
| 148 |
value_int=atoi(value.c_str()); |
|---|
| 149 |
if(value_int>=0 && value_int<size[i]+y) |
|---|
| 150 |
{ |
|---|
| 151 |
if(k==num) |
|---|
| 152 |
return 1; |
|---|
| 153 |
iss>>c; |
|---|
| 154 |
if(c==',') |
|---|
| 155 |
break; |
|---|
| 156 |
else |
|---|
| 157 |
return 0; |
|---|
| 158 |
} |
|---|
| 159 |
else |
|---|
| 160 |
return 0; |
|---|
| 161 |
} |
|---|
| 162 |
else |
|---|
| 163 |
return 0; |
|---|
| 164 |
} |
|---|
| 165 |
else |
|---|
| 166 |
return 0; |
|---|
| 167 |
} |
|---|
| 168 |
} |
|---|
| 169 |
return 1; |
|---|
| 170 |
} |
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
int IsInt(string s) |
|---|
| 174 |
{ |
|---|
| 175 |
|
|---|
| 176 |
int i=0; |
|---|
| 177 |
if(s.length()==0) |
|---|
| 178 |
return 0; |
|---|
| 179 |
if(s[0]=='-') |
|---|
| 180 |
i++; |
|---|
| 181 |
if(s.length()>5+1) |
|---|
| 182 |
{cout<<"wrong length"<<endl; return 0;} |
|---|
| 183 |
if(s[0+i]>'9' || s[0+i]<'0') |
|---|
| 184 |
{cout<<"first out of bounds"<<endl; return 0;} |
|---|
| 185 |
if(s.length()>1+i && (s[1+i]>'9' || s[1+i]<'0')) |
|---|
| 186 |
{cout<<s[2]<<endl;cout<<"second out of bounds"<<endl; return 0;} |
|---|
| 187 |
if(s.length()>2+i && (s[2+i]>'9' || s[2+i]<'0')) |
|---|
| 188 |
{cout<<"third out of bounds"<<endl; return 0;} |
|---|
| 189 |
if(s.length()>3+i && (s[3+i]>'9' || s[3+i]<'0')) |
|---|
| 190 |
{cout<<"fourth out of bounds"<<endl; return 0;} |
|---|
| 191 |
if(s.length()>4+i && (s[4+i]>'9' || s[4+i]<'0')) |
|---|
| 192 |
{cout<<"fourth out of bounds"<<endl; return 0;} |
|---|
| 193 |
return 1; |
|---|
| 194 |
} |
|---|