diff --git a/src/CaroJudge.cpp b/src/CaroJudge.cpp index 4611c1e..a597687 100644 --- a/src/CaroJudge.cpp +++ b/src/CaroJudge.cpp @@ -33,15 +33,14 @@ SOFTWARE. #include #include -using namespace std; -bool CaroJudge::findShap(const board_type &board, int last_move, const pair &p_drt) +bool CaroJudge::findShap(const board_type &board, int last_move, const std::pair &p_drt) { - vector vColor; + std::vector vColor; size_t n = board.size(); - pair p_idx((int)(last_move / n), (int)(last_move % n)); - pair p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second); + std::pair p_idx((int)(last_move / n), (int)(last_move % n)); + std::pair p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second); // push back current stone color if (1 == board[last_move / n][last_move % n]) @@ -131,7 +130,7 @@ bool CaroJudge::checkWin(const board_type &board, int last_move) } size_t n = board.size(); - pair p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1); + std::pair p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1); bool b_up = findShap(board, last_move, p_drt_up); bool b_left = findShap(board, last_move, p_drt_left); bool b_leftup = findShap(board, last_move, p_drt_leftup); diff --git a/src/CaroJudge.h b/src/CaroJudge.h index c9edb71..67b0d1b 100644 --- a/src/CaroJudge.h +++ b/src/CaroJudge.h @@ -34,7 +34,6 @@ SOFTWARE. #include "rule.h" #include -using namespace std; const int WIN_SHAPES[][7] = { {1, 1, 1, 1, 1, 0, 0}, @@ -91,7 +90,7 @@ class CaroJudge final : public rule private: bool isPosOutOfBoard(unsigned int n, int x, int y); - bool findShap(const board_type &board, int last_move, const pair &p_drt); + bool findShap(const board_type &board, int last_move, const std::pair &p_drt); }; #endif diff --git a/src/FreeStyleJudge.cpp b/src/FreeStyleJudge.cpp index bcdf7b8..868ed39 100644 --- a/src/FreeStyleJudge.cpp +++ b/src/FreeStyleJudge.cpp @@ -31,22 +31,21 @@ SOFTWARE. #include "FreeStyleJudge.h" #include -using namespace std; bool FreeStyleJudge::isPosOutOfBoard(unsigned int n, int x, int y) { return ((unsigned int)x > n - 1) || ((unsigned int)y > n - 1) || x < 0 || y < 0; } -int FreeStyleJudge::countNearStone(const board_type &board, int last_move, const pair &p_drt) +int FreeStyleJudge::countNearStone(const board_type &board, int last_move, const std::pair &p_drt) { int i_count = 0; if (-1 == last_move) return 0; size_t n = board.size(); - pair p_idx((int)(last_move / n), (int)(last_move % n)); - pair p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second); + std::pair p_idx((int)(last_move / n), (int)(last_move % n)); + std::pair p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second); while (!isPosOutOfBoard((unsigned int)n, p_drt_idx.first, p_drt_idx.second) && 0 != board[p_drt_idx.first][p_drt_idx.second]) { @@ -76,7 +75,7 @@ bool FreeStyleJudge::checkWin(const board_type &board, int last_move) size_t n = board.size(); - pair p_drt_up(0, -1), + std::pair p_drt_up(0, -1), p_drt_down(0, 1), p_drt_left(-1, 0), p_drt_right(1, 0), diff --git a/src/FreeStyleJudge.h b/src/FreeStyleJudge.h index d81edbd..0d270cf 100644 --- a/src/FreeStyleJudge.h +++ b/src/FreeStyleJudge.h @@ -8,7 +8,7 @@ /** MIT License -Copyright (c) 2023 Joker2770 +Copyright (c) 2023-2024 Joker2770 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -34,7 +34,6 @@ SOFTWARE. #include "rule.h" #include -using namespace std; class FreeStyleJudge final : public rule { @@ -43,7 +42,7 @@ class FreeStyleJudge final : public rule private: bool isPosOutOfBoard(unsigned int n, int x, int y); - int countNearStone(const board_type &board, int last_move, const pair &p_drt); + int countNearStone(const board_type &board, int last_move, const std::pair &p_drt); }; #endif diff --git a/src/RenjuJudge.cpp b/src/RenjuJudge.cpp index 159446a..3ba461a 100644 --- a/src/RenjuJudge.cpp +++ b/src/RenjuJudge.cpp @@ -32,11 +32,10 @@ SOFTWARE. #include "RenjuJudge.h" #include #include -using namespace std; bool RenjuJudge::isOverLine(const board_type &board, int last_move) { - pair p_drt_up(0, -1), p_drt_down(0, 1), p_drt_left(-1, 0), p_drt_right(1, 0), p_drt_leftup(-1, -1), p_drt_rightdown(1, 1), p_drt_rightup(1, -1), p_drt_leftdown(-1, 1); + std::pair p_drt_up(0, -1), p_drt_down(0, 1), p_drt_left(-1, 0), p_drt_right(1, 0), p_drt_leftup(-1, -1), p_drt_rightdown(1, 1), p_drt_rightup(1, -1), p_drt_leftdown(-1, 1); int i_up = countNearStone(board, last_move, p_drt_up); int i_down = countNearStone(board, last_move, p_drt_down); int i_left = countNearStone(board, last_move, p_drt_left); @@ -52,15 +51,15 @@ bool RenjuJudge::isOverLine(const board_type &board, int last_move) return false; } -int RenjuJudge::countA4(const board_type &board, int last_move, const pair &p_drt) +int RenjuJudge::countA4(const board_type &board, int last_move, const std::pair &p_drt) { int i_count = 0; - vector vColor; + std::vector vColor; size_t n = board.size(); - pair p_idx((int)(last_move / n), (int)(last_move % n)); - pair p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second); + std::pair p_idx((int)(last_move / n), (int)(last_move % n)); + std::pair p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second); // push back current stone color if (1 == board[last_move / n][last_move % n]) @@ -178,7 +177,7 @@ int RenjuJudge::countA4(const board_type &board, int last_move, const pair p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1); + std::pair p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1); int i_up = countA4(board, last_move, p_drt_up); int i_left = countA4(board, last_move, p_drt_left); int i_leftup = countA4(board, last_move, p_drt_leftup); @@ -190,13 +189,13 @@ bool RenjuJudge::isDoubleFour(const board_type &board, int last_move) return false; } -int RenjuJudge::countA3(const board_type &board, int last_move, const pair &p_drt) +int RenjuJudge::countA3(const board_type &board, int last_move, const std::pair &p_drt) { - vector vColor; + std::vector vColor; size_t n = board.size(); - pair p_idx((unsigned int)(last_move / n), (unsigned int)(last_move % n)); - pair p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second); + std::pair p_idx((unsigned int)(last_move / n), (unsigned int)(last_move % n)); + std::pair p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second); // push back current stone color if (1 == board[last_move / n][last_move % n]) @@ -287,7 +286,7 @@ int RenjuJudge::countA3(const board_type &board, int last_move, const pair p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1); + std::pair p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1); int i_up_4 = countA4(board, last_move, p_drt_up); int i_left_4 = countA4(board, last_move, p_drt_left); int i_leftup_4 = countA4(board, last_move, p_drt_leftup); @@ -342,7 +341,7 @@ bool RenjuJudge::isFourThree(const board_type &board, int last_move) bool RenjuJudge::isFour(const board_type &board, int last_move) { - pair p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1); + std::pair p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1); int i_up_4 = countA4(board, last_move, p_drt_up); int i_left_4 = countA4(board, last_move, p_drt_left); int i_leftup_4 = countA4(board, last_move, p_drt_leftup); @@ -381,7 +380,7 @@ bool RenjuJudge::isFour(const board_type &board, int last_move) bool RenjuJudge::isDoubleThree(const board_type &board, int last_move) { - pair p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1); + std::pair p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1); int i_up_4 = countA4(board, last_move, p_drt_up); int i_left_4 = countA4(board, last_move, p_drt_left); int i_leftup_4 = countA4(board, last_move, p_drt_leftup); @@ -444,7 +443,7 @@ bool RenjuJudge::isDoubleThree(const board_type &board, int last_move) bool RenjuJudge::isThree(const board_type &board, int last_move) { - pair p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1); + std::pair p_drt_up(0, -1), p_drt_left(-1, 0), p_drt_leftup(-1, -1), p_drt_leftdown(-1, 1); int i_up_4 = countA4(board, last_move, p_drt_up); int i_left_4 = countA4(board, last_move, p_drt_left); int i_leftup_4 = countA4(board, last_move, p_drt_leftup); @@ -523,15 +522,15 @@ bool RenjuJudge::isPosOutOfBoard(unsigned int n, int x, int y) return ((unsigned int)x > n - 1) || ((unsigned int)y > n - 1) || x < 0 || y < 0; } -int RenjuJudge::countNearStone(const board_type &board, int last_move, const pair &p_drt) +int RenjuJudge::countNearStone(const board_type &board, int last_move, const std::pair &p_drt) { int i_count = 0; if (-1 == last_move) return 0; size_t n = board.size(); - pair p_idx((int)(last_move / n), (int)(last_move % n)); - pair p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second); + std::pair p_idx((int)(last_move / n), (int)(last_move % n)); + std::pair p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second); while (!isPosOutOfBoard((unsigned int)n, p_drt_idx.first, p_drt_idx.second) && 0 != board[p_drt_idx.first][p_drt_idx.second]) { @@ -561,7 +560,7 @@ bool RenjuJudge::checkWin(const board_type &board, int last_move) size_t n = board.size(); - pair p_drt_up(0, -1), + std::pair p_drt_up(0, -1), p_drt_down(0, 1), p_drt_left(-1, 0), p_drt_right(1, 0), diff --git a/src/RenjuJudge.h b/src/RenjuJudge.h index d72c551..7a73de6 100644 --- a/src/RenjuJudge.h +++ b/src/RenjuJudge.h @@ -8,7 +8,7 @@ /** MIT License -Copyright (c) 2023 Joker2770 +Copyright (c) 2023-2024 Joker2770 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -34,7 +34,6 @@ SOFTWARE. #include "rule.h" #include -using namespace std; typedef enum pattern { @@ -83,10 +82,10 @@ class RenjuJudge final : public rule bool isDoubleThree(const board_type &board, int last_move); // after double-three, only 3 bool isThree(const board_type &board, int last_move); - int countA4(const board_type &board, int last_move, const pair &p_drt); - int countA3(const board_type &board, int last_move, const pair &p_drt); + int countA4(const board_type &board, int last_move, const std::pair &p_drt); + int countA3(const board_type &board, int last_move, const std::pair &p_drt); bool isPosOutOfBoard(unsigned int n, int x, int y); - int countNearStone(const board_type &board, int last_move, const pair &p_drt); + int countNearStone(const board_type &board, int last_move, const std::pair &p_drt); int m_renju_state; }; diff --git a/src/StandardJudge.cpp b/src/StandardJudge.cpp index 7ed6389..ecb92f2 100644 --- a/src/StandardJudge.cpp +++ b/src/StandardJudge.cpp @@ -31,22 +31,21 @@ SOFTWARE. #include "StandardJudge.h" #include -using namespace std; bool StandardJudge::isPosOutOfBoard(unsigned int n, int x, int y) { return ((unsigned int)x > n - 1) || ((unsigned int)y > n - 1) || x < 0 || y < 0; } -int StandardJudge::countNearStone(const board_type &board, int last_move, const pair &p_drt) +int StandardJudge::countNearStone(const board_type &board, int last_move, const std::pair &p_drt) { int i_count = 0; if (-1 == last_move) return 0; size_t n = board.size(); - pair p_idx((int)(last_move / n), (int)(last_move % n)); - pair p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second); + std::pair p_idx((int)(last_move / n), (int)(last_move % n)); + std::pair p_drt_idx(p_idx.first + p_drt.first, p_idx.second + p_drt.second); while (!isPosOutOfBoard((unsigned int)n, p_drt_idx.first, p_drt_idx.second) && 0 != board[p_drt_idx.first][p_drt_idx.second]) { @@ -76,7 +75,7 @@ bool StandardJudge::checkWin(const board_type &board, int last_move) size_t n = board.size(); - pair p_drt_up(0, -1), + std::pair p_drt_up(0, -1), p_drt_down(0, 1), p_drt_left(-1, 0), p_drt_right(1, 0), diff --git a/src/StandardJudge.h b/src/StandardJudge.h index 740f906..46d9aa5 100644 --- a/src/StandardJudge.h +++ b/src/StandardJudge.h @@ -8,7 +8,7 @@ /** MIT License -Copyright (c) 2023 Joker2770 +Copyright (c) 2023-2024 Joker2770 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -34,7 +34,6 @@ SOFTWARE. #include "rule.h" #include -using namespace std; class StandardJudge final : public rule { @@ -43,7 +42,7 @@ class StandardJudge final : public rule private: bool isPosOutOfBoard(unsigned int n, int x, int y); - int countNearStone(const board_type &board, int last_move, const pair &p_drt); + int countNearStone(const board_type &board, int last_move, const std::pair &p_drt); }; #endif diff --git a/src/onnx.cpp b/src/onnx.cpp index 42bc0f3..552dddd 100644 --- a/src/onnx.cpp +++ b/src/onnx.cpp @@ -145,7 +145,7 @@ NeuralNetwork::NeuralNetwork(const std::string &model_path, const unsigned int b // print input node names char *input_name = shared_session->GetInputName(i, allocator); // printf("Input %d : name = %s\n", i, input_name); - input_node_names[i] = input_name; + this->input_node_names[i] = input_name; // print input node types Ort::TypeInfo type_info = shared_session->GetInputTypeInfo(i); diff --git a/src/pbrain-Z2I/pbrain-Z2I.cpp b/src/pbrain-Z2I/pbrain-Z2I.cpp index 5fd7775..f98762b 100644 --- a/src/pbrain-Z2I/pbrain-Z2I.cpp +++ b/src/pbrain-Z2I/pbrain-Z2I.cpp @@ -38,8 +38,6 @@ SOFTWARE. #include #include #include -#include -using namespace std; bool isNumericString(const char *str, size_t i_len) { @@ -53,18 +51,18 @@ bool isNumericString(const char *str, size_t i_len) return true; } -vector split(const string &str, const string &pattern) +std::vector split(const std::string &str, const std::string &pattern) { - string::size_type pos; - vector result; - string strs = str + pattern; + std::string::size_type pos; + std::vector result; + std::string strs = str + pattern; size_t size = strs.size(); for (size_t i = 0; i < size; ++i) { pos = strs.find(pattern, i); if (pos < size) { - string s = strs.substr(i, pos - i); + std::string s = strs.substr(i, pos - i); result.push_back(s); i = pos + pattern.size() - 1; } @@ -72,7 +70,7 @@ vector split(const string &str, const string &pattern) return result; } -void toupper(string &str) +void toupper(std::string &str) { for (size_t i = 0; i < str.size(); i++) { @@ -86,35 +84,35 @@ void toupper(string &str) int main(int argc, char *argv[]) { - cout << "MESSAGE ................................................................................." << endl; - cout << "MESSAGE MIT License" << endl; - cout << "MESSAGE " << endl; - cout << "MESSAGE Copyright (c) 2023-2024 Joker2770" << endl; - cout << "MESSAGE " << endl; - cout << "MESSAGE Permission is hereby granted, free of charge, to any person obtaining a copy" << endl; - cout << "MESSAGE of this software and associated documentation files (the \"Software\"), to deal" << endl; - cout << "MESSAGE in the Software without restriction, including without limitation the rights" << endl; - cout << "MESSAGE to use, copy, modify, merge, publish, distribute, sublicense, and/or sell" << endl; - cout << "MESSAGE copies of the Software, and to permit persons to whom the Software is" << endl; - cout << "MESSAGE furnished to do so, subject to the following conditions:" << endl; - cout << "MESSAGE MESSAGE " << endl; - cout << "MESSAGE The above copyright notice and this permission notice shall be included in all" << endl; - cout << "MESSAGE copies or substantial portions of the Software." << endl; - cout << "MESSAGE " << endl; - cout << "MESSAGE THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR" << endl; - cout << "MESSAGE IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY," << endl; - cout << "MESSAGE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE" << endl; - cout << "MESSAGE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER" << endl; - cout << "MESSAGE LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM," << endl; - cout << "MESSAGE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE" << endl; - cout << "MESSAGE SOFTWARE." << endl; - cout << "MESSAGE " << endl; - cout << "MESSAGE ................................................................................." << endl; + std::cout << "MESSAGE ................................................................................." << std::endl; + std::cout << "MESSAGE MIT License" << std::endl; + std::cout << "MESSAGE " << std::endl; + std::cout << "MESSAGE Copyright (c) 2023-2024 Joker2770" << std::endl; + std::cout << "MESSAGE " << std::endl; + std::cout << "MESSAGE Permission is hereby granted, free of charge, to any person obtaining a copy" << std::endl; + std::cout << "MESSAGE of this software and associated documentation files (the \"Software\"), to deal" << std::endl; + std::cout << "MESSAGE in the Software without restriction, including without limitation the rights" << std::endl; + std::cout << "MESSAGE to use, copy, modify, merge, publish, distribute, sublicense, and/or sell" << std::endl; + std::cout << "MESSAGE copies of the Software, and to permit persons to whom the Software is" << std::endl; + std::cout << "MESSAGE furnished to do so, subject to the following conditions:" << std::endl; + std::cout << "MESSAGE MESSAGE " << std::endl; + std::cout << "MESSAGE The above copyright notice and this permission notice shall be included in all" << std::endl; + std::cout << "MESSAGE copies or substantial portions of the Software." << std::endl; + std::cout << "MESSAGE " << std::endl; + std::cout << "MESSAGE THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR" << std::endl; + std::cout << "MESSAGE IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY," << std::endl; + std::cout << "MESSAGE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE" << std::endl; + std::cout << "MESSAGE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER" << std::endl; + std::cout << "MESSAGE LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM," << std::endl; + std::cout << "MESSAGE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE" << std::endl; + std::cout << "MESSAGE SOFTWARE." << std::endl; + std::cout << "MESSAGE " << std::endl; + std::cout << "MESSAGE ................................................................................." << std::endl; std::shared_ptr module = nullptr; std::filesystem::path exe_path = std::filesystem::canonical(std::filesystem::path(argv[0])).remove_filename(); - string s_config_file_path = exe_path.string() + "config.toml"; - string s_model_path; + std::string s_config_file_path = exe_path.string() + "config.toml"; + std::string s_model_path; unsigned int u_num_mct_sims = 1600; unsigned int u_num_mct_threads = 10; toml::value toml_data; @@ -125,31 +123,31 @@ int main(int argc, char *argv[]) u_num_mct_sims = toml::find(toml_data["MCTS"], "num_mct_sims"); if (toml_data["MCTS"].is_table()) u_num_mct_threads = toml::find(toml_data["MCTS"], "num_mct_threads"); - cout << "MESSAGE num_mct_sims: " << u_num_mct_sims << endl; - cout << "MESSAGE num_mct_threads: " << u_num_mct_threads << endl; + std::cout << "MESSAGE num_mct_sims: " << u_num_mct_sims << std::endl; + std::cout << "MESSAGE num_mct_threads: " << u_num_mct_threads << std::endl; if (toml_data["model"].is_table()) s_model_path = exe_path.string() + toml::find(toml_data["model"], "default_model"); - cout << "MESSAGE model load path: " << s_model_path << endl; + std::cout << "MESSAGE model load path: " << s_model_path << std::endl; if (!s_model_path.empty() && std::filesystem::exists(s_model_path)) { - cout << "MESSAGE model exists" << endl; + std::cout << "MESSAGE model exists" << std::endl; module = std::make_shared(s_model_path, NUM_MCT_SIMS); } else { - cout << "ERROR model not exists" << endl; + std::cout << "ERROR model not exists" << std::endl; return -1; } } else { - cout << "ERROR config file not exists" << endl; + std::cout << "ERROR config file not exists" << std::endl; return -1; } Gomoku *g = new Gomoku(BOARD_SIZE, N_IN_ROW, BLACK); g->set_rule(0); - cout << "MESSAGE game rule: " << g->get_rule() << endl; + std::cout << "MESSAGE game rule: " << g->get_rule() << std::endl; MCTS *m; m = new MCTS(module.get(), @@ -158,19 +156,19 @@ int main(int argc, char *argv[]) (unsigned int)(u_num_mct_sims != 0 ? u_num_mct_sims : NUM_MCT_SIMS), C_VIRTUAL_LOSS, BOARD_SIZE * BOARD_SIZE); - string command; + std::string command; unsigned int size = 0; char dot = ','; bool isPlaying = false; for (;;) { - cin >> command; + std::cin >> command; toupper(command); if (command == "START") { char s_size[4] = "\0"; - cin >> s_size; + std::cin >> s_size; if (isNumericString(s_size, strlen(s_size))) { size = atoi(s_size); @@ -186,11 +184,11 @@ int main(int argc, char *argv[]) if (size == 15) { - cout << "OK" << endl; + std::cout << "OK" << std::endl; } else { - cout << "ERROR unsupported board size!" << endl; + std::cout << "ERROR unsupported board size!" << std::endl; } } // else if (command == "RESTART") @@ -207,13 +205,13 @@ int main(int argc, char *argv[]) g->execute_move(res); unsigned int x = res / size; unsigned int y = res % size; - cout << x << "," << y << endl; + std::cout << x << "," << y << std::endl; } else if (command == "TURN") { isPlaying = true; unsigned int x, y; - cin >> x >> dot >> y; + std::cin >> x >> dot >> y; if (!(g->is_illegal(x, y))) { int move = x * size + y; @@ -227,23 +225,23 @@ int main(int argc, char *argv[]) { m->update_with_move(action); g->execute_move(action); - cout << x << "," << y << endl; + std::cout << x << "," << y << std::endl; } else { - cout << "ERROR Illegal move generated! " << endl; + std::cout << "ERROR Illegal move generated! " << std::endl; } } else { - cout << "ERROR Illegal move from opponent! " << endl; + std::cout << "ERROR Illegal move from opponent! " << std::endl; } } else if (command == "BOARD") { isPlaying = true; unsigned int x, y, c; - vector move_1, move_2, move_3; + std::vector move_1, move_2, move_3; if (nullptr != g) { @@ -252,14 +250,14 @@ int main(int argc, char *argv[]) } g = new Gomoku(BOARD_SIZE, N_IN_ROW, BLACK); - cin >> command; + std::cin >> command; while (command != "DONE") { - // cout << "DEBUG " << command << endl; - vector v_s = split(command, ","); + // std::cout << "DEBUG " << command << std::endl; + std::vector v_s = split(command, ","); if ((command.find_first_of(',', 0) != command.find_last_of(',', 0)) && v_s.size() == 3) { - // cout << "DEBUG " << v_s.at(0) << "," << v_s.at(1) << "," << v_s.at(2) << endl; + // std::cout << "DEBUG " << v_s.at(0) << "," << v_s.at(1) << "," << v_s.at(2) << std::endl; if (isNumericString(v_s.at(0).c_str(), v_s.at(0).length()) && isNumericString(v_s.at(1).c_str(), v_s.at(1).length()) && isNumericString(v_s.at(2).c_str(), v_s.at(2).length())) @@ -268,7 +266,7 @@ int main(int argc, char *argv[]) y = atoi(v_s.at(1).c_str()); c = atoi(v_s.at(2).c_str()); int move = x * size + y; - // cout << "DEBUG move: " << move << endl; + // std::cout << "DEBUG move: " << move << std::endl; if (c == 1) { move_1.push_back(move); @@ -287,7 +285,7 @@ int main(int argc, char *argv[]) } else { - cout << "ERROR Illegal pos! " << endl; + std::cout << "ERROR Illegal pos! " << std::endl; move_1.clear(); move_2.clear(); move_3.clear(); @@ -296,17 +294,17 @@ int main(int argc, char *argv[]) } else { - cout << "ERROR Illegal board! " << endl; + std::cout << "ERROR Illegal board! " << std::endl; move_1.clear(); move_2.clear(); move_3.clear(); break; } - cin >> command; + std::cin >> command; } - // cout << "DEBUG move_1 size: " << move_1.size() << endl; - // cout << "DEBUG move_2 size: " << move_2.size() << endl; - // cout << "DEBUG move_3 size: " << move_3.size() << endl; + // std::cout << "DEBUG move_1 size: " << move_1.size() << std::endl; + // std::cout << "DEBUG move_2 size: " << move_2.size() << std::endl; + // std::cout << "DEBUG move_3 size: " << move_3.size() << std::endl; if (move_1.size() == 0 && move_2.size() == 0 && move_3.size() != 0) { @@ -321,7 +319,7 @@ int main(int argc, char *argv[]) } else { - cout << "ERROR Illegal pos! " << endl; + std::cout << "ERROR Illegal pos! " << std::endl; move_3.clear(); break; } @@ -337,11 +335,11 @@ int main(int argc, char *argv[]) { m->update_with_move(action); g->execute_move(action); - cout << x << "," << y << endl; + std::cout << x << "," << y << std::endl; } else { - cout << "ERROR Illegal move generated! " << endl; + std::cout << "ERROR Illegal move generated! " << std::endl; break; } } @@ -366,7 +364,7 @@ int main(int argc, char *argv[]) } else { - cout << "ERROR Illegal pos! " << endl; + std::cout << "ERROR Illegal pos! " << std::endl; move_1.clear(); move_2.clear(); move_3.clear(); @@ -380,7 +378,7 @@ int main(int argc, char *argv[]) } else { - cout << "ERROR Illegal pos! " << endl; + std::cout << "ERROR Illegal pos! " << std::endl; move_1.clear(); move_2.clear(); move_3.clear(); @@ -396,7 +394,7 @@ int main(int argc, char *argv[]) } else { - cout << "ERROR Illegal pos! " << endl; + std::cout << "ERROR Illegal pos! " << std::endl; move_1.clear(); move_2.clear(); move_3.clear(); @@ -405,7 +403,7 @@ int main(int argc, char *argv[]) } else { - cout << "ERROR Illegal quantity gap! " << endl; + std::cout << "ERROR Illegal quantity gap! " << std::endl; move_1.clear(); move_2.clear(); move_3.clear(); @@ -428,7 +426,7 @@ int main(int argc, char *argv[]) } else { - cout << "ERROR Illegal pos! " << endl; + std::cout << "ERROR Illegal pos! " << std::endl; move_1.clear(); move_2.clear(); move_3.clear(); @@ -442,7 +440,7 @@ int main(int argc, char *argv[]) } else { - cout << "ERROR Illegal pos! " << endl; + std::cout << "ERROR Illegal pos! " << std::endl; move_1.clear(); move_2.clear(); move_3.clear(); @@ -457,30 +455,30 @@ int main(int argc, char *argv[]) std::vector p = m->get_action_probs(g); int action = m->get_best_action_from_prob(p); - // cout << "DEBUG action: " << action << endl; + // std::cout << "DEBUG action: " << action << std::endl; x = action / size; y = action % size; if (!g->is_illegal(x, y)) { m->update_with_move(action); g->execute_move(action); - cout << x << "," << y << endl; + std::cout << x << "," << y << std::endl; } else { - cout << "ERROR Illegal move generated! " << endl; + std::cout << "ERROR Illegal move generated! " << std::endl; } } else if (command == "INFO") { unsigned int value = 0; - string key; - cin >> key; + std::string key; + std::cin >> key; if (key == "timeout_turn") { char s_value[16] = "\0"; - cin >> s_value; + std::cin >> s_value; if (isNumericString(s_value, strlen(s_value))) { value = atoi(s_value); @@ -489,14 +487,14 @@ int main(int argc, char *argv[]) else if (key == "timeout_match") { char s_value[16] = "\0"; - cin >> s_value; + std::cin >> s_value; if (isNumericString(s_value, strlen(s_value))) value = atoi(s_value); } else if (key == "time_left") { char s_value[16] = "\0"; - cin >> s_value; + std::cin >> s_value; if (isNumericString(s_value, strlen(s_value))) value = atoi(s_value); @@ -518,7 +516,7 @@ int main(int argc, char *argv[]) else if (key == "max_memory") { char s_value[16] = "\0"; - cin >> s_value; + std::cin >> s_value; if (isNumericString(s_value, strlen(s_value))) value = atoi(s_value); // TODO @@ -526,7 +524,7 @@ int main(int argc, char *argv[]) else if (key == "game_type") { char s_value[16] = "\0"; - cin >> s_value; + std::cin >> s_value; if (isNumericString(s_value, strlen(s_value))) value = atoi(s_value); // TODO @@ -534,7 +532,7 @@ int main(int argc, char *argv[]) else if (key == "rule") { char s_value[16] = "\0"; - cin >> s_value; + std::cin >> s_value; if (isPlaying) continue; @@ -546,60 +544,60 @@ int main(int argc, char *argv[]) // renju > caro > standard > free-style if (0 == value) { - if (s_model_path.find("free-style") == string::npos) + if (s_model_path.find("free-style") == std::string::npos) { if (std::filesystem::exists(s_config_file_path)) { - cout << "MESSAGE change model path!" << endl; + std::cout << "MESSAGE change model path!" << std::endl; toml_data = toml::parse(s_config_file_path); if (toml_data["model"].is_table()) { - string s_tmp_path = exe_path.string() + toml::find(toml_data["model"], "free_style_model"); + std::string s_tmp_path = exe_path.string() + toml::find(toml_data["model"], "free_style_model"); if (std::filesystem::exists(s_tmp_path)) { - cout << "MESSAGE model exists" << endl; + std::cout << "MESSAGE model exists" << std::endl; s_model_path = s_tmp_path; - cout << "MESSAGE model load path: " << s_model_path << endl; + std::cout << "MESSAGE model load path: " << s_model_path << std::endl; bChangeModule = true; g->set_rule(0); } else { - cout << "ERROR model not exists" << endl; + std::cout << "ERROR model not exists" << std::endl; } } } else - cout << "ERROR config file not exists" << endl; + std::cout << "ERROR config file not exists" << std::endl; } } else if (4 == (value & 4)) { - if (s_model_path.find("renju") == string::npos) + if (s_model_path.find("renju") == std::string::npos) { if (std::filesystem::exists(s_config_file_path)) { - cout << "MESSAGE change model path!" << endl; + std::cout << "MESSAGE change model path!" << std::endl; toml_data = toml::parse(s_config_file_path); if (toml_data["model"].is_table()) { - string s_tmp_path = exe_path.string() + toml::find(toml_data["model"], "renju_model"); + std::string s_tmp_path = exe_path.string() + toml::find(toml_data["model"], "renju_model"); if (std::filesystem::exists(s_tmp_path)) { - cout << "MESSAGE model exists" << endl; + std::cout << "MESSAGE model exists" << std::endl; s_model_path = s_tmp_path; - cout << "MESSAGE model load path: " << s_model_path << endl; + std::cout << "MESSAGE model load path: " << s_model_path << std::endl; bChangeModule = true; g->set_rule(4); } else { - cout << "ERROR model not exists" << endl; + std::cout << "ERROR model not exists" << std::endl; } } } else - cout << "ERROR config file not exists" << endl; + std::cout << "ERROR config file not exists" << std::endl; } } else if (8 == (value & 8)) @@ -607,101 +605,101 @@ int main(int argc, char *argv[]) // standard caro if (1 == (value & 1)) { - if (s_model_path.find("standard_caro") == string::npos) + if (s_model_path.find("standard_caro") == std::string::npos) { if (std::filesystem::exists(s_config_file_path)) { - cout << "MESSAGE change model path!" << endl; + std::cout << "MESSAGE change model path!" << std::endl; toml_data = toml::parse(s_config_file_path); if (toml_data["model"].is_table()) { - string s_tmp_path = exe_path.string() + toml::find(toml_data["model"], "standard_caro_model"); + std::string s_tmp_path = exe_path.string() + toml::find(toml_data["model"], "standard_caro_model"); if (std::filesystem::exists(s_tmp_path)) { - cout << "MESSAGE model exists" << endl; + std::cout << "MESSAGE model exists" << std::endl; s_model_path = s_tmp_path; - cout << "MESSAGE model load path: " << s_model_path << endl; + std::cout << "MESSAGE model load path: " << s_model_path << std::endl; bChangeModule = true; g->set_rule(9); } else { - cout << "ERROR model not exists" << endl; + std::cout << "ERROR model not exists" << std::endl; } } } else - cout << "ERROR config file not exists" << endl; + std::cout << "ERROR config file not exists" << std::endl; } } else { - if (s_model_path.find("caro") == string::npos || (s_model_path.find("standard_caro") != string::npos)) + if (s_model_path.find("caro") == std::string::npos || (s_model_path.find("standard_caro") != std::string::npos)) { if (std::filesystem::exists(s_config_file_path)) { - cout << "MESSAGE change model path!" << endl; + std::cout << "MESSAGE change model path!" << std::endl; toml_data = toml::parse(s_config_file_path); if (toml_data["model"].is_table()) { - string s_tmp_path = exe_path.string() + toml::find(toml_data["model"], "caro_model"); + std::string s_tmp_path = exe_path.string() + toml::find(toml_data["model"], "caro_model"); if (std::filesystem::exists(s_tmp_path)) { - cout << "MESSAGE model exists" << endl; + std::cout << "MESSAGE model exists" << std::endl; s_model_path = s_tmp_path; - cout << "MESSAGE model load path: " << s_model_path << endl; + std::cout << "MESSAGE model load path: " << s_model_path << std::endl; bChangeModule = true; g->set_rule(8); } else { - cout << "ERROR model not exists" << endl; + std::cout << "ERROR model not exists" << std::endl; } } } else - cout << "ERROR config file not exists" << endl; + std::cout << "ERROR config file not exists" << std::endl; } } } else if (1 == (value & 1)) { - if (s_model_path.find("standard") == string::npos) + if (s_model_path.find("standard") == std::string::npos) { if (std::filesystem::exists(s_config_file_path)) { - cout << "MESSAGE change model path!" << endl; + std::cout << "MESSAGE change model path!" << std::endl; toml_data = toml::parse(s_config_file_path); if (toml_data["model"].is_table()) { - string s_tmp_path = exe_path.string() + toml::find(toml_data["model"], "standard_model"); + std::string s_tmp_path = exe_path.string() + toml::find(toml_data["model"], "standard_model"); if (std::filesystem::exists(s_tmp_path)) { - cout << "MESSAGE model exists" << endl; + std::cout << "MESSAGE model exists" << std::endl; s_model_path = s_tmp_path; - cout << "MESSAGE model load path: " << s_model_path << endl; + std::cout << "MESSAGE model load path: " << s_model_path << std::endl; bChangeModule = true; g->set_rule(1); } else { - cout << "ERROR model not exists" << endl; + std::cout << "ERROR model not exists" << std::endl; } } } else - cout << "ERROR config file not exists" << endl; + std::cout << "ERROR config file not exists" << std::endl; } } else - cout << "ERROR unsupport rule: " << value << endl; + std::cout << "ERROR unsupport rule: " << value << std::endl; if (bChangeModule) { if (std::filesystem::exists(s_model_path)) { - cout << "MESSAGE model exists" << endl; - cout << "MESSAGE game rule: " << g->get_rule() << endl; + std::cout << "MESSAGE model exists" << std::endl; + std::cout << "MESSAGE game rule: " << g->get_rule() << std::endl; module = std::make_shared(s_model_path, NUM_MCT_SIMS); if (nullptr != m) { @@ -717,27 +715,27 @@ int main(int argc, char *argv[]) } else { - cout << "ERROR model not exists" << endl; + std::cout << "ERROR model not exists" << std::endl; continue; } } } else if (key == "folder") { - string t; - cin >> t; + std::string t; + std::cin >> t; } else { - cout << "ERROR unsupport key: " << key << endl; + std::cout << "ERROR unsupport key: " << key << std::endl; } } else if (command == "ABOUT") - cout << "name=\"Z2I\", version=\"0.2\", author=\"Joker2770\", country=\"CHN\"" << endl; + std::cout << "name=\"Z2I\", version=\"0.2\", author=\"Joker2770\", country=\"CHN\"" << std::endl; else if (command == "END") break; else - cout << "UNKNOWN unsupport command!" << endl; + std::cout << "UNKNOWN unsupport command!" << std::endl; } if (nullptr != m) diff --git a/src/play.cpp b/src/play.cpp index cac2365..6d0186e 100644 --- a/src/play.cpp +++ b/src/play.cpp @@ -33,8 +33,6 @@ SOFTWARE. #include #include -using namespace std; - SelfPlay::SelfPlay(NeuralNetwork *nn) : /* p_buffer(new p_buff_type()),*/ /* board_buffer(new board_buff_type()),*/ /* v_buffer(new v_buff_type()),*/ @@ -52,18 +50,18 @@ void SelfPlay::play(unsigned int saved_id) std::cout << "game rule: " << g->get_rule() << std::endl; // std::cout << "begin !!" << std::endl; int step = 0; - board_buff_type board_buffer(BUFFER_LEN, vector>(BOARD_SIZE, vector(BOARD_SIZE))); + board_buff_type board_buffer(BUFFER_LEN, std::vector>(BOARD_SIZE, std::vector(BOARD_SIZE))); v_buff_type v_buffer(BUFFER_LEN); - p_buff_type p_buffer(BUFFER_LEN, vector(BOARD_SIZE * BOARD_SIZE)); /* = new p_buff_type();*/ - vector col_buffer(BUFFER_LEN); - vector last_move_buffer(BUFFER_LEN); + p_buff_type p_buffer(BUFFER_LEN, std::vector(BOARD_SIZE * BOARD_SIZE)); /* = new p_buff_type();*/ + std::vector col_buffer(BUFFER_LEN); + std::vector last_move_buffer(BUFFER_LEN); // diri noise static std::gamma_distribution gamma(0.3f, 1.0f); static std::default_random_engine rng(static_cast(std::time(nullptr))); while (game_state.first == 0) { - // cout << "game id: " << saved_id << endl; + // std::cout << "game id: " << saved_id << std::endl; double temp = step < EXPLORE_STEP ? 1.0 : 1e-3; auto action_probs = mcts->get_action_probs(g.get(), temp); // auto action_probs = m->get_action_probs(g.get(), 1); @@ -92,7 +90,7 @@ void SelfPlay::play(unsigned int saved_id) { double noi = DIRI * gamma(rng); // if (is1){ - // cout << "noi = " << noi << endl; + // std::cout << "noi = " << noi << std::endl; // is1 = false; // } action_probs[i] += noi; @@ -121,13 +119,13 @@ void SelfPlay::play(unsigned int saved_id) g->render(); step++; } - cout << "Self play: total step num = " << step << " winner = " << game_state.second << endl; + std::cout << "Self play: total step num = " << step << " winner = " << game_state.second << std::endl; size_t hash_value = std::hash>{}(g); std::ostringstream oss; oss << hash_value; - ofstream bestand; - bestand.open("./data/data_" + to_string(saved_id) + "_" + oss.str(), ios::out | ios::binary); + std::ofstream bestand; + bestand.open("./data/data_" + std::to_string(saved_id) + "_" + oss.str(), std::ios::out | std::ios::binary); bestand.write(reinterpret_cast(&step), sizeof(int)); for (int i = 0; i < step; i++) @@ -159,11 +157,11 @@ void SelfPlay::play(unsigned int saved_id) // just validation // ifstream inlezen; // int new_step; - // inlezen.open("./data/data_"+str(id), ios::in | ios::binary); + // inlezen.open("./data/data_"+str(id), std::ios::in | std::ios::binary); // inlezen.read(reinterpret_cast(&new_step), sizeof(int)); - // board_buff_type new_board_buffer(new_step, vector>(BOARD_SIZE, vector(BOARD_SIZE))); - // p_buff_type new_p_buffer(new_step, vector(BOARD_SIZE * BOARD_SIZE)); + // board_buff_type new_board_buffer(new_step, std::vector>(BOARD_SIZE, std::vector(BOARD_SIZE))); + // p_buff_type new_p_buffer(new_step, std::vector(BOARD_SIZE * BOARD_SIZE)); // v_buff_type new_v_buffer(new_step); // for (int i = 0; i < step; i++) { @@ -192,8 +190,8 @@ void SelfPlay::self_play_for_train(unsigned int game_num, unsigned int start_bat { futures[i].wait(); - this->nn->set_batch_size(max((unsigned)1, (game_num - i) * NUM_MCT_THREADS)); - // cout << "end" << endl; + this->nn->set_batch_size(std::max((unsigned)1, (game_num - i) * NUM_MCT_THREADS)); + // std::cout << "end" << std::endl; } // return { *this->board_buffer , *this->p_buffer ,*this->v_buffer }; } @@ -209,7 +207,7 @@ void SelfPlay::self_play_for_train(unsigned int game_num, unsigned int start_bat // for (unsigned int i = 0; i < futures.size(); i++) { // futures[i].wait(); // -// this->nn->batch_size = max((unsigned)1, (game_num - i) * NUM_MCT_THREADS); +// this->nn->batch_size = std::max((unsigned)1, (game_num - i) * NUM_MCT_THREADS); // } // //return { *this->board_buffer , *this->p_buffer ,*this->v_buffer }; //} diff --git a/src/rule.h b/src/rule.h index 7270e39..031663a 100644 --- a/src/rule.h +++ b/src/rule.h @@ -8,7 +8,7 @@ /** MIT License -Copyright (c) 2023 Joker2770 +Copyright (c) 2023-2024 Joker2770 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -36,7 +36,6 @@ SOFTWARE. #include #include -using namespace std; class rule { diff --git a/src/train_and_eval/train_eval_net.cpp b/src/train_and_eval/train_eval_net.cpp index 4e24c6a..ca664c9 100644 --- a/src/train_and_eval/train_eval_net.cpp +++ b/src/train_and_eval/train_eval_net.cpp @@ -32,11 +32,9 @@ SOFTWARE. #include #include -using namespace std; - void generate_data_for_train(int current_weight, int start_batch_id) { - string path = "./weights/" + to_string(current_weight) + ".onnx"; + std::string path = "./weights/" + std::to_string(current_weight) + ".onnx"; std::shared_ptr model = std::make_shared(path, NUM_MCT_THREADS * NUM_MCT_SIMS); SelfPlay *sp = new SelfPlay(model.get()); @@ -68,23 +66,23 @@ void play_for_eval(NeuralNetwork *a, NeuralNetwork *b, bool a_first, int *win_ta game_state = g->get_game_status(); step++; } - cout << "eval: total step num = " << step << endl; + std::cout << "eval: total step num = " << step << std::endl; if ((game_state.second == BLACK && a_first) || (game_state.second == WHITE && !a_first)) { - cout << "winner = a" << endl; + std::cout << "winner = a" << std::endl; win_table[0]++; } else if ((game_state.second == BLACK && !a_first) || (game_state.second == WHITE && a_first)) { - cout << "winner = b" << endl; + std::cout << "winner = b" << std::endl; win_table[1]++; } else if (game_state.second == 0) win_table[2]++; } -vector eval(int weight_a, int weight_b, unsigned int game_num, unsigned int a_sims, unsigned int b_sims) +std::vector eval(int weight_a, int weight_b, unsigned int game_num, unsigned int a_sims, unsigned int b_sims) { int win_table[3] = {0, 0, 0}; std::unique_ptr thread_pool(new ThreadPool(game_num)); @@ -93,24 +91,24 @@ vector eval(int weight_a, int weight_b, unsigned int game_num, unsigned int if (weight_a >= 0) { - string path = "./weights/" + to_string(weight_a) + ".onnx"; + std::string path = "./weights/" + std::to_string(weight_a) + ".onnx"; nn_a = std::make_shared(path, game_num * a_sims); - cout << "NeuralNetwork A load: " << weight_a << endl; + std::cout << "NeuralNetwork A load: " << weight_a << std::endl; } else { - cout << "NeuralNetwork A applies random policy!" << endl; + std::cout << "NeuralNetwork A applies random policy!" << std::endl; } if (weight_b >= 0) { - string path = "./weights/" + to_string(weight_b) + ".onnx"; + std::string path = "./weights/" + std::to_string(weight_b) + ".onnx"; nn_b = std::make_shared(path, game_num * b_sims); - cout << "NeuralNetwork B load: " << weight_b << endl; + std::cout << "NeuralNetwork B load: " << weight_b << std::endl; } else { - cout << "NeuralNetwork B applies random policy!" << endl; + std::cout << "NeuralNetwork B applies random policy!" << std::endl; } std::vector> futures; @@ -125,14 +123,14 @@ vector eval(int weight_a, int weight_b, unsigned int game_num, unsigned int futures[i].wait(); if (nn_a != nullptr) { - nn_a->set_batch_size(max((unsigned)1, (game_num - i) * NUM_MCT_THREADS)); + nn_a->set_batch_size(std::max((unsigned)1, (game_num - i) * NUM_MCT_THREADS)); } if (nn_b != nullptr) { - nn_b->set_batch_size(max((unsigned)1, (game_num - i) * NUM_MCT_THREADS)); + nn_b->set_batch_size(std::max((unsigned)1, (game_num - i) * NUM_MCT_THREADS)); } } - // cout << "win_table = " << win_table[0] << win_table[1] << win_table [2] << endl; + // std::cout << "win_table = " << win_table[0] << win_table[1] << win_table [2] << std::endl; return {win_table[0], win_table[1], win_table[2]}; } @@ -141,43 +139,43 @@ int main(int argc, char *argv[]) { if (strcmp(argv[1], "prepare") == 0) { - cout << "Prepare for training." << endl; + std::cout << "Prepare for training." << std::endl; // system("mkdir weights"); #ifdef _WIN32 system("mkdir .\\weights"); system("mkdir .\\data"); #elif __linux__ auto ret = system("mkdir ./weights"); - // cout <> current_weight; // logger_reader >> best_weight; if (current_weight < 0) { - cout << "LOAD error,check current_and_best_weight.txt" << endl; + std::cout << "LOAD error,check current_and_best_weight.txt" << std::endl; return -1; } // logger_reader >> temp[1]; logger_reader.close(); - cout << "Generating... current_weight = " << current_weight << " start batch id: " << argv[2] << endl; + std::cout << "Generating... current_weight = " << current_weight << " start batch id: " << argv[2] << std::endl; generate_data_for_train(current_weight, atoi(argv[2]) * NUM_TRAIN_THREADS); } else if (strcmp(argv[1], "eval_with_winner") == 0) @@ -185,10 +183,10 @@ int main(int argc, char *argv[]) int current_weight; int best_weight; - ifstream weight_logger_reader("current_and_best_weight.txt"); + std::ifstream weight_logger_reader("current_and_best_weight.txt"); weight_logger_reader >> current_weight; weight_logger_reader >> best_weight; - cout << "Evaluating... current_weight = " << current_weight << " and best_weight = " << best_weight << endl; + std::cout << "Evaluating... current_weight = " << current_weight << " and best_weight = " << best_weight << std::endl; int game_num = atoi(argv[2]); @@ -197,28 +195,28 @@ int main(int argc, char *argv[]) #else auto result = eval(current_weight, best_weight, game_num, (unsigned int)(NUM_MCT_SIMS / 16 + 1), (unsigned int)(NUM_MCT_SIMS / 16 + 1)); #endif - string result_log_info = to_string(current_weight) + + std::string result_log_info = std::to_string(current_weight) + "-th weight win: " + - to_string(result[0]) + + std::to_string(result[0]) + " " + - to_string(best_weight) + + std::to_string(best_weight) + "-th weight win: " + - to_string(result[1]) + + std::to_string(result[1]) + " tie: " + - to_string(result[2]) + + std::to_string(result[2]) + "\n"; double win_ratio = result[0] / (result[1] + 0.01); if (win_ratio > 1.2) { - result_log_info += "new best weight: " + to_string(current_weight) + " generated!!!!\n"; - ofstream weight_logger_writer("current_and_best_weight.txt"); + result_log_info += "new best weight: " + std::to_string(current_weight) + " generated!!!!\n"; + std::ofstream weight_logger_writer("current_and_best_weight.txt"); weight_logger_writer << current_weight << " " << current_weight; weight_logger_writer.close(); } - cout << result_log_info; + std::cout << result_log_info; - ofstream detail_logger_writer("logger.txt", ios::app); + std::ofstream detail_logger_writer("logger.txt", std::ios::app); // detail_logger_writer << result_log_info << result_log_info2; detail_logger_writer << result_log_info; detail_logger_writer.close(); @@ -227,58 +225,58 @@ int main(int argc, char *argv[]) { int current_weight; - ifstream weight_logger_reader("current_and_best_weight.txt"); + std::ifstream weight_logger_reader("current_and_best_weight.txt"); weight_logger_reader >> current_weight; // weight_logger_reader >> best_weight; int game_num = atoi(argv[2]); unsigned int random_mcts_simulation; - ifstream random_mcts_logger_reader("random_mcts_number.txt"); + std::ifstream random_mcts_logger_reader("random_mcts_number.txt"); random_mcts_logger_reader >> random_mcts_simulation; unsigned int nn_mcts_simulation = NUM_MCT_SIMS / 16 + 1; // can not be too small !! - vector result_random_mcts = eval(current_weight, -1, game_num, nn_mcts_simulation, random_mcts_simulation); + std::vector result_random_mcts = eval(current_weight, -1, game_num, nn_mcts_simulation, random_mcts_simulation); - string result_log_info2 = to_string(current_weight) + + std::string result_log_info2 = std::to_string(current_weight) + "-th weight with mcts [" + - to_string(nn_mcts_simulation) + + std::to_string(nn_mcts_simulation) + "] win: " + - to_string(result_random_mcts[0]) + + std::to_string(result_random_mcts[0]) + " Random mcts [" + - to_string(random_mcts_simulation) + + std::to_string(random_mcts_simulation) + "] win: " + - to_string(result_random_mcts[1]) + + std::to_string(result_random_mcts[1]) + " tie: " + - to_string(result_random_mcts[2]) + + std::to_string(result_random_mcts[2]) + "\n"; if (result_random_mcts[0] == game_num) { if (random_mcts_simulation < 8000) { random_mcts_simulation += 100; - result_log_info2 += "add random mcts number to: " + to_string(random_mcts_simulation) + "\n"; - ofstream random_mcts_logger_writer("random_mcts_number.txt"); + result_log_info2 += "add random mcts number to: " + std::to_string(random_mcts_simulation) + "\n"; + std::ofstream random_mcts_logger_writer("random_mcts_number.txt"); random_mcts_logger_writer << random_mcts_simulation; random_mcts_logger_writer.close(); } /////////////// - result_log_info2 += "new best weight: " + to_string(current_weight) + " generated!!!!\n"; - ofstream weight_logger_writer("current_and_best_weight.txt"); + result_log_info2 += "new best weight: " + std::to_string(current_weight) + " generated!!!!\n"; + std::ofstream weight_logger_writer("current_and_best_weight.txt"); weight_logger_writer << current_weight << " " << current_weight; weight_logger_writer.close(); ////////////// } - cout << result_log_info2; + std::cout << result_log_info2; - ofstream detail_logger_writer("logger.txt", ios::app); + std::ofstream detail_logger_writer("logger.txt", std::ios::app); detail_logger_writer << result_log_info2; detail_logger_writer.close(); } else { - cout << "Do nothing...check your input!!" << endl; + std::cout << "Do nothing...check your input!!" << std::endl; } } diff --git a/test/get_best_action_from_prob_test.cpp b/test/get_best_action_from_prob_test.cpp index 7a67ca9..8027834 100644 --- a/test/get_best_action_from_prob_test.cpp +++ b/test/get_best_action_from_prob_test.cpp @@ -28,8 +28,6 @@ SOFTWARE. #include -using namespace std; - int main(int argc, char *argv[]) { Gomoku *g = new Gomoku(BOARD_SIZE, N_IN_ROW, BLACK); diff --git a/test/mcts_test.cpp b/test/mcts_test.cpp index c177127..693be14 100644 --- a/test/mcts_test.cpp +++ b/test/mcts_test.cpp @@ -2,7 +2,7 @@ MIT License Copyright (c) 2022 Augustusmyc -Copyright (c) 2023 Joker2770 +Copyright (c) 2023-2024 Joker2770 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -29,8 +29,6 @@ SOFTWARE. #include -using namespace std; - int main(int argc, char *argv[]) { auto g = std::make_shared(BOARD_SIZE, N_IN_ROW, BLACK); diff --git a/test/onnx_test.cpp b/test/onnx_test.cpp index 8176994..23699ca 100644 --- a/test/onnx_test.cpp +++ b/test/onnx_test.cpp @@ -2,7 +2,7 @@ MIT License Copyright (c) 2022 Augustusmyc -Copyright (c) 2023 Joker2770 +Copyright (c) 2023-2024 Joker2770 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -31,8 +31,6 @@ SOFTWARE. #include #include -using namespace std; - int main() { Gomoku gomoku(BOARD_SIZE, N_IN_ROW, BLACK); diff --git a/test/random_test.cpp b/test/random_test.cpp index 5c6f3f3..2216051 100644 --- a/test/random_test.cpp +++ b/test/random_test.cpp @@ -2,7 +2,7 @@ MIT License Copyright (c) 2022 Augustusmyc -Copyright (c) 2023 Joker2770 +Copyright (c) 2023-2024 Joker2770 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -26,8 +26,6 @@ SOFTWARE. #include #include -using namespace std; - int main() { std::vector rand_order; diff --git a/test/run_ort_trt.cpp b/test/run_ort_trt.cpp index 12e6ac5..f6fd580 100644 --- a/test/run_ort_trt.cpp +++ b/test/run_ort_trt.cpp @@ -28,7 +28,6 @@ SOFTWARE. #include #include #include -using namespace std; // #ifdef HAVE_TENSORRT_PROVIDER_FACTORY_H // #include // #include diff --git a/test/write_and_read_test.cpp b/test/write_and_read_test.cpp index 921182c..7e8e87d 100644 --- a/test/write_and_read_test.cpp +++ b/test/write_and_read_test.cpp @@ -2,7 +2,7 @@ MIT License Copyright (c) 2022 Augustusmyc -Copyright (c) 2023 Joker2770 +Copyright (c) 2023-2024 Joker2770 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -32,8 +32,6 @@ SOFTWARE. #include #include -using namespace std; - int main() { ofstream bestand;