perfect: perfectAI rename

This commit is contained in:
Calcitem 2021-01-20 01:19:35 +08:00
parent 53916f9aba
commit 4761897750
3 changed files with 98 additions and 98 deletions

View File

@ -27,7 +27,7 @@ int main(void)
char ch[100]; char ch[100];
unsigned int pushFrom, pushTo; unsigned int pushFrom, pushTo;
Position *myGame = new Position(); Position *myGame = new Position();
perfectAI *myAI = new perfectAI(databaseDirectory); PerfectAI *myAI = new PerfectAI(databaseDirectory);
SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS); SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
srand(GetTickCount()); srand(GetTickCount());

View File

@ -1,5 +1,5 @@
/********************************************************************* /*********************************************************************
perfectAI.cpp PerfectAI.cpp
Copyright (c) Thomas Weber. All rights reserved. Copyright (c) Thomas Weber. All rights reserved.
Copyright (C) 2021 The Sanmill developers (see AUTHORS file) Copyright (C) 2021 The Sanmill developers (see AUTHORS file)
Licensed under the MIT License. Licensed under the MIT License.
@ -183,10 +183,10 @@ unsigned int fieldPosIsOfGroup[] = { GROUP_C, GROUP_D,
GROUP_C, GROUP_D, GROUP_C }; GROUP_C, GROUP_D, GROUP_C };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Name: perfectAI() // Name: PerfectAI()
// Desc: perfectAI class constructor // Desc: PerfectAI class constructor
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
perfectAI::perfectAI(const char *directory) PerfectAI::PerfectAI(const char *directory)
{ {
// loacls // loacls
unsigned int i, a, b, c, totalNumStones; unsigned int i, a, b, c, totalNumStones;
@ -199,10 +199,10 @@ perfectAI::perfectAI(const char *directory)
DWORD dwBytesWritten = 0; DWORD dwBytesWritten = 0;
HANDLE hFilePreCalcVars; HANDLE hFilePreCalcVars;
stringstream ssPreCalcVarsFilePath; stringstream ssPreCalcVarsFilePath;
preCalcedVarsFileHeaderStruct preCalcVarsHeader; PreCalcedVarsFileHeader preCalcVarsHeader;
// //
threadVars = new threadVarsStruct[getNumThreads()]; threadVars = new ThreadVars[getNumThreads()];
for (unsigned int curThread = 0; curThread < getNumThreads(); curThread++) { for (unsigned int curThread = 0; curThread < getNumThreads(); curThread++) {
threadVars[curThread].parent = this; threadVars[curThread].parent = this;
threadVars[curThread].field = &dummyField; threadVars[curThread].field = &dummyField;
@ -216,13 +216,13 @@ perfectAI::perfectAI(const char *directory)
ssPreCalcVarsFilePath << directory << "\\"; ssPreCalcVarsFilePath << directory << "\\";
} ssPreCalcVarsFilePath << "preCalculatedVars.dat"; } ssPreCalcVarsFilePath << "preCalculatedVars.dat";
hFilePreCalcVars = CreateFileA(ssPreCalcVarsFilePath.str().c_str(), GENERIC_READ /*| GENERIC_WRITE*/, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); hFilePreCalcVars = CreateFileA(ssPreCalcVarsFilePath.str().c_str(), GENERIC_READ /*| GENERIC_WRITE*/, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
ReadFile(hFilePreCalcVars, &preCalcVarsHeader, sizeof(preCalcedVarsFileHeaderStruct), &dwBytesRead, nullptr); ReadFile(hFilePreCalcVars, &preCalcVarsHeader, sizeof(PreCalcedVarsFileHeader), &dwBytesRead, nullptr);
// vars already stored in file? // vars already stored in file?
if (dwBytesRead) { if (dwBytesRead) {
// Read from file // Read from file
ReadFile(hFilePreCalcVars, layer, sizeof(layerStruct) * NUM_LAYERS, &dwBytesRead, nullptr); ReadFile(hFilePreCalcVars, layer, sizeof(Layer) * NUM_LAYERS, &dwBytesRead, nullptr);
ReadFile(hFilePreCalcVars, layerIndex, sizeof(unsigned int) * 2 * NUM_STONES_PER_PLAYER_PLUS_ONE * NUM_STONES_PER_PLAYER_PLUS_ONE, &dwBytesRead, nullptr); ReadFile(hFilePreCalcVars, layerIndex, sizeof(unsigned int) * 2 * NUM_STONES_PER_PLAYER_PLUS_ONE * NUM_STONES_PER_PLAYER_PLUS_ONE, &dwBytesRead, nullptr);
ReadFile(hFilePreCalcVars, anzahlStellungenAB, sizeof(unsigned int) * NUM_STONES_PER_PLAYER_PLUS_ONE * NUM_STONES_PER_PLAYER_PLUS_ONE, &dwBytesRead, nullptr); ReadFile(hFilePreCalcVars, anzahlStellungenAB, sizeof(unsigned int) * NUM_STONES_PER_PLAYER_PLUS_ONE * NUM_STONES_PER_PLAYER_PLUS_ONE, &dwBytesRead, nullptr);
ReadFile(hFilePreCalcVars, anzahlStellungenCD, sizeof(unsigned int) * NUM_STONES_PER_PLAYER_PLUS_ONE * NUM_STONES_PER_PLAYER_PLUS_ONE, &dwBytesRead, nullptr); ReadFile(hFilePreCalcVars, anzahlStellungenCD, sizeof(unsigned int) * NUM_STONES_PER_PLAYER_PLUS_ONE * NUM_STONES_PER_PLAYER_PLUS_ONE, &dwBytesRead, nullptr);
@ -585,10 +585,10 @@ perfectAI::perfectAI(const char *directory)
} }
// write vars into file // write vars into file
preCalcVarsHeader.sizeInBytes = sizeof(preCalcedVarsFileHeaderStruct); preCalcVarsHeader.sizeInBytes = sizeof(PreCalcedVarsFileHeader);
WriteFile(hFilePreCalcVars, &preCalcVarsHeader, preCalcVarsHeader.sizeInBytes, &dwBytesWritten, nullptr); WriteFile(hFilePreCalcVars, &preCalcVarsHeader, preCalcVarsHeader.sizeInBytes, &dwBytesWritten, nullptr);
WriteFile(hFilePreCalcVars, layer, sizeof(layerStruct) * NUM_LAYERS, &dwBytesWritten, nullptr); WriteFile(hFilePreCalcVars, layer, sizeof(Layer) * NUM_LAYERS, &dwBytesWritten, nullptr);
WriteFile(hFilePreCalcVars, layerIndex, sizeof(unsigned int) * 2 * NUM_STONES_PER_PLAYER_PLUS_ONE * NUM_STONES_PER_PLAYER_PLUS_ONE, &dwBytesWritten, nullptr); WriteFile(hFilePreCalcVars, layerIndex, sizeof(unsigned int) * 2 * NUM_STONES_PER_PLAYER_PLUS_ONE * NUM_STONES_PER_PLAYER_PLUS_ONE, &dwBytesWritten, nullptr);
WriteFile(hFilePreCalcVars, anzahlStellungenAB, sizeof(unsigned int) * NUM_STONES_PER_PLAYER_PLUS_ONE * NUM_STONES_PER_PLAYER_PLUS_ONE, &dwBytesWritten, nullptr); WriteFile(hFilePreCalcVars, anzahlStellungenAB, sizeof(unsigned int) * NUM_STONES_PER_PLAYER_PLUS_ONE * NUM_STONES_PER_PLAYER_PLUS_ONE, &dwBytesWritten, nullptr);
WriteFile(hFilePreCalcVars, anzahlStellungenCD, sizeof(unsigned int) * NUM_STONES_PER_PLAYER_PLUS_ONE * NUM_STONES_PER_PLAYER_PLUS_ONE, &dwBytesWritten, nullptr); WriteFile(hFilePreCalcVars, anzahlStellungenCD, sizeof(unsigned int) * NUM_STONES_PER_PLAYER_PLUS_ONE * NUM_STONES_PER_PLAYER_PLUS_ONE, &dwBytesWritten, nullptr);
@ -626,10 +626,10 @@ perfectAI::perfectAI(const char *directory)
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Name: ~perfectAI() // Name: ~PerfectAI()
// Desc: perfectAI class destructor // Desc: PerfectAI class destructor
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
perfectAI::~perfectAI() PerfectAI::~PerfectAI()
{ {
// locals // locals
unsigned int curThread; unsigned int curThread;
@ -648,7 +648,7 @@ perfectAI::~perfectAI()
// Name: play() // Name: play()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::play(fieldStruct *theField, unsigned int *pushFrom, unsigned int *pushTo) void PerfectAI::play(fieldStruct *theField, unsigned int *pushFrom, unsigned int *pushTo)
{ {
// ... trick 17 // ... trick 17
theField->copyField(&dummyField); theField->copyField(&dummyField);
@ -676,10 +676,10 @@ void perfectAI::play(fieldStruct *theField, unsigned int *pushFrom, unsigned int
// current state already calculated? // current state already calculated?
if (isCurrentStateInDatabase(0)) { if (isCurrentStateInDatabase(0)) {
cout << "perfectAI is using database!\n\n\n"; cout << "PerfectAI is using database!\n\n\n";
threadVars[0].depthOfFullTree = 3; threadVars[0].depthOfFullTree = 3;
} else { } else {
cout << "perfectAI is thinking thinking with a depth of " << threadVars[0].depthOfFullTree << " steps!\n\n\n"; cout << "PerfectAI is thinking thinking with a depth of " << threadVars[0].depthOfFullTree << " steps!\n\n\n";
} }
// start the miniMax-algorithmn // start the miniMax-algorithmn
@ -703,7 +703,7 @@ void perfectAI::play(fieldStruct *theField, unsigned int *pushFrom, unsigned int
// Name: prepareDatabaseCalculation() // Name: prepareDatabaseCalculation()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::prepareDatabaseCalculation() void PerfectAI::prepareDatabaseCalculation()
{ {
// only prepare layers? // only prepare layers?
unsigned int curThread; unsigned int curThread;
@ -723,7 +723,7 @@ void perfectAI::prepareDatabaseCalculation()
// Name: wrapUpDatabaseCalculation() // Name: wrapUpDatabaseCalculation()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::wrapUpDatabaseCalculation(bool calculationAborted) void PerfectAI::wrapUpDatabaseCalculation(bool calculationAborted)
{ {
// locals // locals
unsigned int curThread; unsigned int curThread;
@ -740,7 +740,7 @@ void perfectAI::wrapUpDatabaseCalculation(bool calculationAborted)
// Name: testLayers() // Name: testLayers()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool perfectAI::testLayers(unsigned int startTestFromLayer, unsigned int endTestAtLayer) bool PerfectAI::testLayers(unsigned int startTestFromLayer, unsigned int endTestAtLayer)
{ {
// locals // locals
unsigned int curLayer; unsigned int curLayer;
@ -762,7 +762,7 @@ bool perfectAI::testLayers(unsigned int startTestFromLayer, unsigned int endTest
// Name: setDatabasePath() // Name: setDatabasePath()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool perfectAI::setDatabasePath(const char *directory) bool PerfectAI::setDatabasePath(const char *directory)
{ {
if (directory == nullptr) { if (directory == nullptr) {
return false; return false;
@ -777,7 +777,7 @@ bool perfectAI::setDatabasePath(const char *directory)
// Name: prepareBestChoiceCalculation() // Name: prepareBestChoiceCalculation()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::prepareBestChoiceCalculation() void PerfectAI::prepareBestChoiceCalculation()
{ {
for (unsigned int curThread = 0; curThread < getNumThreads(); curThread++) { for (unsigned int curThread = 0; curThread < getNumThreads(); curThread++) {
threadVars[curThread].floatValue = 0.0f; threadVars[curThread].floatValue = 0.0f;
@ -788,10 +788,10 @@ void perfectAI::prepareBestChoiceCalculation()
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Name: threadVarsStruct() // Name: ThreadVars()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
perfectAI::threadVarsStruct::threadVarsStruct() PerfectAI::ThreadVars::ThreadVars()
{ {
field = nullptr; field = nullptr;
floatValue = 0; floatValue = 0;
@ -811,7 +811,7 @@ perfectAI::threadVarsStruct::threadVarsStruct()
// Name: getPossSettingPhase() // Name: getPossSettingPhase()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
unsigned int *perfectAI::threadVarsStruct::getPossSettingPhase(unsigned int *numPossibilities, void **pPossibilities) unsigned int *PerfectAI::ThreadVars::getPossSettingPhase(unsigned int *numPossibilities, void **pPossibilities)
{ {
// locals // locals
unsigned int i; unsigned int i;
@ -858,7 +858,7 @@ unsigned int *perfectAI::threadVarsStruct::getPossSettingPhase(unsigned int *num
// Name: getPossNormalMove() // Name: getPossNormalMove()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
unsigned int *perfectAI::threadVarsStruct::getPossNormalMove(unsigned int *numPossibilities, void **pPossibilities) unsigned int *PerfectAI::ThreadVars::getPossNormalMove(unsigned int *numPossibilities, void **pPossibilities)
{ {
// locals // locals
unsigned int from, to, dir; unsigned int from, to, dir;
@ -917,7 +917,7 @@ unsigned int *perfectAI::threadVarsStruct::getPossNormalMove(unsigned int *numPo
// Name: getPossStoneRemove() // Name: getPossStoneRemove()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
unsigned int *perfectAI::threadVarsStruct::getPossStoneRemove(unsigned int *numPossibilities, void **pPossibilities) unsigned int *PerfectAI::ThreadVars::getPossStoneRemove(unsigned int *numPossibilities, void **pPossibilities)
{ {
// locals // locals
unsigned int i; unsigned int i;
@ -944,7 +944,7 @@ unsigned int *perfectAI::threadVarsStruct::getPossStoneRemove(unsigned int *numP
// Name: getPossibilities() // Name: getPossibilities()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
unsigned int *perfectAI::getPossibilities(unsigned int threadNo, unsigned int *numPossibilities, bool *opponentsMove, void **pPossibilities) unsigned int *PerfectAI::getPossibilities(unsigned int threadNo, unsigned int *numPossibilities, bool *opponentsMove, void **pPossibilities)
{ {
// locals // locals
bool aStoneCanBeRemovedFromCurPlayer = 0; bool aStoneCanBeRemovedFromCurPlayer = 0;
@ -953,7 +953,7 @@ unsigned int *perfectAI::getPossibilities(unsigned int threadNo, unsigned int *n
unsigned int i; unsigned int i;
// set opponentsMove // set opponentsMove
threadVarsStruct *tv = &threadVars[threadNo]; ThreadVars *tv = &threadVars[threadNo];
*opponentsMove = (tv->field->curPlayer->id == tv->ownId) ? false : true; *opponentsMove = (tv->field->curPlayer->id == tv->ownId) ? false : true;
// count completed mills // count completed mills
@ -981,9 +981,9 @@ unsigned int *perfectAI::getPossibilities(unsigned int threadNo, unsigned int *n
// Name: getValueOfSituation() // Name: getValueOfSituation()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::getValueOfSituation(unsigned int threadNo, float &floatValue, TwoBit &shortValue) void PerfectAI::getValueOfSituation(unsigned int threadNo, float &floatValue, TwoBit &shortValue)
{ {
threadVarsStruct *tv = &threadVars[threadNo]; ThreadVars *tv = &threadVars[threadNo];
floatValue = tv->floatValue; floatValue = tv->floatValue;
shortValue = tv->shortValue; shortValue = tv->shortValue;
} }
@ -992,7 +992,7 @@ void perfectAI::getValueOfSituation(unsigned int threadNo, float &floatValue, Tw
// Name: deletePossibilities() // Name: deletePossibilities()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::deletePossibilities(unsigned int threadNo, void *pPossibilities) void PerfectAI::deletePossibilities(unsigned int threadNo, void *pPossibilities)
{ {
} }
@ -1000,10 +1000,10 @@ void perfectAI::deletePossibilities(unsigned int threadNo, void *pPossibilities)
// Name: undo() // Name: undo()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::undo(unsigned int threadNo, unsigned int idPossibility, bool opponentsMove, void *pBackup, void *pPossibilities) void PerfectAI::undo(unsigned int threadNo, unsigned int idPossibility, bool opponentsMove, void *pBackup, void *pPossibilities)
{ {
// locals // locals
threadVarsStruct *tv = &threadVars[threadNo]; ThreadVars *tv = &threadVars[threadNo];
Backup *oldState = (Backup *)pBackup; Backup *oldState = (Backup *)pBackup;
// reset old value // reset old value
@ -1036,7 +1036,7 @@ void perfectAI::undo(unsigned int threadNo, unsigned int idPossibility, bool opp
// Name: setWarning() // Name: setWarning()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
inline void perfectAI::threadVarsStruct::setWarning(unsigned int stoneOne, unsigned int stoneTwo, unsigned int stoneThree) inline void PerfectAI::ThreadVars::setWarning(unsigned int stoneOne, unsigned int stoneTwo, unsigned int stoneThree)
{ {
// if all 3 fields are occupied by current player than he closed a mill // if all 3 fields are occupied by current player than he closed a mill
if (field->board[stoneOne] == field->curPlayer->id && field->board[stoneTwo] == field->curPlayer->id && field->board[stoneThree] == field->curPlayer->id) { if (field->board[stoneOne] == field->curPlayer->id && field->board[stoneTwo] == field->curPlayer->id && field->board[stoneThree] == field->curPlayer->id) {
@ -1058,7 +1058,7 @@ inline void perfectAI::threadVarsStruct::setWarning(unsigned int stoneOne, unsig
// Name: updateWarning() // Name: updateWarning()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
inline void perfectAI::threadVarsStruct::updateWarning(unsigned int firstStone, unsigned int secondStone) inline void PerfectAI::ThreadVars::updateWarning(unsigned int firstStone, unsigned int secondStone)
{ {
// set warnings // set warnings
if (firstStone < field->size) this->setWarning(firstStone, field->neighbour[firstStone][0][0], field->neighbour[firstStone][0][1]); if (firstStone < field->size) this->setWarning(firstStone, field->neighbour[firstStone][0][0], field->neighbour[firstStone][0][1]);
@ -1080,7 +1080,7 @@ inline void perfectAI::threadVarsStruct::updateWarning(unsigned int firstStone,
// Name: updatePossibleMoves() // Name: updatePossibleMoves()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
inline void perfectAI::threadVarsStruct::updatePossibleMoves(unsigned int stone, Player *stoneOwner, bool stoneRemoved, unsigned int ignoreStone) inline void PerfectAI::ThreadVars::updatePossibleMoves(unsigned int stone, Player *stoneOwner, bool stoneRemoved, unsigned int ignoreStone)
{ {
// locals // locals
unsigned int neighbor, direction; unsigned int neighbor, direction;
@ -1125,7 +1125,7 @@ inline void perfectAI::threadVarsStruct::updatePossibleMoves(unsigned int stone,
// Name: setStone() // Name: setStone()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
inline void perfectAI::threadVarsStruct::setStone(unsigned int to, Backup *backup) inline void PerfectAI::ThreadVars::setStone(unsigned int to, Backup *backup)
{ {
// backup // backup
backup->from = field->size; backup->from = field->size;
@ -1152,7 +1152,7 @@ inline void perfectAI::threadVarsStruct::setStone(unsigned int to, Backup *backu
// Name: normalMove() // Name: normalMove()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
inline void perfectAI::threadVarsStruct::normalMove(unsigned int from, unsigned int to, Backup *backup) inline void PerfectAI::ThreadVars::normalMove(unsigned int from, unsigned int to, Backup *backup)
{ {
// backup // backup
backup->from = from; backup->from = from;
@ -1176,7 +1176,7 @@ inline void perfectAI::threadVarsStruct::normalMove(unsigned int from, unsigned
// Name: removeStone() // Name: removeStone()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
inline void perfectAI::threadVarsStruct::removeStone(unsigned int from, Backup *backup) inline void PerfectAI::ThreadVars::removeStone(unsigned int from, Backup *backup)
{ {
// backup // backup
backup->from = from; backup->from = from;
@ -1204,10 +1204,10 @@ inline void perfectAI::threadVarsStruct::removeStone(unsigned int from, Backup *
// Name: move() // Name: move()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::move(unsigned int threadNo, unsigned int idPossibility, bool opponentsMove, void **pBackup, void *pPossibilities) void PerfectAI::move(unsigned int threadNo, unsigned int idPossibility, bool opponentsMove, void **pBackup, void *pPossibilities)
{ {
// locals // locals
threadVarsStruct *tv = &threadVars[threadNo]; ThreadVars *tv = &threadVars[threadNo];
Backup *oldState = &tv->oldStates[tv->curSearchDepth]; Backup *oldState = &tv->oldStates[tv->curSearchDepth];
Possibility *tmpPossibility = (Possibility *)pPossibilities; Possibility *tmpPossibility = (Possibility *)pPossibilities;
Player *tmpPlayer; Player *tmpPlayer;
@ -1274,10 +1274,10 @@ void perfectAI::move(unsigned int threadNo, unsigned int idPossibility, bool opp
// Name: storeValueOfMove() // Name: storeValueOfMove()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::storeValueOfMove(unsigned int threadNo, unsigned int idPossibility, void *pPossibilities, unsigned char value, unsigned int *freqValuesSubMoves, PlyInfoVarType plyInfo) void PerfectAI::storeValueOfMove(unsigned int threadNo, unsigned int idPossibility, void *pPossibilities, unsigned char value, unsigned int *freqValuesSubMoves, PlyInfoVarType plyInfo)
{ {
// locals // locals
threadVarsStruct *tv = &threadVars[threadNo]; ThreadVars *tv = &threadVars[threadNo];
unsigned int index; unsigned int index;
Possibility *tmpPossibility = (Possibility *)pPossibilities; Possibility *tmpPossibility = (Possibility *)pPossibilities;
@ -1297,7 +1297,7 @@ void perfectAI::storeValueOfMove(unsigned int threadNo, unsigned int idPossibili
// Name: getValueOfMoves() // Name: getValueOfMoves()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::getValueOfMoves(unsigned char *moveValue, unsigned int *freqValuesSubMoves, PlyInfoVarType *plyInfo, unsigned int *moveQuality, unsigned char &knotValue, PlyInfoVarType &bestAmountOfPlies) void PerfectAI::getValueOfMoves(unsigned char *moveValue, unsigned int *freqValuesSubMoves, PlyInfoVarType *plyInfo, unsigned int *moveQuality, unsigned char &knotValue, PlyInfoVarType &bestAmountOfPlies)
{ {
// locals // locals
unsigned int moveQualities[fieldStruct::size * fieldStruct::size]; // 0 is bad, 1 is good unsigned int moveQualities[fieldStruct::size * fieldStruct::size]; // 0 is bad, 1 is good
@ -1384,10 +1384,10 @@ void perfectAI::getValueOfMoves(unsigned char *moveValue, unsigned int *freqValu
// Name: printMoveInformation() // Name: printMoveInformation()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::printMoveInformation(unsigned int threadNo, unsigned int idPossibility, void *pPossibilities) void PerfectAI::printMoveInformation(unsigned int threadNo, unsigned int idPossibility, void *pPossibilities)
{ {
// locals // locals
threadVarsStruct *tv = &threadVars[threadNo]; ThreadVars *tv = &threadVars[threadNo];
Possibility *tmpPossibility = (Possibility *)pPossibilities; Possibility *tmpPossibility = (Possibility *)pPossibilities;
// move // move
@ -1400,7 +1400,7 @@ void perfectAI::printMoveInformation(unsigned int threadNo, unsigned int idPossi
// Name: getNumberOfLayers() // Name: getNumberOfLayers()
// Desc: called one time // Desc: called one time
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
unsigned int perfectAI::getNumberOfLayers() unsigned int PerfectAI::getNumberOfLayers()
{ {
return NUM_LAYERS; return NUM_LAYERS;
} }
@ -1409,7 +1409,7 @@ unsigned int perfectAI::getNumberOfLayers()
// Name: shallRetroAnalysisBeUsed() // Name: shallRetroAnalysisBeUsed()
// Desc: called one time for each layer time // Desc: called one time for each layer time
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool perfectAI::shallRetroAnalysisBeUsed(unsigned int layerNum) bool PerfectAI::shallRetroAnalysisBeUsed(unsigned int layerNum)
{ {
if (layerNum < 100) if (layerNum < 100)
return true; return true;
@ -1421,7 +1421,7 @@ bool perfectAI::shallRetroAnalysisBeUsed(unsigned int layerNum)
// Name: getNumberOfKnotsInLayer() // Name: getNumberOfKnotsInLayer()
// Desc: called one time // Desc: called one time
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
unsigned int perfectAI::getNumberOfKnotsInLayer(unsigned int layerNum) unsigned int PerfectAI::getNumberOfKnotsInLayer(unsigned int layerNum)
{ {
// locals // locals
unsigned int numberOfKnots = layer[layerNum].subLayer[layer[layerNum].numSubLayers - 1].maxIndex + 1; unsigned int numberOfKnots = layer[layerNum].subLayer[layer[layerNum].numSubLayers - 1].maxIndex + 1;
@ -1443,7 +1443,7 @@ unsigned int perfectAI::getNumberOfKnotsInLayer(unsigned int layerNum)
// Name: nOverN() // Name: nOverN()
// Desc: called seldom // Desc: called seldom
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
long long perfectAI::mOverN_Function(unsigned int m, unsigned int n) long long PerfectAI::mOverN_Function(unsigned int m, unsigned int n)
{ {
// locals // locals
long long result = 1; long long result = 1;
@ -1472,7 +1472,7 @@ long long perfectAI::mOverN_Function(unsigned int m, unsigned int n)
// Name: applySymmetrieOperationOnField() // Name: applySymmetrieOperationOnField()
// Desc: called very often // Desc: called very often
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::applySymmetrieOperationOnField(unsigned char symmetryOperationNumber, unsigned int *sourceField, unsigned int *destField) void PerfectAI::applySymmetrieOperationOnField(unsigned char symmetryOperationNumber, unsigned int *sourceField, unsigned int *destField)
{ {
for (unsigned int i = 0; i < fieldStruct::size; i++) { for (unsigned int i = 0; i < fieldStruct::size; i++) {
destField[i] = sourceField[symmetryOperationTable[symmetryOperationNumber][i]]; destField[i] = sourceField[symmetryOperationTable[symmetryOperationNumber][i]];
@ -1483,9 +1483,9 @@ void perfectAI::applySymmetrieOperationOnField(unsigned char symmetryOperationNu
// Name: getLayerNumber() // Name: getLayerNumber()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
unsigned int perfectAI::getLayerNumber(unsigned int threadNo) unsigned int PerfectAI::getLayerNumber(unsigned int threadNo)
{ {
threadVarsStruct *tv = &threadVars[threadNo]; ThreadVars *tv = &threadVars[threadNo];
unsigned int numBlackStones = tv->field->oppPlayer->numStones; unsigned int numBlackStones = tv->field->oppPlayer->numStones;
unsigned int numWhiteStones = tv->field->curPlayer->numStones; unsigned int numWhiteStones = tv->field->curPlayer->numStones;
unsigned int phaseIndex = (tv->field->settingPhase == true) ? LAYER_INDEX_SETTING_PHASE : LAYER_INDEX_MOVING_PHASE; unsigned int phaseIndex = (tv->field->settingPhase == true) ? LAYER_INDEX_SETTING_PHASE : LAYER_INDEX_MOVING_PHASE;
@ -1496,9 +1496,9 @@ unsigned int perfectAI::getLayerNumber(unsigned int threadNo)
// Name: getLayerAndStateNumber() // Name: getLayerAndStateNumber()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
unsigned int perfectAI::getLayerAndStateNumber(unsigned int threadNo, unsigned int &layerNum, unsigned int &stateNumber) unsigned int PerfectAI::getLayerAndStateNumber(unsigned int threadNo, unsigned int &layerNum, unsigned int &stateNumber)
{ {
threadVarsStruct *tv = &threadVars[threadNo]; ThreadVars *tv = &threadVars[threadNo];
return tv->getLayerAndStateNumber(layerNum, stateNumber); return tv->getLayerAndStateNumber(layerNum, stateNumber);
} }
@ -1506,7 +1506,7 @@ unsigned int perfectAI::getLayerAndStateNumber(unsigned int threadNo, unsigned i
// Name: getLayerAndStateNumber() // Name: getLayerAndStateNumber()
// Desc: Current player has white stones, the opponent the black ones. // Desc: Current player has white stones, the opponent the black ones.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
unsigned int perfectAI::threadVarsStruct::getLayerAndStateNumber(unsigned int &layerNum, unsigned int &stateNumber) unsigned int PerfectAI::ThreadVars::getLayerAndStateNumber(unsigned int &layerNum, unsigned int &stateNumber)
{ {
// locals // locals
unsigned int myField[fieldStruct::size]; unsigned int myField[fieldStruct::size];
@ -1581,14 +1581,14 @@ unsigned int perfectAI::threadVarsStruct::getLayerAndStateNumber(unsigned int &l
// Desc: Current player has white stones, the opponent the black ones. // Desc: Current player has white stones, the opponent the black ones.
// Sets up the game situation corresponding to the passed layer number and state. // Sets up the game situation corresponding to the passed layer number and state.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool perfectAI::setSituation(unsigned int threadNo, unsigned int layerNum, unsigned int stateNumber) bool PerfectAI::setSituation(unsigned int threadNo, unsigned int layerNum, unsigned int stateNumber)
{ {
// parameters ok ? // parameters ok ?
if (getNumberOfLayers() <= layerNum) return false; if (getNumberOfLayers() <= layerNum) return false;
if (getNumberOfKnotsInLayer(layerNum) <= stateNumber) return false; if (getNumberOfKnotsInLayer(layerNum) <= stateNumber) return false;
// locals // locals
threadVarsStruct *tv = &threadVars[threadNo]; ThreadVars *tv = &threadVars[threadNo];
unsigned int stateNumberWithInSubLayer; unsigned int stateNumberWithInSubLayer;
unsigned int stateNumberWithInAB; unsigned int stateNumberWithInAB;
unsigned int stateNumberWithInCD; unsigned int stateNumberWithInCD;
@ -1740,7 +1740,7 @@ bool perfectAI::setSituation(unsigned int threadNo, unsigned int layerNum, unsig
// Name: calcPossibleMoves() // Name: calcPossibleMoves()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::threadVarsStruct::calcPossibleMoves(Player *player) void PerfectAI::ThreadVars::calcPossibleMoves(Player *player)
{ {
// locals // locals
unsigned int i, j, k, movingDirection; unsigned int i, j, k, movingDirection;
@ -1774,7 +1774,7 @@ void perfectAI::threadVarsStruct::calcPossibleMoves(Player *player)
// Name: setWarningAndMill() // Name: setWarningAndMill()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::threadVarsStruct::setWarningAndMill(unsigned int stone, unsigned int firstNeighbour, unsigned int secondNeighbour) void PerfectAI::ThreadVars::setWarningAndMill(unsigned int stone, unsigned int firstNeighbour, unsigned int secondNeighbour)
{ {
// locals // locals
int rowOwner = field->board[stone]; int rowOwner = field->board[stone];
@ -1792,7 +1792,7 @@ void perfectAI::threadVarsStruct::setWarningAndMill(unsigned int stone, unsigned
// Name: getOutputInformation() // Name: getOutputInformation()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
string perfectAI::getOutputInformation(unsigned int layerNum) string PerfectAI::getOutputInformation(unsigned int layerNum)
{ {
stringstream ss; stringstream ss;
ss << " white stones : " << layer[layerNum].numWhiteStones << " \tblack stones : " << layer[layerNum].numBlackStones; ss << " white stones : " << layer[layerNum].numWhiteStones << " \tblack stones : " << layer[layerNum].numBlackStones;
@ -1803,9 +1803,9 @@ string perfectAI::getOutputInformation(unsigned int layerNum)
// Name: printField() // Name: printField()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::printField(unsigned int threadNo, unsigned char value) void PerfectAI::printField(unsigned int threadNo, unsigned char value)
{ {
threadVarsStruct *tv = &threadVars[threadNo]; ThreadVars *tv = &threadVars[threadNo];
char wonStr[] = "WON"; char wonStr[] = "WON";
char lostStr[] = "LOST"; char lostStr[] = "LOST";
char drawStr[] = "DRAW"; char drawStr[] = "DRAW";
@ -1821,7 +1821,7 @@ void perfectAI::printField(unsigned int threadNo, unsigned char value)
// Name: getField() // Name: getField()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::getField(unsigned int layerNum, unsigned int stateNumber, fieldStruct *field, bool *gameHasFinished) void PerfectAI::getField(unsigned int layerNum, unsigned int stateNumber, fieldStruct *field, bool *gameHasFinished)
{ {
// set current desired state on thread zero // set current desired state on thread zero
setSituation(0, layerNum, stateNumber); setSituation(0, layerNum, stateNumber);
@ -1836,7 +1836,7 @@ void perfectAI::getField(unsigned int layerNum, unsigned int stateNumber, fieldS
// Name: getLayerAndStateNumber() // Name: getLayerAndStateNumber()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::getLayerAndStateNumber(unsigned int &layerNum, unsigned int &stateNumber/*, unsigned int& symmetryOperation*/) void PerfectAI::getLayerAndStateNumber(unsigned int &layerNum, unsigned int &stateNumber/*, unsigned int& symmetryOperation*/)
{ {
/*symmetryOperation = */threadVars[0].getLayerAndStateNumber(layerNum, stateNumber); /*symmetryOperation = */threadVars[0].getLayerAndStateNumber(layerNum, stateNumber);
} }
@ -1845,9 +1845,9 @@ void perfectAI::getLayerAndStateNumber(unsigned int &layerNum, unsigned int &sta
// Name: setOpponentLevel() // Name: setOpponentLevel()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::setOpponentLevel(unsigned int threadNo, bool isOpponentLevel) void PerfectAI::setOpponentLevel(unsigned int threadNo, bool isOpponentLevel)
{ {
threadVarsStruct *tv = &threadVars[threadNo]; ThreadVars *tv = &threadVars[threadNo];
tv->ownId = isOpponentLevel ? tv->field->oppPlayer->id : tv->field->curPlayer->id; tv->ownId = isOpponentLevel ? tv->field->oppPlayer->id : tv->field->curPlayer->id;
} }
@ -1855,9 +1855,9 @@ void perfectAI::setOpponentLevel(unsigned int threadNo, bool isOpponentLevel)
// Name: getOpponentLevel() // Name: getOpponentLevel()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool perfectAI::getOpponentLevel(unsigned int threadNo) bool PerfectAI::getOpponentLevel(unsigned int threadNo)
{ {
threadVarsStruct *tv = &threadVars[threadNo]; ThreadVars *tv = &threadVars[threadNo];
return (tv->ownId == tv->field->oppPlayer->id); return (tv->ownId == tv->field->oppPlayer->id);
} }
@ -1865,7 +1865,7 @@ bool perfectAI::getOpponentLevel(unsigned int threadNo)
// Name: getPartnerLayer() // Name: getPartnerLayer()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
unsigned int perfectAI::getPartnerLayer(unsigned int layerNum) unsigned int PerfectAI::getPartnerLayer(unsigned int layerNum)
{ {
if (layerNum < 100) if (layerNum < 100)
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
@ -1881,7 +1881,7 @@ unsigned int perfectAI::getPartnerLayer(unsigned int layerNum)
// Name: getSuccLayers() // Name: getSuccLayers()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::getSuccLayers(unsigned int layerNum, unsigned int *amountOfSuccLayers, unsigned int *succLayers) void PerfectAI::getSuccLayers(unsigned int layerNum, unsigned int *amountOfSuccLayers, unsigned int *succLayers)
{ {
// locals // locals
unsigned int i; unsigned int i;
@ -1913,10 +1913,10 @@ void perfectAI::getSuccLayers(unsigned int layerNum, unsigned int *amountOfSuccL
// Name: getSymStateNumWithDoubles() // Name: getSymStateNumWithDoubles()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::getSymStateNumWithDoubles(unsigned int threadNo, unsigned int *numSymmetricStates, unsigned int **symStateNumbers) void PerfectAI::getSymStateNumWithDoubles(unsigned int threadNo, unsigned int *numSymmetricStates, unsigned int **symStateNumbers)
{ {
// locals // locals
threadVarsStruct *tv = &threadVars[threadNo]; ThreadVars *tv = &threadVars[threadNo];
int originalField[fieldStruct::size]; int originalField[fieldStruct::size];
unsigned int originalPartOfMill[fieldStruct::size]; unsigned int originalPartOfMill[fieldStruct::size];
unsigned int i, symmetryOperation; unsigned int i, symmetryOperation;
@ -1954,7 +1954,7 @@ void perfectAI::getSymStateNumWithDoubles(unsigned int threadNo, unsigned int *n
// Name: fieldIntegrityOK() // Name: fieldIntegrityOK()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool perfectAI::threadVarsStruct::fieldIntegrityOK(unsigned int numberOfMillsCurrentPlayer, unsigned int numberOfMillsOpponentPlayer, bool aStoneCanBeRemovedFromCurPlayer) bool PerfectAI::ThreadVars::fieldIntegrityOK(unsigned int numberOfMillsCurrentPlayer, unsigned int numberOfMillsOpponentPlayer, bool aStoneCanBeRemovedFromCurPlayer)
{ {
// locals // locals
int i, j; int i, j;
@ -1999,7 +1999,7 @@ bool perfectAI::threadVarsStruct::fieldIntegrityOK(unsigned int numberOfMillsCur
// Name: isSymOperationInvariantOnGroupCD() // Name: isSymOperationInvariantOnGroupCD()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool perfectAI::isSymOperationInvariantOnGroupCD(unsigned int symmetryOperation, int *theField) bool PerfectAI::isSymOperationInvariantOnGroupCD(unsigned int symmetryOperation, int *theField)
{ {
// locals // locals
unsigned int i; unsigned int i;
@ -2028,7 +2028,7 @@ bool perfectAI::isSymOperationInvariantOnGroupCD(unsigned int symmetryOperation,
// Name: storePredecessor() // Name: storePredecessor()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::threadVarsStruct::storePredecessor(unsigned int numberOfMillsCurrentPlayer, unsigned int numberOfMillsOpponentPlayer, unsigned int *amountOfPred, RetroAnalysisPredVars *predVars) void PerfectAI::ThreadVars::storePredecessor(unsigned int numberOfMillsCurrentPlayer, unsigned int numberOfMillsOpponentPlayer, unsigned int *amountOfPred, RetroAnalysisPredVars *predVars)
{ {
// locals // locals
int originalField[fieldStruct::size]; int originalField[fieldStruct::size];
@ -2072,7 +2072,7 @@ void perfectAI::threadVarsStruct::storePredecessor(unsigned int numberOfMillsCur
// Name: getPredecessors() // Name: getPredecessors()
// Desc: CAUTION: States musn't be returned twice. // Desc: CAUTION: States musn't be returned twice.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void perfectAI::getPredecessors(unsigned int threadNo, unsigned int *amountOfPred, RetroAnalysisPredVars *predVars) void PerfectAI::getPredecessors(unsigned int threadNo, unsigned int *amountOfPred, RetroAnalysisPredVars *predVars)
{ {
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// the important variables, which much be updated for the getLayerAndStateNumber function are the following ones: // the important variables, which much be updated for the getLayerAndStateNumber function are the following ones:
@ -2085,7 +2085,7 @@ void perfectAI::getPredecessors(unsigned int threadNo, unsigned int *amountOfPre
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// locals // locals
threadVarsStruct *tv = &threadVars[threadNo]; ThreadVars *tv = &threadVars[threadNo];
bool aStoneCanBeRemovedFromCurPlayer; bool aStoneCanBeRemovedFromCurPlayer;
bool millWasClosed; bool millWasClosed;
unsigned int from, to, dir, i; unsigned int from, to, dir, i;
@ -2308,7 +2308,7 @@ void perfectAI::getPredecessors(unsigned int threadNo, unsigned int *amountOfPre
// Name: checkMoveAndSetSituation() // Name: checkMoveAndSetSituation()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool perfectAI::checkMoveAndSetSituation() bool PerfectAI::checkMoveAndSetSituation()
{ {
// locals // locals
bool aStoneCanBeRemovedFromCurPlayer; bool aStoneCanBeRemovedFromCurPlayer;
@ -2320,7 +2320,7 @@ bool perfectAI::checkMoveAndSetSituation()
void *pPossibilities; void *pPossibilities;
void *pBackup; void *pBackup;
unsigned int threadNo = 0; unsigned int threadNo = 0;
threadVarsStruct *tv = &threadVars[threadNo]; ThreadVars *tv = &threadVars[threadNo];
// output // output
cout << endl << "checkMoveAndSetSituation()" << endl; cout << endl << "checkMoveAndSetSituation()" << endl;
@ -2387,7 +2387,7 @@ bool perfectAI::checkMoveAndSetSituation()
// Name: checkGetPossThanGetPred() // Name: checkGetPossThanGetPred()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool perfectAI::checkGetPossThanGetPred() bool PerfectAI::checkGetPossThanGetPred()
{ {
// locals // locals
unsigned int stateNum, layerNum, i, j; unsigned int stateNum, layerNum, i, j;
@ -2399,7 +2399,7 @@ bool perfectAI::checkGetPossThanGetPred()
void *pBackup; void *pBackup;
RetroAnalysisPredVars predVars[MAX_NUM_PREDECESSORS]; RetroAnalysisPredVars predVars[MAX_NUM_PREDECESSORS];
unsigned int threadNo = 0; unsigned int threadNo = 0;
threadVarsStruct *tv = &threadVars[threadNo]; ThreadVars *tv = &threadVars[threadNo];
// test if each successor from getPossibilities() leads to the original state using getPredecessors() // test if each successor from getPossibilities() leads to the original state using getPredecessors()
for (layerNum = 0; layerNum < NUM_LAYERS; layerNum++) { for (layerNum = 0; layerNum < NUM_LAYERS; layerNum++) {
@ -2466,11 +2466,11 @@ bool perfectAI::checkGetPossThanGetPred()
// Name: checkGetPredThanGetPoss() // Name: checkGetPredThanGetPoss()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool perfectAI::checkGetPredThanGetPoss() bool PerfectAI::checkGetPredThanGetPoss()
{ {
// locals // locals
unsigned int threadNo = 0; unsigned int threadNo = 0;
threadVarsStruct *tv = &threadVars[threadNo]; ThreadVars *tv = &threadVars[threadNo];
unsigned int stateNum, layerNum, i, j, k; unsigned int stateNum, layerNum, i, j, k;
unsigned int stateNumB, layerNumB; unsigned int stateNumB, layerNumB;
unsigned int *idPossibility; unsigned int *idPossibility;

View File

@ -1,5 +1,5 @@
/*********************************************************************\ /*********************************************************************\
perfectAI.h PerfectAI.h
Copyright (c) Thomas Weber. All rights reserved. Copyright (c) Thomas Weber. All rights reserved.
Copyright (C) 2021 The Sanmill developers (see AUTHORS file) Copyright (C) 2021 The Sanmill developers (see AUTHORS file)
Licensed under the MIT License. Licensed under the MIT License.
@ -75,12 +75,12 @@
#define NUM_SYM_OPERATIONS 16 #define NUM_SYM_OPERATIONS 16
/*** Klassen *********************************************************/ /*** Klassen *********************************************************/
class perfectAI : public MillAI, public MiniMax class PerfectAI : public MillAI, public MiniMax
{ {
protected: protected:
// structs // structs
struct subLayerStruct struct SubLayer
{ {
unsigned int minIndex; unsigned int minIndex;
unsigned int maxIndex; unsigned int maxIndex;
@ -88,14 +88,14 @@ protected:
unsigned int numWhiteStonesGroupAB, numBlackStonesGroupAB; unsigned int numWhiteStonesGroupAB, numBlackStonesGroupAB;
}; };
struct layerStruct struct Layer
{ {
unsigned int numWhiteStones; unsigned int numWhiteStones;
unsigned int numBlackStones; unsigned int numBlackStones;
unsigned int numSubLayers; unsigned int numSubLayers;
unsigned int subLayerIndexAB[NUM_STONES_PER_PLAYER_PLUS_ONE][NUM_STONES_PER_PLAYER_PLUS_ONE]; unsigned int subLayerIndexAB[NUM_STONES_PER_PLAYER_PLUS_ONE][NUM_STONES_PER_PLAYER_PLUS_ONE];
unsigned int subLayerIndexCD[NUM_STONES_PER_PLAYER_PLUS_ONE][NUM_STONES_PER_PLAYER_PLUS_ONE]; unsigned int subLayerIndexCD[NUM_STONES_PER_PLAYER_PLUS_ONE][NUM_STONES_PER_PLAYER_PLUS_ONE];
subLayerStruct subLayer[MAX_NUM_SUB_LAYERS]; SubLayer subLayer[MAX_NUM_SUB_LAYERS];
}; };
struct Possibility struct Possibility
@ -122,13 +122,13 @@ protected:
}; };
// preCalcedVars.dat // preCalcedVars.dat
struct preCalcedVarsFileHeaderStruct struct PreCalcedVarsFileHeader
{ {
unsigned int sizeInBytes; unsigned int sizeInBytes;
}; };
// constant variables for state addressing in the database // constant variables for state addressing in the database
layerStruct layer[NUM_LAYERS]; // the layers Layer layer[NUM_LAYERS]; // the layers
unsigned int layerIndex[2][NUM_STONES_PER_PLAYER_PLUS_ONE][NUM_STONES_PER_PLAYER_PLUS_ONE]; // indices of layer [moving/setting phase][number of white stones][number of black stones] unsigned int layerIndex[2][NUM_STONES_PER_PLAYER_PLUS_ONE][NUM_STONES_PER_PLAYER_PLUS_ONE]; // indices of layer [moving/setting phase][number of white stones][number of black stones]
unsigned int anzahlStellungenCD[NUM_STONES_PER_PLAYER_PLUS_ONE][NUM_STONES_PER_PLAYER_PLUS_ONE]; unsigned int anzahlStellungenCD[NUM_STONES_PER_PLAYER_PLUS_ONE][NUM_STONES_PER_PLAYER_PLUS_ONE];
unsigned int anzahlStellungenAB[NUM_STONES_PER_PLAYER_PLUS_ONE][NUM_STONES_PER_PLAYER_PLUS_ONE]; unsigned int anzahlStellungenAB[NUM_STONES_PER_PLAYER_PLUS_ONE][NUM_STONES_PER_PLAYER_PLUS_ONE];
@ -149,7 +149,7 @@ protected:
string databaseDirectory; // directory containing the database files string databaseDirectory; // directory containing the database files
// Variables used individually by each single thread // Variables used individually by each single thread
class threadVarsStruct class ThreadVars
{ {
public: public:
fieldStruct *field; // pointer of the current board [changed by move()] fieldStruct *field; // pointer of the current board [changed by move()]
@ -162,10 +162,10 @@ protected:
unsigned int *idPossibilities; // returned pointer of getPossibilities()-function unsigned int *idPossibilities; // returned pointer of getPossibilities()-function
Backup *oldStates; // for undo()-function Backup *oldStates; // for undo()-function
Possibility *possibilities; // for getPossNormalMove()-function Possibility *possibilities; // for getPossNormalMove()-function
perfectAI *parent; // PerfectAI *parent; //
// constructor // constructor
threadVarsStruct(); ThreadVars();
// Functions // Functions
unsigned int *getPossSettingPhase(unsigned int *numPossibilities, void **pPossibilities); unsigned int *getPossSettingPhase(unsigned int *numPossibilities, void **pPossibilities);
@ -187,7 +187,7 @@ protected:
void calcPossibleMoves(Player *player); void calcPossibleMoves(Player *player);
void storePredecessor(unsigned int numberOfMillsCurrentPlayer, unsigned int numberOfMillsOpponentPlayer, unsigned int *amountOfPred, RetroAnalysisPredVars *predVars); void storePredecessor(unsigned int numberOfMillsCurrentPlayer, unsigned int numberOfMillsOpponentPlayer, unsigned int *amountOfPred, RetroAnalysisPredVars *predVars);
}; };
threadVarsStruct *threadVars; ThreadVars *threadVars;
// database functions // database functions
unsigned int getNumberOfLayers(); unsigned int getNumberOfLayers();
@ -227,8 +227,8 @@ protected:
public: public:
// Constructor / destructor // Constructor / destructor
perfectAI(const char *directory); PerfectAI(const char *directory);
~perfectAI(); ~PerfectAI();
// Functions // Functions
bool setDatabasePath(const char *directory); bool setDatabasePath(const char *directory);