diff options
author | Joursoir <chat@joursoir.net> | 2021-02-20 16:29:21 +0000 |
---|---|---|
committer | Joursoir <chat@joursoir.net> | 2021-02-20 16:29:21 +0000 |
commit | 6a0fc4c8c53f539cf0779ec750b0282db74c63d1 (patch) | |
tree | a135dc8233f2ef940a91e4f1ca8eebceb779cf67 | |
parent | 9a668c78bed7197e0b349d4bd2908a67bedd295f (diff) | |
download | lp-gomoku-6a0fc4c8c53f539cf0779ec750b0282db74c63d1.tar.gz lp-gomoku-6a0fc4c8c53f539cf0779ec750b0282db74c63d1.tar.bz2 lp-gomoku-6a0fc4c8c53f539cf0779ec750b0282db74c63d1.zip |
min() and max() -> MinMax()
-rw-r--r-- | ai.cpp | 34 | ||||
-rw-r--r-- | ai.hpp | 3 |
2 files changed, 4 insertions, 33 deletions
@@ -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; } @@ -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 */ |