summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-02-20 16:29:21 +0000
committerJoursoir <chat@joursoir.net>2021-02-20 16:29:21 +0000
commit6a0fc4c8c53f539cf0779ec750b0282db74c63d1 (patch)
treea135dc8233f2ef940a91e4f1ca8eebceb779cf67
parent9a668c78bed7197e0b349d4bd2908a67bedd295f (diff)
downloadlp-gomoku-6a0fc4c8c53f539cf0779ec750b0282db74c63d1.tar.gz
lp-gomoku-6a0fc4c8c53f539cf0779ec750b0282db74c63d1.tar.bz2
lp-gomoku-6a0fc4c8c53f539cf0779ec750b0282db74c63d1.zip
min() and max() -> MinMax()
-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 */