From cc80e84dbea88fc8f9867c94b8daff5001e2d761 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Wed, 20 Jan 2021 01:22:17 +0800 Subject: [PATCH] perfect: Rename functions name --- src/perfect/cyclicArray.cpp | 4 +-- src/perfect/miniMax.h | 10 +++--- src/perfect/miniMax_alphaBetaAlgorithmn.cpp | 4 +-- src/perfect/miniMax_retroAnalysis.cpp | 6 ++-- src/perfect/randomAI.cpp | 16 ++++----- src/perfect/randomAI.h | 8 ++--- src/perfect/strLib.cpp | 30 ++++++++-------- src/perfect/strLib.h | 14 ++++---- src/perfect/threadManager.cpp | 38 ++++++++++----------- src/perfect/threadManager.h | 18 +++++----- 10 files changed, 74 insertions(+), 74 deletions(-) diff --git a/src/perfect/cyclicArray.cpp b/src/perfect/cyclicArray.cpp index c33c2892..beec76fb 100644 --- a/src/perfect/cyclicArray.cpp +++ b/src/perfect/cyclicArray.cpp @@ -36,8 +36,8 @@ CyclicArray::CyclicArray(unsigned int blockSizeInBytes, unsigned int numberOfBlo } //----------------------------------------------------------------------------- -// Name: ~randomAI() -// Desc: randomAI class destructor +// Name: ~RandomAI() +// Desc: RandomAI class destructor //----------------------------------------------------------------------------- CyclicArray::~CyclicArray() { diff --git a/src/perfect/miniMax.h b/src/perfect/miniMax.h index 6f601e81..b206f49a 100644 --- a/src/perfect/miniMax.h +++ b/src/perfect/miniMax.h @@ -455,7 +455,7 @@ private: }; }; - struct InitAlphaBetaVars : public threadManagerClass::threadVarsArrayItem, public AlphaBetaDefaultThreadVars + struct InitAlphaBetaVars : public ThreadManager::ThreadVarsArrayItem, public AlphaBetaDefaultThreadVars { BufferedFile *bufferedFile; bool initAlreadyDone; @@ -478,7 +478,7 @@ private: }; }; - struct RunAlphaBetaVars : public threadManagerClass::threadVarsArrayItem, public AlphaBetaDefaultThreadVars + struct RunAlphaBetaVars : public ThreadManager::ThreadVarsArrayItem, public AlphaBetaDefaultThreadVars { Node *branchArray = nullptr; // array of size [(depthOfFullTree - tilLevel) * maxNumBranches] for storage of the branches at each search depth unsigned int *freqValuesSubMovesBranchWon = nullptr; // ... @@ -565,7 +565,7 @@ private: }; }; - struct InitRetroAnalysisVars : public threadManagerClass::threadVarsArrayItem, public RetroAnalysisDefaultThreadVars + struct InitRetroAnalysisVars : public ThreadManager::ThreadVarsArrayItem, public RetroAnalysisDefaultThreadVars { BufferedFile *bufferedFile; bool initAlreadyDone; @@ -588,7 +588,7 @@ private: }; }; - struct AddNumSuccedorsVars : public threadManagerClass::threadVarsArrayItem, public RetroAnalysisDefaultThreadVars + struct AddNumSuccedorsVars : public ThreadManager::ThreadVarsArrayItem, public RetroAnalysisDefaultThreadVars { RetroAnalysisPredVars predVars[MAX_NUM_PREDECESSORS]; @@ -625,7 +625,7 @@ private: vector layersToCalculate; // used in calcLayer() and getCurrentCalculatedLayers() bool onlyPrepareLayer = false; // bool stopOnCriticalError = true; // if true then process will stay in while loop - threadManagerClass threadManager; // + ThreadManager threadManager; // CRITICAL_SECTION csDatabase; // CRITICAL_SECTION csOsPrint; // for thread safety when output is passed to osPrint void (*userPrintFunc)(void *) = nullptr; // called every time output is passed to osPrint diff --git a/src/perfect/miniMax_alphaBetaAlgorithmn.cpp b/src/perfect/miniMax_alphaBetaAlgorithmn.cpp index d88b61b2..ae3b82ee 100644 --- a/src/perfect/miniMax_alphaBetaAlgorithmn.cpp +++ b/src/perfect/miniMax_alphaBetaAlgorithmn.cpp @@ -111,7 +111,7 @@ bool MiniMax::initAlphaBeta(AlphaBetaGlobalVars &alphaBetaVars) alphaBetaVars.statsValueCounter[SKV_VALUE_GAME_LOST] = 0; alphaBetaVars.statsValueCounter[SKV_VALUE_GAME_DRAWN] = 0; alphaBetaVars.statsValueCounter[SKV_VALUE_INVALID] = 0; - threadManagerClass::threadVarsArray tva(threadManager.getNumThreads(), InitAlphaBetaVars(this, &alphaBetaVars, alphaBetaVars.layerNumber, invalidArray, initAlreadyDone)); + ThreadManager::ThreadVarsArray tva(threadManager.getNumThreads(), InitAlphaBetaVars(this, &alphaBetaVars, alphaBetaVars.layerNumber, invalidArray, initAlreadyDone)); // process each state in the current layer switch (threadManager.executeParallelLoop(initAlphaBetaThreadProc, tva.getPointerToArray(), tva.getSizeOfArray(), TM_SCHEDULE_STATIC, 0, layerStats[alphaBetaVars.layerNumber].knotsInLayer - 1, 1)) { @@ -228,7 +228,7 @@ bool MiniMax::runAlphaBeta(AlphaBetaGlobalVars &alphaBetaVars) alphaBetaVars.statsValueCounter[SKV_VALUE_GAME_LOST] = 0; alphaBetaVars.statsValueCounter[SKV_VALUE_GAME_DRAWN] = 0; alphaBetaVars.statsValueCounter[SKV_VALUE_INVALID] = 0; - threadManagerClass::threadVarsArray tva(threadManager.getNumThreads(), RunAlphaBetaVars(this, &alphaBetaVars, alphaBetaVars.layerNumber)); + ThreadManager::ThreadVarsArray tva(threadManager.getNumThreads(), RunAlphaBetaVars(this, &alphaBetaVars, alphaBetaVars.layerNumber)); // so far no multi-threadin implemented threadManager.setNumThreads(1); diff --git a/src/perfect/miniMax_retroAnalysis.cpp b/src/perfect/miniMax_retroAnalysis.cpp index 899f8168..230c17c7 100644 --- a/src/perfect/miniMax_retroAnalysis.cpp +++ b/src/perfect/miniMax_retroAnalysis.cpp @@ -145,7 +145,7 @@ bool MiniMax::initRetroAnalysis(retroAnalysisGlobalVars &retroVars) retroVars.statsValueCounter[SKV_VALUE_GAME_LOST] = 0; retroVars.statsValueCounter[SKV_VALUE_GAME_DRAWN] = 0; retroVars.statsValueCounter[SKV_VALUE_INVALID] = 0; - threadManagerClass::threadVarsArray tva(threadManager.getNumThreads(), InitRetroAnalysisVars(this, &retroVars, layerNumber, initArray, initAlreadyDone)); + ThreadManager::ThreadVarsArray tva(threadManager.getNumThreads(), InitRetroAnalysisVars(this, &retroVars, layerNumber, initArray, initAlreadyDone)); // process each state in the current layer switch (threadManager.executeParallelLoop(initRetroAnalysisThreadProc, tva.getPointerToArray(), tva.getSizeOfArray(), TM_SCHEDULE_STATIC, 0, layerStats[layerNumber].knotsInLayer - 1, 1)) { @@ -360,7 +360,7 @@ bool MiniMax::calcNumSuccedors(retroAnalysisGlobalVars &retroVars) // prepare parameters for multithreading succCalculated[layerNumber] = true; numStatesProcessed = 0; - threadManagerClass::threadVarsArray tva(threadManager.getNumThreads(), AddNumSuccedorsVars(this, &retroVars, layerNumber)); + ThreadManager::ThreadVarsArray tva(threadManager.getNumThreads(), AddNumSuccedorsVars(this, &retroVars, layerNumber)); // process each state in the current layer switch (threadManager.executeParallelLoop(addNumSuccedorsThreadProc, tva.getPointerToArray(), tva.getSizeOfArray(), TM_SCHEDULE_STATIC, 0, layerStats[layerNumber].knotsInLayer - 1, 1)) { @@ -402,7 +402,7 @@ bool MiniMax::calcNumSuccedors(retroAnalysisGlobalVars &retroVars) // prepare parameters for multithreading numStatesProcessed = 0; - threadManagerClass::threadVarsArray tva(threadManager.getNumThreads(), AddNumSuccedorsVars(this, &retroVars, succState.layerNumber)); + ThreadManager::ThreadVarsArray tva(threadManager.getNumThreads(), AddNumSuccedorsVars(this, &retroVars, succState.layerNumber)); // process each state in the current layer switch (threadManager.executeParallelLoop(addNumSuccedorsThreadProc, tva.getPointerToArray(), tva.getSizeOfArray(), TM_SCHEDULE_STATIC, 0, layerStats[succState.layerNumber].knotsInLayer - 1, 1)) { diff --git a/src/perfect/randomAI.cpp b/src/perfect/randomAI.cpp index 3d4e3b32..b535f752 100644 --- a/src/perfect/randomAI.cpp +++ b/src/perfect/randomAI.cpp @@ -1,5 +1,5 @@ /********************************************************************* - randomAI.cpp + RandomAI.cpp Copyright (c) Thomas Weber. All rights reserved. Copyright (C) 2021 The Sanmill developers (see AUTHORS file) Licensed under the MIT License. @@ -9,20 +9,20 @@ #include "randomAI.h" //----------------------------------------------------------------------------- -// Name: randomAI() -// Desc: randomAI class constructor +// Name: RandomAI() +// Desc: RandomAI class constructor //----------------------------------------------------------------------------- -randomAI::randomAI() +RandomAI::RandomAI() { // Init srand((unsigned)time(nullptr)); } //----------------------------------------------------------------------------- -// Name: ~randomAI() -// Desc: randomAI class destructor +// Name: ~RandomAI() +// Desc: RandomAI class destructor //----------------------------------------------------------------------------- -randomAI::~randomAI() +RandomAI::~RandomAI() { // Locals @@ -32,7 +32,7 @@ randomAI::~randomAI() // Name: play() // Desc: //----------------------------------------------------------------------------- -void randomAI::play(fieldStruct *theField, unsigned int *pushFrom, unsigned int *pushTo) +void RandomAI::play(fieldStruct *theField, unsigned int *pushFrom, unsigned int *pushTo) { // locals unsigned int from, to, direction; diff --git a/src/perfect/randomAI.h b/src/perfect/randomAI.h index fdf42588..82e04d20 100644 --- a/src/perfect/randomAI.h +++ b/src/perfect/randomAI.h @@ -1,5 +1,5 @@ /*********************************************************************\ - randomAI.h + RandomAI.h Copyright (c) Thomas Weber. All rights reserved. Copyright (C) 2021 The Sanmill developers (see AUTHORS file) Licensed under the MIT License. @@ -15,12 +15,12 @@ /*** Klassen *********************************************************/ -class randomAI : public MillAI +class RandomAI : public MillAI { public: // Constructor / destructor - randomAI(); - ~randomAI(); + RandomAI(); + ~RandomAI(); // Functions void play(fieldStruct *theField, unsigned int *pushFrom, unsigned int *pushTo); diff --git a/src/perfect/strLib.cpp b/src/perfect/strLib.cpp index 097a10aa..33ba0f6c 100644 --- a/src/perfect/strLib.cpp +++ b/src/perfect/strLib.cpp @@ -12,7 +12,7 @@ // Name: hibit() // Desc: //----------------------------------------------------------------------------- -int mystring::hibit(unsigned int n) +int MyString::hibit(unsigned int n) { n |= (n >> 1); n |= (n >> 2); @@ -23,36 +23,36 @@ int mystring::hibit(unsigned int n) } //----------------------------------------------------------------------------- -// Name: mystring() +// Name: MyString() // Desc: //----------------------------------------------------------------------------- -mystring::mystring() +MyString::MyString() { } //----------------------------------------------------------------------------- -// Name: mystring() +// Name: MyString() // Desc: //----------------------------------------------------------------------------- -mystring::mystring(const char *cStr) +MyString::MyString(const char *cStr) { assign(cStr); } //----------------------------------------------------------------------------- -// Name: mystring() +// Name: MyString() // Desc: //----------------------------------------------------------------------------- -mystring::mystring(const WCHAR *cStr) +MyString::MyString(const WCHAR *cStr) { assign(cStr); } //----------------------------------------------------------------------------- -// Name: mystring() +// Name: MyString() // Desc: //----------------------------------------------------------------------------- -mystring::~mystring() +MyString::~MyString() { if (strA != nullptr) { delete[] strA; strA = nullptr; @@ -70,7 +70,7 @@ mystring::~mystring() // Name: c_strA() // Desc: //----------------------------------------------------------------------------- -const char *mystring::c_strA() +const char *MyString::c_strA() { return strA; } @@ -79,7 +79,7 @@ const char *mystring::c_strA() // Name: c_strW() // Desc: //----------------------------------------------------------------------------- -const WCHAR *mystring::c_strW() +const WCHAR *MyString::c_strW() { return strW; } @@ -88,14 +88,14 @@ const WCHAR *mystring::c_strW() // Name: assign() // Desc: //----------------------------------------------------------------------------- -mystring &mystring::assign(const char *cStr) +MyString &MyString::assign(const char *cStr) { // locals size_t convertedChars = 0; size_t newLength = strlen(cStr); size_t newReserved = (size_t)hibit((unsigned int)newLength) * 2; - if (reserved < newReserved) this->~mystring(); + if (reserved < newReserved) this->~MyString(); if (strA == nullptr) strA = new char[newReserved]; if (strW == nullptr) strW = new WCHAR[newReserved]; @@ -112,14 +112,14 @@ mystring &mystring::assign(const char *cStr) // Name: assign() // Desc: //----------------------------------------------------------------------------- -mystring &mystring::assign(const WCHAR *cStr) +MyString &MyString::assign(const WCHAR *cStr) { // locals size_t returnValue; size_t newLength = wcslen(cStr); size_t newReserved = (size_t)hibit((unsigned int)newLength) * 2; - if (reserved < newReserved) this->~mystring(); + if (reserved < newReserved) this->~MyString(); if (strA == nullptr) strA = new char[newReserved]; if (strW == nullptr) strW = new WCHAR[newReserved]; diff --git a/src/perfect/strLib.h b/src/perfect/strLib.h index 67589f67..1428d3b5 100644 --- a/src/perfect/strLib.h +++ b/src/perfect/strLib.h @@ -21,7 +21,7 @@ using namespace std; // general functions bool readAsciiData(HANDLE hFile, double *pData, unsigned int numValues, unsigned char decimalSeperator, unsigned char columnSeparator); -class mystring +class MyString { private: @@ -36,15 +36,15 @@ private: public: // functions - mystring(); - mystring(const char *cStr); - mystring(const WCHAR *cStr); - ~mystring(); + MyString(); + MyString(const char *cStr); + MyString(const WCHAR *cStr); + ~MyString(); const char *c_strA(); const WCHAR *c_strW(); - mystring &assign(const char *cStr); - mystring &assign(const WCHAR *cStr); + MyString &assign(const char *cStr); + MyString &assign(const WCHAR *cStr); static int hibit(unsigned int n); }; diff --git a/src/perfect/threadManager.cpp b/src/perfect/threadManager.cpp index 05b600cd..9e48e602 100644 --- a/src/perfect/threadManager.cpp +++ b/src/perfect/threadManager.cpp @@ -9,10 +9,10 @@ #include "threadManager.h" //----------------------------------------------------------------------------- -// Name: threadManagerClass() -// Desc: threadManagerClass class constructor +// Name: ThreadManager() +// Desc: ThreadManager class constructor //----------------------------------------------------------------------------- -threadManagerClass::threadManagerClass() +ThreadManager::ThreadManager() { // locals unsigned int curThreadNo; @@ -40,10 +40,10 @@ threadManagerClass::threadManagerClass() } //----------------------------------------------------------------------------- -// Name: ~threadManagerClass() -// Desc: threadManagerClass class destructor +// Name: ~ThreadManager() +// Desc: ThreadManager class destructor //----------------------------------------------------------------------------- -threadManagerClass::~threadManagerClass() +ThreadManager::~ThreadManager() { // locals unsigned int curThreadNo; @@ -64,7 +64,7 @@ threadManagerClass::~threadManagerClass() // Name: waitForOtherThreads() // Desc: //----------------------------------------------------------------------------- -void threadManagerClass::waitForOtherThreads(unsigned int threadNo) +void ThreadManager::waitForOtherThreads(unsigned int threadNo) { // wait if other threads are still waiting at the barrier //cout << endl << "thread=" << threadNo << ", numThreadsPassedBarrier= " << numThreadsPassedBarrier << ": " << "while (numThreadsPassedBarrier>0)"; @@ -108,7 +108,7 @@ void threadManagerClass::waitForOtherThreads(unsigned int threadNo) // Name: getNumThreads() // Desc: //----------------------------------------------------------------------------- -unsigned int threadManagerClass::getNumThreads() +unsigned int ThreadManager::getNumThreads() { return numThreads; } @@ -117,7 +117,7 @@ unsigned int threadManagerClass::getNumThreads() // Name: setNumThreads() // Desc: //----------------------------------------------------------------------------- -bool threadManagerClass::setNumThreads(unsigned int newNumThreads) +bool ThreadManager::setNumThreads(unsigned int newNumThreads) { // cancel if any thread running EnterCriticalSection(&csBarrier); @@ -139,7 +139,7 @@ bool threadManagerClass::setNumThreads(unsigned int newNumThreads) // Name: pauseExecution() // Desc: //----------------------------------------------------------------------------- -void threadManagerClass::pauseExecution() +void ThreadManager::pauseExecution() { for (unsigned int curThread = 0; curThread < numThreads; curThread++) { @@ -159,7 +159,7 @@ void threadManagerClass::pauseExecution() // Desc: Stops executeParallelLoop() before the next iteration. // When executeInParallel() was called, user has to handle cancellation by himself. //----------------------------------------------------------------------------- -void threadManagerClass::cancelExecution() +void ThreadManager::cancelExecution() { termineAllThreads = true; executionCancelled = true; @@ -172,7 +172,7 @@ void threadManagerClass::cancelExecution() // Name: uncancelExecution() // Desc: //----------------------------------------------------------------------------- -void threadManagerClass::uncancelExecution() +void ThreadManager::uncancelExecution() { executionCancelled = false; } @@ -181,7 +181,7 @@ void threadManagerClass::uncancelExecution() // Name: wasExecutionCancelled() // Desc: //----------------------------------------------------------------------------- -bool threadManagerClass::wasExecutionCancelled() +bool ThreadManager::wasExecutionCancelled() { return executionCancelled; } @@ -190,7 +190,7 @@ bool threadManagerClass::wasExecutionCancelled() // Name: getThreadId() // Desc: Returns a number from 0 to 'numThreads'-1. Returns 0 if the function fails. //----------------------------------------------------------------------------- -unsigned int threadManagerClass::getThreadNumber() +unsigned int ThreadManager::getThreadNumber() { // locals DWORD curThreadId = GetCurrentThreadId(); @@ -208,7 +208,7 @@ unsigned int threadManagerClass::getThreadNumber() // Name: executeInParallel() // Desc: lpParameter is an array of size numThreads. //----------------------------------------------------------------------------- -unsigned int threadManagerClass::executeInParallel(DWORD threadProc(void *pParameter), void *pParameter, unsigned int parameterStructSize) +unsigned int ThreadManager::executeInParallel(DWORD threadProc(void *pParameter), void *pParameter, unsigned int parameterStructSize) { // locals unsigned int curThreadNo; @@ -264,7 +264,7 @@ unsigned int threadManagerClass::executeInParallel(DWORD threadProc(void *pPara // lpParameter - an array of size numThreads // finalValue - this value is part of the iteration, meaning that index ranges from initialValue to finalValue including both border values //----------------------------------------------------------------------------- -unsigned int threadManagerClass::executeParallelLoop(DWORD threadProc(void *pParameter, int index), +unsigned int ThreadManager::executeParallelLoop(DWORD threadProc(void *pParameter, int index), void *pParameter, unsigned int parameterStructSize, unsigned int scheduleType, @@ -284,7 +284,7 @@ unsigned int threadManagerClass::executeParallelLoop(DWORD threadProc(void *p int numIterations = (finalValue - initialValue) / inkrement + 1; // total number of iterations int chunkSize = 0; // number of iterations per chunk SIZE_T dwStackSize = 0; // initital stack size of each thread. 0 means default size ~1MB - forLoopStruct *forLoopParameters = new forLoopStruct[numThreads]; // + ForLoop *forLoopParameters = new ForLoop[numThreads]; // // globals termineAllThreads = false; @@ -361,10 +361,10 @@ unsigned int threadManagerClass::executeParallelLoop(DWORD threadProc(void *p // Name: threadForLoop() // Desc: //----------------------------------------------------------------------------- -DWORD WINAPI threadManagerClass::threadForLoop(LPVOID lpParameter) +DWORD WINAPI ThreadManager::threadForLoop(LPVOID lpParameter) { // locals - forLoopStruct *forLoopParameters = (forLoopStruct *)lpParameter; + ForLoop *forLoopParameters = (ForLoop *)lpParameter; int index; switch (forLoopParameters->scheduleType) { diff --git a/src/perfect/threadManager.h b/src/perfect/threadManager.h index 0a3ba019..5b317577 100644 --- a/src/perfect/threadManager.h +++ b/src/perfect/threadManager.h @@ -36,12 +36,12 @@ using namespace std; // use standard library namespace /*** Klassen *********************************************************/ -class threadManagerClass +class ThreadManager { private: // structures - struct forLoopStruct + struct ForLoop { unsigned int scheduleType; int inkrement; @@ -49,7 +49,7 @@ private: int finalValue; void *pParameter; DWORD(*threadProc)(void *pParameter, int index); // pointer to the user function to be executed by the threads - threadManagerClass *threadManager; + ThreadManager *threadManager; }; // Variables @@ -71,7 +71,7 @@ private: public: - class threadVarsArrayItem + class ThreadVarsArrayItem { public: unsigned int curThreadNo; @@ -87,13 +87,13 @@ public: }; }; - template class threadVarsArray + template class ThreadVarsArray { public: unsigned int numberOfThreads; varType *item; - threadVarsArray(unsigned int numberOfThreads, varType &master) + ThreadVarsArray(unsigned int numberOfThreads, varType &master) { this->numberOfThreads = numberOfThreads; this->item = new varType[numberOfThreads]; @@ -105,7 +105,7 @@ public: } }; - ~threadVarsArray() + ~ThreadVarsArray() { for (unsigned int threadCounter = 0; threadCounter < numberOfThreads; threadCounter++) { item[threadCounter].destroyElement(); @@ -132,8 +132,8 @@ public: }; // Constructor / destructor - threadManagerClass(); - ~threadManagerClass(); + ThreadManager(); + ~ThreadManager(); // Functions unsigned int getThreadNumber();