26 mVariableTiming (true),
27 mAlwaysCollectNugget (true),
29 mReappearAtTop (true),
44 {40, 58, 78, 88, 340, 23},
45 {50, 68, 78, 88, 340, 32},
46 {57, 67, 114, 128, 540, 37},
47 {60, 70, 134, 136, 660, 40},
48 {63, 76, 165, 150, 800, 46},
49 {70, 80, 189, 165, 920, 51}
52 choice = (enemyCount < 0) ? 0 : enemyCount;
53 choice = (enemyCount > 5) ? 5 : enemyCount;
54 times = varTiming [choice];
76 Timing t = {40, 58, 78, 88, 340, 23};
85 const int hI,
const int hJ,
101 dbk2 <<
"not DOWN yet";
106 dirn = getHero (eI, eJ, hI);
113 dirn = searchUp (eI, eJ, hJ);
116 dirn = searchDown (eI, eJ, hJ);
117 dbk2 <<
"searchDown1" << eI << eJ << hJ <<
"ret" << dirn;
119 dirn = searchUp (eI, eJ, hJ);
124 dirn = searchDown (eI, eJ, eJ - 1);
125 dbk2 <<
"searchDown2" << eI << eJ << (eJ - 1) <<
"ret" << dirn;
131 Direction KGrTraditionalRules::searchUp (
int ew,
int eh,
int hh)
133 int i, ilen, ipos, j, jlen, jpos, deltah, rungs;
138 i = ew; ilen = 0; ipos = -1;
140 rungs = distanceUp (i, eh, deltah);
145 if (searchOK (-1, i, eh))
152 j = ew; jlen = 0; jpos = -1;
154 if (searchOK (+1, j, eh)) {
156 rungs = distanceUp (j, eh, deltah);
166 if ((ilen == 0) && (jlen == 0))
185 else if (ilen == deltah) {
186 if ((ew - ipos) <= (jpos - ew))
195 Direction KGrTraditionalRules::searchDown (
int ew,
int eh,
int hh)
197 int i, ilen, ipos, j, jlen, jpos, deltah, rungs, path;
203 i = (willNotFall (ew, eh)) ? ew : -1;
204 rungs = distanceDown (ew, eh, deltah);
206 ilen = rungs; ipos = ew;
210 rungs = distanceDown (i - 1, eh, deltah);
211 if (((rungs > 0) && (ilen == 0)) ||
212 ((deltah > 0) && (rungs > ilen)) ||
213 ((deltah <= 0) && (rungs < ilen) && (rungs != 0))) {
217 if (searchOK (-1, i, eh))
224 j = ew; jlen = 0; jpos = -1;
226 rungs = distanceDown (j + 1, eh, deltah);
227 if (((rungs > 0) && (jlen == 0)) ||
228 ((deltah > 0) && (rungs > jlen)) ||
229 ((deltah <= 0) && (rungs < jlen) && (rungs != 0))) {
233 if (searchOK (+1, j, eh)) {
240 if ((ilen == 0) && (jlen == 0))
248 else if (ilen != jlen) {
266 if ((ew - ipos) <= (jpos - ew))
283 Direction KGrTraditionalRules::getHero (
int eI,
int eJ,
int hI)
285 int i, inc, returnValue;
287 inc = (eI > hI) ? -1 : +1;
290 returnValue = canWalkLR (inc, i, eJ);
293 else if (returnValue < 0)
299 if (i < eI)
return LEFT;
300 else if (i > eI)
return RIGHT;
304 int KGrTraditionalRules::distanceUp (
int x,
int y,
int deltah)
311 if (rungs >= deltah) {
318 int KGrTraditionalRules::distanceDown (
int x,
int y,
int deltah)
325 bool canGoThru =
true;
337 if ((deltah > 0) && (rungs <= deltah))
339 if ((objType ==
HOLE) && (rungs < 0))
347 if ((deltah > 0) && (rungs >= 0)) {
349 if ((rungs - 1) <= deltah) {
351 if ((objType ==
LADDER) && (searchOK (-1, x, y+rungs-1) ||
352 searchOK (+1, x, y+rungs-1)))
353 exitRung = rungs - 1;
355 if ((rungs <= deltah) && (searchOK (-1, x, y+rungs) ||
356 searchOK (+1, x, y+rungs)))
371 <<
"at" << x << (y + 1);
383 bool KGrTraditionalRules::searchOK (
int direction,
int x,
int y)
386 if (canWalkLR (direction, x, y) > 0) {
388 if (willNotFall (x+direction, y))
394 int KGrTraditionalRules::canWalkLR (
int direction,
int x,
int y)
396 if (willNotFall (x, y)) {
416 bool KGrTraditionalRules::willNotFall (
int x,
int y)
442 <<
"at" << x << (y + 1);
470 Timing t = {45, 50, 55, 100, 1000, 40};
479 const int hI,
const int hJ,
481 bool leftRightSearch)
483 dbk2 << eI << eJ << hI << hJ;
499 if (leftRightSearch) {
501 return findWayLeft (eI, eJ);
504 return findWayRight (eI, eJ);
509 return findWayUp (eI, eJ);
512 return findWayDown (eI, eJ);
519 Direction KGrKGoldrunnerRules::findWayUp (
const int eI,
const int eJ)
554 Direction KGrKGoldrunnerRules::findWayDown (
const int eI,
const int eJ)
586 Direction KGrKGoldrunnerRules::findWayLeft (
const int eI,
const int eJ)
620 Direction KGrKGoldrunnerRules::findWayRight (
const int eI,
const int eJ)
670 Timing t = {45, 50, 55, 100, 1000, 40};
679 const int hI,
const int hJ,
683 dbk2 << eI << eJ << hI << hJ;
688 #include "kgrrulebook.moc"
KGrScavengerRules(QObject *parent)
int enemyOccupied(int i, int j)
char cellType(int i, int j)
Direction findBestWay(const int eI, const int eJ, const int hI, const int hJ, KGrLevelGrid *pGrid, bool leftRightSearch=true)
KGrRuleBook(QObject *parent)
KGrKGoldrunnerRules(QObject *parent)
bool mRunThruHole
Enemy can run L/R through dug hole.
Flags enemyMoves(int i, int j)
const char TraditionalRules
Codes for the rules of the selected game and level.
int mPointsPerCell
Number of points in each grid-cell.
bool mAlwaysCollectNugget
Enemies always collect nuggets.
Direction findBestWay(const int eI, const int eJ, const int hI, const int hJ, KGrLevelGrid *pGrid, bool leftRightSearch=true)
const char ScavengerRules
int mReappearRow
Row where enemies reappear.
char mRules
The type of rules and enemy search method.
bool mReappearAtTop
Enemies reborn at top of screen.
const char KGoldrunnerRules
bool mEnemiesShowGold
Enemies show when they are carrying gold.
void setTiming(const int enemyCount=0)
KGrTraditionalRules(QObject *parent)
Direction findBestWay(const int eI, const int eJ, const int hI, const int hJ, KGrLevelGrid *pGrid, bool leftRightSearch=true)
bool mVariableTiming
More enemies imply less speed.
const DirectionFlag dFlag[nDirections]
bool mTurnAnywhere
Can change direction anywhere in grid-cell.