summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ai.cpp34
-rw-r--r--ai.hpp3
2 files changed, 4 insertions, 33 deletions
diff --git a/ai.cpp b/ai.cpp
index 05f95af..dafa57a 100644
--- a/ai.cpp
+++ b/ai.cpp
@@ -39,7 +39,7 @@ void AI::GetBestMove(int &my, int &mx, GameField field)
if(!field.CanMove(y, x))
continue;
field.Move(y, x);
- int result = min(field, 1);
+ int result = MinMax(field, 1);
field.UndoMove(y, x);
if(result > score) {
score = result;
@@ -62,7 +62,7 @@ int AI::score(GameField field)
return NONE_SCORE;
}
-int AI::min(GameField field, int depth)
+int AI::MinMax(GameField field, int depth)
{
if(field.GetState() != G_NONE || depth >= max_depth) {
return score(field);
@@ -79,39 +79,11 @@ int AI::min(GameField field, int depth)
if(!field.CanMove(y, x))
continue;
field.Move(y, x);
- int result = max(field, depth + 1);
+ int result = MinMax(field, depth + 1);
field.UndoMove(y, x);
if(result < score)
score = result;
}
}
-
- return score;
-}
-
-int AI::max(GameField field, int depth)
-{
- if(field.GetState() != G_NONE || depth >= max_depth) {
- return score(field);
- }
-
- int score = MIN_SCORE;
- int rows = field.GetRows();
- int cols = field.GetCols();
-
- int y, x;
- for(y = 0; y < rows; y++) {
- for(x = 0; x < cols; x++)
- {
- if(!field.CanMove(y, x))
- continue;
- field.Move(y, x);
- int result = min(field, depth + 1);
- field.UndoMove(y, x);
- if(result > score)
- score = result;
- }
- }
-
return score;
}
diff --git a/ai.hpp b/ai.hpp
index 0b757c9..ec1f56b 100644
--- a/ai.hpp
+++ b/ai.hpp
@@ -13,8 +13,7 @@ public:
void GetBestMove(int &my, int &mx, GameField field);
private:
int score(GameField field);
- int min(GameField field, int depth);
- int max(GameField field, int depth);
+ int MinMax(GameField field, int depth);
};
#endif /* LPG_AI_H */