| 1 |
/* |
| 2 |
* Copyright (C) 2004 Ivo Danihelka ([email protected]) |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; either version 2 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
*/ |
| 9 |
#include "Goal.h" |
| 10 |
|
| 11 |
#include "Cube.h" |
| 12 |
|
| 13 |
//----------------------------------------------------------------- |
| 14 |
Goal::Goal(eSATISFY out, eSATISFY alive) |
| 15 |
{ |
| 16 |
m_out = out; |
| 17 |
m_alive = alive; |
| 18 |
} |
| 19 |
//----------------------------------------------------------------- |
| 20 |
Goal |
| 21 |
Goal::noGoal() |
| 22 |
{ |
| 23 |
return Goal(SATISFY_IGNORE, SATISFY_IGNORE); |
| 24 |
} |
| 25 |
//----------------------------------------------------------------- |
| 26 |
Goal |
| 27 |
Goal::outGoal() |
| 28 |
{ |
| 29 |
return Goal(SATISFY_TRUE, SATISFY_IGNORE); |
| 30 |
} |
| 31 |
//----------------------------------------------------------------- |
| 32 |
Goal |
| 33 |
Goal::escapeGoal() |
| 34 |
{ |
| 35 |
return Goal(SATISFY_TRUE, SATISFY_TRUE); |
| 36 |
} |
| 37 |
//----------------------------------------------------------------- |
| 38 |
Goal |
| 39 |
Goal::aliveGoal() |
| 40 |
{ |
| 41 |
return Goal(SATISFY_IGNORE, SATISFY_TRUE); |
| 42 |
} |
| 43 |
//----------------------------------------------------------------- |
| 44 |
bool |
| 45 |
Goal::isSatisfy(const Cube *model) const |
| 46 |
{ |
| 47 |
bool result = true; |
| 48 |
if (SATISFY_TRUE == m_out) { |
| 49 |
result &= model->isOut(); |
| 50 |
} |
| 51 |
else if (SATISFY_FALSE == m_out) { |
| 52 |
result &= (!model->isOut()); |
| 53 |
} |
| 54 |
|
| 55 |
if (SATISFY_TRUE == m_alive) { |
| 56 |
result &= model->isAlive(); |
| 57 |
} |
| 58 |
else if (SATISFY_FALSE == m_alive) { |
| 59 |
result &= (!model->isAlive()); |
| 60 |
} |
| 61 |
|
| 62 |
return result; |
| 63 |
} |
| 64 |
//----------------------------------------------------------------- |
| 65 |
/** |
| 66 |
* Return whether goal cannot by solved any more. |
| 67 |
* Dead fish cannot be revived. |
| 68 |
* Object out of room cannot go back. |
| 69 |
*/ |
| 70 |
bool |
| 71 |
Goal::isWrong(const Cube *model) const |
| 72 |
{ |
| 73 |
bool wrong = false; |
| 74 |
if (SATISFY_TRUE == m_alive) { |
| 75 |
wrong |= !model->isAlive(); |
| 76 |
} |
| 77 |
|
| 78 |
if (SATISFY_FALSE == m_out) { |
| 79 |
wrong |= model->isOut(); |
| 80 |
} |
| 81 |
return wrong; |
| 82 |
} |
| 83 |
//----------------------------------------------------------------- |
| 84 |
bool |
| 85 |
Goal::shouldGoOut() const |
| 86 |
{ |
| 87 |
return SATISFY_TRUE == m_out; |
| 88 |
} |
| 89 |
|
| 90 |
|