perfect: Rename minMax functions (2)

This commit is contained in:
Calcitem 2021-01-20 01:16:18 +08:00
parent d9efb9ce67
commit de58c91578
12 changed files with 208 additions and 208 deletions

View File

@ -1,5 +1,5 @@
/********************************************************************* /*********************************************************************
miniMaxAI.cpp MiniMaxAI.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.
@ -9,19 +9,19 @@
#include "miniMaxAI.h" #include "miniMaxAI.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Name: miniMaxAI() // Name: MiniMaxAI()
// Desc: miniMaxAI class constructor // Desc: MiniMaxAI class constructor
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
miniMaxAI::miniMaxAI() MiniMaxAI::MiniMaxAI()
{ {
depthOfFullTree = 0; depthOfFullTree = 0;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Name: ~miniMaxAI() // Name: ~MiniMaxAI()
// Desc: miniMaxAI class destructor // Desc: MiniMaxAI class destructor
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
miniMaxAI::~miniMaxAI() MiniMaxAI::~MiniMaxAI()
{ {
} }
@ -29,7 +29,7 @@ miniMaxAI::~miniMaxAI()
// Name: play() // Name: play()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void miniMaxAI::play(fieldStruct *theField, unsigned int *pushFrom, unsigned int *pushTo) void MiniMaxAI::play(fieldStruct *theField, unsigned int *pushFrom, unsigned int *pushTo)
{ {
// globals // globals
field = theField; field = theField;
@ -49,15 +49,15 @@ void miniMaxAI::play(fieldStruct *theField, unsigned int *pushFrom, unsigned int
} }
// Inform user about progress // Inform user about progress
cout << "miniMaxAI is thinking with a depth of " << searchDepth << " steps!\n\n\n"; cout << "MiniMaxAI is thinking with a depth of " << searchDepth << " steps!\n\n\n";
// reserve memory // reserve memory
possibilities = new possibilityStruct[searchDepth + 1]; possibilities = new Possibility[searchDepth + 1];
oldStates = new backupStruct[searchDepth + 1]; oldStates = new Backup[searchDepth + 1];
idPossibilities = new unsigned int[(searchDepth + 1) * MAX_NUM_POS_MOVES]; idPossibilities = new unsigned int[(searchDepth + 1) * MAX_NUM_POS_MOVES];
// start the miniMax-algorithmn // start the miniMax-algorithmn
possibilityStruct *rootPossibilities = (possibilityStruct *)getBestChoice(searchDepth, &bestChoice, MAX_NUM_POS_MOVES); Possibility *rootPossibilities = (Possibility *)getBestChoice(searchDepth, &bestChoice, MAX_NUM_POS_MOVES);
// decode the best choice // decode the best choice
if (field->stoneMustBeRemoved) { if (field->stoneMustBeRemoved) {
@ -82,7 +82,7 @@ void miniMaxAI::play(fieldStruct *theField, unsigned int *pushFrom, unsigned int
// Name: setSearchDepth() // Name: setSearchDepth()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void miniMaxAI::setSearchDepth(unsigned int depth) void MiniMaxAI::setSearchDepth(unsigned int depth)
{ {
depthOfFullTree = depth; depthOfFullTree = depth;
} }
@ -91,7 +91,7 @@ void miniMaxAI::setSearchDepth(unsigned int depth)
// Name: prepareBestChoiceCalculation() // Name: prepareBestChoiceCalculation()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void miniMaxAI::prepareBestChoiceCalculation() void MiniMaxAI::prepareBestChoiceCalculation()
{ {
// calculate current value // calculate current value
currentValue = 0; currentValue = 0;
@ -102,7 +102,7 @@ void miniMaxAI::prepareBestChoiceCalculation()
// Name: getPossSettingPhase() // Name: getPossSettingPhase()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
unsigned int *miniMaxAI::getPossSettingPhase(unsigned int *numPossibilities, void **pPossibilities) unsigned int *MiniMaxAI::getPossSettingPhase(unsigned int *numPossibilities, void **pPossibilities)
{ {
// locals // locals
unsigned int i; unsigned int i;
@ -129,12 +129,12 @@ unsigned int *miniMaxAI::getPossSettingPhase(unsigned int *numPossibilities, voi
// Name: getPossNormalMove() // Name: getPossNormalMove()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
unsigned int *miniMaxAI::getPossNormalMove(unsigned int *numPossibilities, void **pPossibilities) unsigned int *MiniMaxAI::getPossNormalMove(unsigned int *numPossibilities, void **pPossibilities)
{ {
// locals // locals
unsigned int from, to, dir; unsigned int from, to, dir;
unsigned int *idPossibility = &idPossibilities[curSearchDepth * MAX_NUM_POS_MOVES]; unsigned int *idPossibility = &idPossibilities[curSearchDepth * MAX_NUM_POS_MOVES];
possibilityStruct *possibility = &possibilities[curSearchDepth]; Possibility *possibility = &possibilities[curSearchDepth];
// if he is not allowed to spring // if he is not allowed to spring
if (field->curPlayer->numStones > 3) { if (field->curPlayer->numStones > 3) {
@ -186,7 +186,7 @@ unsigned int *miniMaxAI::getPossNormalMove(unsigned int *numPossibilities, void
// Name: getPossStoneRemove() // Name: getPossStoneRemove()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
unsigned int *miniMaxAI::getPossStoneRemove(unsigned int *numPossibilities, void **pPossibilities) unsigned int *MiniMaxAI::getPossStoneRemove(unsigned int *numPossibilities, void **pPossibilities)
{ {
// locals // locals
unsigned int i; unsigned int i;
@ -213,7 +213,7 @@ unsigned int *miniMaxAI::getPossStoneRemove(unsigned int *numPossibilities, void
// Name: getPossibilities() // Name: getPossibilities()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
unsigned int *miniMaxAI::getPossibilities(unsigned int threadNo, unsigned int *numPossibilities, bool *opponentsMove, void **pPossibilities) unsigned int *MiniMaxAI::getPossibilities(unsigned int threadNo, unsigned int *numPossibilities, bool *opponentsMove, void **pPossibilities)
{ {
// set opponentsMove // set opponentsMove
*opponentsMove = (field->curPlayer->id == ownId) ? false : true; *opponentsMove = (field->curPlayer->id == ownId) ? false : true;
@ -234,7 +234,7 @@ unsigned int *miniMaxAI::getPossibilities(unsigned int threadNo, unsigned int *n
// Name: getValueOfSituation() // Name: getValueOfSituation()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void miniMaxAI::getValueOfSituation(unsigned int threadNo, float &floatValue, twoBit &shortValue) void MiniMaxAI::getValueOfSituation(unsigned int threadNo, float &floatValue, TwoBit &shortValue)
{ {
floatValue = currentValue; floatValue = currentValue;
shortValue = 0; shortValue = 0;
@ -244,7 +244,7 @@ void miniMaxAI::getValueOfSituation(unsigned int threadNo, float &floatValue, tw
// Name: deletePossibilities() // Name: deletePossibilities()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void miniMaxAI::deletePossibilities(unsigned int threadNo, void *pPossibilities) void MiniMaxAI::deletePossibilities(unsigned int threadNo, void *pPossibilities)
{ {
} }
@ -252,10 +252,10 @@ void miniMaxAI::deletePossibilities(unsigned int threadNo, void *pPossibilities)
// Name: undo() // Name: undo()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void miniMaxAI::undo(unsigned int threadNo, unsigned int idPossibility, bool opponentsMove, void *pBackup, void *pPossibilities) void MiniMaxAI::undo(unsigned int threadNo, unsigned int idPossibility, bool opponentsMove, void *pBackup, void *pPossibilities)
{ {
// locals // locals
backupStruct *oldState = (backupStruct *)pBackup; Backup *oldState = (Backup *)pBackup;
// reset old value // reset old value
currentValue = oldState->value; currentValue = oldState->value;
@ -287,7 +287,7 @@ void miniMaxAI::undo(unsigned int threadNo, unsigned int idPossibility, bool opp
// Name: setWarning() // Name: setWarning()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
inline void miniMaxAI::setWarning(unsigned int stoneOne, unsigned int stoneTwo, unsigned int stoneThree) inline void MiniMaxAI::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) {
@ -349,7 +349,7 @@ inline void miniMaxAI::setWarning(unsigned int stoneOne, unsigned int stoneTwo,
// Name: updateWarning() // Name: updateWarning()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
inline void miniMaxAI::updateWarning(unsigned int firstStone, unsigned int secondStone) inline void MiniMaxAI::updateWarning(unsigned int firstStone, unsigned int secondStone)
{ {
// set warnings // set warnings
if (firstStone < field->size) setWarning(firstStone, field->neighbour[firstStone][0][0], field->neighbour[firstStone][0][1]); if (firstStone < field->size) setWarning(firstStone, field->neighbour[firstStone][0][0], field->neighbour[firstStone][0][1]);
@ -371,7 +371,7 @@ inline void miniMaxAI::updateWarning(unsigned int firstStone, unsigned int secon
// Name: updatePossibleMoves() // Name: updatePossibleMoves()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
inline void miniMaxAI::updatePossibleMoves(unsigned int stone, Player *stoneOwner, bool stoneRemoved, unsigned int ignoreStone) inline void MiniMaxAI::updatePossibleMoves(unsigned int stone, Player *stoneOwner, bool stoneRemoved, unsigned int ignoreStone)
{ {
// locals // locals
unsigned int neighbor, direction; unsigned int neighbor, direction;
@ -416,7 +416,7 @@ inline void miniMaxAI::updatePossibleMoves(unsigned int stone, Player *stoneOwne
// Name: setStone() // Name: setStone()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
inline void miniMaxAI::setStone(unsigned int to, backupStruct *backup) inline void MiniMaxAI::setStone(unsigned int to, Backup *backup)
{ {
// backup // backup
backup->from = field->size; backup->from = field->size;
@ -443,7 +443,7 @@ inline void miniMaxAI::setStone(unsigned int to, backupStruct *backup)
// Name: normalMove() // Name: normalMove()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
inline void miniMaxAI::normalMove(unsigned int from, unsigned int to, backupStruct *backup) inline void MiniMaxAI::normalMove(unsigned int from, unsigned int to, Backup *backup)
{ {
// backup // backup
backup->from = from; backup->from = from;
@ -467,7 +467,7 @@ inline void miniMaxAI::normalMove(unsigned int from, unsigned int to, backupStru
// Name: removeStone() // Name: removeStone()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
inline void miniMaxAI::removeStone(unsigned int from, backupStruct *backup) inline void MiniMaxAI::removeStone(unsigned int from, Backup *backup)
{ {
// backup // backup
backup->from = from; backup->from = from;
@ -495,11 +495,11 @@ inline void miniMaxAI::removeStone(unsigned int from, backupStruct *backup)
// Name: move() // Name: move()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void miniMaxAI::move(unsigned int threadNo, unsigned int idPossibility, bool opponentsMove, void **pBackup, void *pPossibilities) void MiniMaxAI::move(unsigned int threadNo, unsigned int idPossibility, bool opponentsMove, void **pBackup, void *pPossibilities)
{ {
// locals // locals
backupStruct *oldState = &oldStates[curSearchDepth]; Backup *oldState = &oldStates[curSearchDepth];
possibilityStruct *tmpPossibility = (possibilityStruct *)pPossibilities; Possibility *tmpPossibility = (Possibility *)pPossibilities;
Player *tmpPlayer; Player *tmpPlayer;
unsigned int i; unsigned int i;
@ -558,10 +558,10 @@ void miniMaxAI::move(unsigned int threadNo, unsigned int idPossibility, bool opp
// Name: printMoveInformation() // Name: printMoveInformation()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void miniMaxAI::printMoveInformation(unsigned int threadNo, unsigned int idPossibility, void *pPossibilities) void MiniMaxAI::printMoveInformation(unsigned int threadNo, unsigned int idPossibility, void *pPossibilities)
{ {
// locals // locals
possibilityStruct *tmpPossibility = (possibilityStruct *)pPossibilities; Possibility *tmpPossibility = (Possibility *)pPossibilities;
// move // move
if (field->stoneMustBeRemoved) cout << "remove stone from " << (char)(idPossibility + 97); if (field->stoneMustBeRemoved) cout << "remove stone from " << (char)(idPossibility + 97);

View File

@ -110,10 +110,10 @@ class MiniMax
public: public:
/*** typedefines ***************************************************************************************************************************/ /*** typedefines ***************************************************************************************************************************/
typedef unsigned char twoBit; // 2-Bit variable ranging from 0 to 3 typedef unsigned char TwoBit; // 2-Bit variable ranging from 0 to 3
typedef unsigned short plyInfoVarType; // 2 Bytes for saving the ply info typedef unsigned short PlyInfoVarType; // 2 Bytes for saving the ply info
typedef unsigned char countArrayVarType; // 1 Byte for counting predesseccors typedef unsigned char CountArrayVarType; // 1 Byte for counting predesseccors
typedef unsigned int stateNumberVarType; // 4 Bytes for addressing states within a layer typedef unsigned int StateNumberVarType; // 4 Bytes for addressing states within a layer
/*** protected structures ********************************************************************************************************************/ /*** protected structures ********************************************************************************************************************/
@ -139,8 +139,8 @@ public:
bool plyInfoIsCompletedAndInFile; // the array plyInfo[] contains only fully calculated valid values bool plyInfoIsCompletedAndInFile; // the array plyInfo[] contains only fully calculated valid values
long long layerOffset; // position of this struct in the ply info file long long layerOffset; // position of this struct in the ply info file
unsigned int sizeInBytes; // size of this struct plus the array plyInfo[] unsigned int sizeInBytes; // size of this struct plus the array plyInfo[]
stateNumberVarType knotsInLayer; // number of knots of the corresponding layer StateNumberVarType knotsInLayer; // number of knots of the corresponding layer
plyInfoVarType *plyInfo; // array of size [knotsInLayer] containing the ply info for each knot in this layer PlyInfoVarType *plyInfo; // array of size [knotsInLayer] containing the ply info for each knot in this layer
// compressorClass::compressedArrayClass * plyInfoCompressed; // compressed array containing the ply info for each knot in this layer // compressorClass::compressedArrayClass * plyInfoCompressed; // compressed array containing the ply info for each knot in this layer
void *plyInfoCompressed; // dummy pointer for padding void *plyInfoCompressed; // dummy pointer for padding
}; };
@ -153,20 +153,20 @@ public:
unsigned int numSuccLayers; // number of succeding layers. states of other layers are connected by a move of a player unsigned int numSuccLayers; // number of succeding layers. states of other layers are connected by a move of a player
unsigned int succLayers[MAX_NUM_PRED_LAYERS];// array containg the layer ids of the succeding layers unsigned int succLayers[MAX_NUM_PRED_LAYERS];// array containg the layer ids of the succeding layers
unsigned int partnerLayer; // layer id relevant when switching current and opponent player unsigned int partnerLayer; // layer id relevant when switching current and opponent player
stateNumberVarType knotsInLayer; // number of knots of the corresponding layer StateNumberVarType knotsInLayer; // number of knots of the corresponding layer
stateNumberVarType numWonStates; // number of won states in this layer StateNumberVarType numWonStates; // number of won states in this layer
stateNumberVarType numLostStates; // number of lost states in this layer StateNumberVarType numLostStates; // number of lost states in this layer
stateNumberVarType numDrawnStates; // number of drawn states in this layer StateNumberVarType numDrawnStates; // number of drawn states in this layer
stateNumberVarType numInvalidStates; // number of invalid states in this layer StateNumberVarType numInvalidStates; // number of invalid states in this layer
unsigned int sizeInBytes; // (knotsInLayer + 3) / 4 unsigned int sizeInBytes; // (knotsInLayer + 3) / 4
twoBit *shortKnotValueByte; // array of size [sizeInBytes] containg the short knot values TwoBit *shortKnotValueByte; // array of size [sizeInBytes] containg the short knot values
//compressorClass::compressedArrayClass * skvCompressed; // compressed array containing the short knot values //compressorClass::compressedArrayClass * skvCompressed; // compressed array containing the short knot values
void *skvCompressed; // dummy pointer for padding void *skvCompressed; // dummy pointer for padding
}; };
struct StateAdress struct StateAdress
{ {
stateNumberVarType stateNumber; // state id within the corresponding layer StateNumberVarType stateNumber; // state id within the corresponding layer
unsigned char layerNumber; // layer id unsigned char layerNumber; // layer id
}; };
@ -174,15 +174,15 @@ public:
{ {
bool isOpponentLevel; // the current considered knot belongs to an opponent game state bool isOpponentLevel; // the current considered knot belongs to an opponent game state
float floatValue; // Value of knot (for normal mode) float floatValue; // Value of knot (for normal mode)
twoBit shortValue; // Value of knot (for database) TwoBit shortValue; // Value of knot (for database)
unsigned int bestMoveId; // for calling class unsigned int bestMoveId; // for calling class
unsigned int bestBranch; // branch with highest value unsigned int bestBranch; // branch with highest value
unsigned int numPossibilities; // number of branches unsigned int numPossibilities; // number of branches
plyInfoVarType plyInfo; // number of moves till win/lost PlyInfoVarType plyInfo; // number of moves till win/lost
Node *branches; // pointer to branches Node *branches; // pointer to branches
}; };
struct retroAnalysisPredVars struct RetroAnalysisPredVars
{ {
unsigned int predStateNumbers; // unsigned int predStateNumbers; //
unsigned int predLayerNumbers; // unsigned int predLayerNumbers; //
@ -245,10 +245,10 @@ public:
unsigned int getNumThreads(); unsigned int getNumThreads();
bool anyFreshlyCalculatedLayer(); bool anyFreshlyCalculatedLayer();
unsigned int getLastCalculatedLayer(); unsigned int getLastCalculatedLayer();
stateNumberVarType getNumWonStates(unsigned int layerNum); StateNumberVarType getNumWonStates(unsigned int layerNum);
stateNumberVarType getNumLostStates(unsigned int layerNum); StateNumberVarType getNumLostStates(unsigned int layerNum);
stateNumberVarType getNumDrawnStates(unsigned int layerNum); StateNumberVarType getNumDrawnStates(unsigned int layerNum);
stateNumberVarType getNumInvalidStates(unsigned int layerNum); StateNumberVarType getNumInvalidStates(unsigned int layerNum);
bool isLayerInDatabase(unsigned int layerNum); bool isLayerInDatabase(unsigned int layerNum);
long long getLayerSizeInBytes(unsigned int layerNum); long long getLayerSizeInBytes(unsigned int layerNum);
void setOutputStream(ostream *theStream, void(*printFunc)(void *pUserData), void *pUserData); void setOutputStream(ostream *theStream, void(*printFunc)(void *pUserData), void *pUserData);
@ -284,7 +284,7 @@ public:
{ {
while (true); while (true);
}; };
virtual void storeValueOfMove(unsigned int threadNo, unsigned int idPossibility, void *pPossibilities, twoBit value, unsigned int *freqValuesSubMoves, plyInfoVarType plyInfo) virtual void storeValueOfMove(unsigned int threadNo, unsigned int idPossibility, void *pPossibilities, TwoBit value, unsigned int *freqValuesSubMoves, PlyInfoVarType plyInfo)
{ {
}; };
virtual void move(unsigned int threadNo, unsigned int idPossibility, bool opponentsMove, void **pBackup, void *pPossibilities) virtual void move(unsigned int threadNo, unsigned int idPossibility, bool opponentsMove, void **pBackup, void *pPossibilities)
@ -330,7 +330,7 @@ public:
while (true); return false; while (true); return false;
}; };
virtual void getValueOfSituation(unsigned int threadNo, float &floatValue, twoBit &shortValue) virtual void getValueOfSituation(unsigned int threadNo, float &floatValue, TwoBit &shortValue)
{ {
while (true); while (true);
}; // value of situation for the initial current player }; // value of situation for the initial current player
@ -350,7 +350,7 @@ public:
{ {
while (true); while (true);
}; };
virtual void getPredecessors(unsigned int threadNo, unsigned int *amountOfPred, retroAnalysisPredVars *predVars) virtual void getPredecessors(unsigned int threadNo, unsigned int *amountOfPred, RetroAnalysisPredVars *predVars)
{ {
while (true); while (true);
}; };
@ -383,8 +383,8 @@ private:
unsigned int curThreadNo; unsigned int curThreadNo;
unsigned int layerNumber; unsigned int layerNumber;
LONGLONG statesProcessed; LONGLONG statesProcessed;
twoBit *subValueInDatabase; TwoBit *subValueInDatabase;
plyInfoVarType *subPlyInfos; PlyInfoVarType *subPlyInfos;
bool *hasCurPlayerChanged; bool *hasCurPlayerChanged;
}; };
@ -511,8 +511,8 @@ private:
struct RetroAnalysisQueueState struct RetroAnalysisQueueState
{ {
stateNumberVarType stateNumber; // state stored in the retro analysis queue. the queue is a buffer containing states to be passed to 'RetroAnalysisThreadVars::statesToProcess' StateNumberVarType stateNumber; // state stored in the retro analysis queue. the queue is a buffer containing states to be passed to 'RetroAnalysisThreadVars::statesToProcess'
plyInfoVarType numPliesTillCurState; // ply number for the stored state PlyInfoVarType numPliesTillCurState; // ply number for the stored state
}; };
struct RetroAnalysisThreadVars // thread specific variables for each thread in the retro analysis struct RetroAnalysisThreadVars // thread specific variables for each thread in the retro analysis
@ -525,7 +525,7 @@ private:
struct retroAnalysisGlobalVars // constant during calculation struct retroAnalysisGlobalVars // constant during calculation
{ {
vector<countArrayVarType *> countArrays; // One count array for each layer in 'layersToCalculate'. (For the nine men's morris game two layers have to considered at once.) vector<CountArrayVarType *> countArrays; // One count array for each layer in 'layersToCalculate'. (For the nine men's morris game two layers have to considered at once.)
vector<bool> layerInitialized; // vector<bool> layerInitialized; //
vector<unsigned int> layersToCalculate; // layers which shall be calculated vector<unsigned int> layersToCalculate; // layers which shall be calculated
long long totalNumKnots; // total numbers of knots which have to be stored in memory long long totalNumKnots; // total numbers of knots which have to be stored in memory
@ -590,7 +590,7 @@ private:
struct AddNumSuccedorsVars : public threadManagerClass::threadVarsArrayItem, public RetroAnalysisDefaultThreadVars struct AddNumSuccedorsVars : public threadManagerClass::threadVarsArrayItem, public RetroAnalysisDefaultThreadVars
{ {
retroAnalysisPredVars predVars[MAX_NUM_PREDECESSORS]; RetroAnalysisPredVars predVars[MAX_NUM_PREDECESSORS];
AddNumSuccedorsVars() AddNumSuccedorsVars()
{ {
@ -669,11 +669,11 @@ private:
void unloadLayer(unsigned int layerNumber); void unloadLayer(unsigned int layerNumber);
void saveHeader(SkvFileHeader *dbH, LayerStats *lStats); void saveHeader(SkvFileHeader *dbH, LayerStats *lStats);
void saveHeader(PlyInfoFileHeader *piH, PlyInfo *pInfo); void saveHeader(PlyInfoFileHeader *piH, PlyInfo *pInfo);
void readKnotValueFromDatabase(unsigned int threadNo, unsigned int &layerNumber, unsigned int &stateNumber, twoBit &knotValue, bool &invalidLayerOrStateNumber, bool &layerInDatabaseAndCompleted); void readKnotValueFromDatabase(unsigned int threadNo, unsigned int &layerNumber, unsigned int &stateNumber, TwoBit &knotValue, bool &invalidLayerOrStateNumber, bool &layerInDatabaseAndCompleted);
void readKnotValueFromDatabase(unsigned int layerNumber, unsigned int stateNumber, twoBit &knotValue); void readKnotValueFromDatabase(unsigned int layerNumber, unsigned int stateNumber, TwoBit &knotValue);
void readPlyInfoFromDatabase(unsigned int layerNumber, unsigned int stateNumber, plyInfoVarType &value); void readPlyInfoFromDatabase(unsigned int layerNumber, unsigned int stateNumber, PlyInfoVarType &value);
void saveKnotValueInDatabase(unsigned int layerNumber, unsigned int stateNumber, twoBit knotValue); void saveKnotValueInDatabase(unsigned int layerNumber, unsigned int stateNumber, TwoBit knotValue);
void savePlyInfoInDatabase(unsigned int layerNumber, unsigned int stateNumber, plyInfoVarType value); void savePlyInfoInDatabase(unsigned int layerNumber, unsigned int stateNumber, PlyInfoVarType value);
void loadBytesFromFile(HANDLE hFile, long long offset, unsigned int numBytes, void *pBytes); void loadBytesFromFile(HANDLE hFile, long long offset, unsigned int numBytes, void *pBytes);
void saveBytesToFile(HANDLE hFile, long long offset, unsigned int numBytes, void *pBytes); void saveBytesToFile(HANDLE hFile, long long offset, unsigned int numBytes, void *pBytes);
void saveLayerToFile(unsigned int layerNumber); void saveLayerToFile(unsigned int layerNumber);
@ -693,7 +693,7 @@ private:
void alphaBetaCalcPlyInfo(Node *knot); void alphaBetaCalcPlyInfo(Node *knot);
void alphaBetaCalcKnotValue(Node *knot); void alphaBetaCalcKnotValue(Node *knot);
void alphaBetaChooseBestMove(Node *knot, RunAlphaBetaVars *rabVars, unsigned int tilLevel, unsigned int *idPossibility, unsigned int maxWonfreqValuesSubMoves); void alphaBetaChooseBestMove(Node *knot, RunAlphaBetaVars *rabVars, unsigned int tilLevel, unsigned int *idPossibility, unsigned int maxWonfreqValuesSubMoves);
void alphaBetaSaveInDatabase(unsigned int threadNo, unsigned int layerNumber, unsigned int stateNumber, twoBit knotValue, plyInfoVarType plyValue, bool invertValue); void alphaBetaSaveInDatabase(unsigned int threadNo, unsigned int layerNumber, unsigned int stateNumber, TwoBit knotValue, PlyInfoVarType plyValue, bool invertValue);
static DWORD initAlphaBetaThreadProc(void *pParameter, int index); static DWORD initAlphaBetaThreadProc(void *pParameter, int index);
static DWORD runAlphaBetaThreadProc(void *pParameter, int index); static DWORD runAlphaBetaThreadProc(void *pParameter, int index);

View File

@ -1,5 +1,5 @@
/*********************************************************************\ /*********************************************************************\
miniMaxAI.h MiniMaxAI.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.
@ -21,18 +21,18 @@
#define VALUE_GAME_WON 1000.0f #define VALUE_GAME_WON 1000.0f
/*** Klassen *********************************************************/ /*** Klassen *********************************************************/
class miniMaxAI : public MillAI, MiniMax class MiniMaxAI : public MillAI, MiniMax
{ {
protected: protected:
// structs // structs
struct possibilityStruct struct Possibility
{ {
unsigned int from[MAX_NUM_POS_MOVES]; unsigned int from[MAX_NUM_POS_MOVES];
unsigned int to[MAX_NUM_POS_MOVES]; unsigned int to[MAX_NUM_POS_MOVES];
}; };
struct backupStruct struct Backup
{ {
float value; float value;
bool gameHasFinished; bool gameHasFinished;
@ -58,8 +58,8 @@ protected:
unsigned int curSearchDepth; // current level unsigned int curSearchDepth; // current level
unsigned int depthOfFullTree; // search depth where the whole tree is explored unsigned int depthOfFullTree; // search depth where the whole tree is explored
unsigned int *idPossibilities; // returned pointer of getPossibilities()-function unsigned int *idPossibilities; // returned pointer of getPossibilities()-function
backupStruct *oldStates; // for undo()-function Backup *oldStates; // for undo()-function
possibilityStruct *possibilities; // for getPossNormalMove()-function Possibility *possibilities; // for getPossNormalMove()-function
// Functions // Functions
unsigned int *getPossSettingPhase(unsigned int *numPossibilities, void **pPossibilities); unsigned int *getPossSettingPhase(unsigned int *numPossibilities, void **pPossibilities);
@ -70,9 +70,9 @@ protected:
inline void updatePossibleMoves(unsigned int stone, Player *stoneOwner, bool stoneRemoved, unsigned int ignoreStone); inline void updatePossibleMoves(unsigned int stone, Player *stoneOwner, bool stoneRemoved, unsigned int ignoreStone);
inline void updateWarning(unsigned int firstStone, unsigned int secondStone); inline void updateWarning(unsigned int firstStone, unsigned int secondStone);
inline void setWarning(unsigned int stoneOne, unsigned int stoneTwo, unsigned int stoneThree); inline void setWarning(unsigned int stoneOne, unsigned int stoneTwo, unsigned int stoneThree);
inline void removeStone(unsigned int from, backupStruct *backup); inline void removeStone(unsigned int from, Backup *backup);
inline void setStone(unsigned int to, backupStruct *backup); inline void setStone(unsigned int to, Backup *backup);
inline void normalMove(unsigned int from, unsigned int to, backupStruct *backup); inline void normalMove(unsigned int from, unsigned int to, Backup *backup);
// Virtual Functions // Virtual Functions
void prepareBestChoiceCalculation(); void prepareBestChoiceCalculation();
@ -80,7 +80,7 @@ protected:
void deletePossibilities(unsigned int threadNo, void *pPossibilities); void deletePossibilities(unsigned int threadNo, void *pPossibilities);
void move(unsigned int threadNo, unsigned int idPossibility, bool opponentsMove, void **pBackup, void *pPossibilities); void move(unsigned int threadNo, unsigned int idPossibility, bool opponentsMove, void **pBackup, void *pPossibilities);
void undo(unsigned int threadNo, unsigned int idPossibility, bool opponentsMove, void *pBackup, void *pPossibilities); void undo(unsigned int threadNo, unsigned int idPossibility, bool opponentsMove, void *pBackup, void *pPossibilities);
void getValueOfSituation(unsigned int threadNo, float &floatValue, twoBit &shortValue); void getValueOfSituation(unsigned int threadNo, float &floatValue, TwoBit &shortValue);
void printMoveInformation(unsigned int threadNo, unsigned int idPossibility, void *pPossibilities); void printMoveInformation(unsigned int threadNo, unsigned int idPossibility, void *pPossibilities);
unsigned int getNumberOfLayers() unsigned int getNumberOfLayers()
@ -124,7 +124,7 @@ protected:
void getSymStateNumWithDoubles(unsigned int threadNo, unsigned int *numSymmetricStates, unsigned int **symStateNumbers) void getSymStateNumWithDoubles(unsigned int threadNo, unsigned int *numSymmetricStates, unsigned int **symStateNumbers)
{ {
}; };
void getPredecessors(unsigned int threadNo, unsigned int *amountOfPred, retroAnalysisPredVars *predVars) void getPredecessors(unsigned int threadNo, unsigned int *amountOfPred, RetroAnalysisPredVars *predVars)
{ {
}; };
void printField(unsigned int threadNo, unsigned char value) void printField(unsigned int threadNo, unsigned char value)
@ -139,8 +139,8 @@ protected:
public: public:
// Constructor / destructor // Constructor / destructor
miniMaxAI(); MiniMaxAI();
~miniMaxAI(); ~MiniMaxAI();
// Functions // Functions
void play(fieldStruct *theField, unsigned int *pushFrom, unsigned int *pushTo); void play(fieldStruct *theField, unsigned int *pushFrom, unsigned int *pushTo);

View File

@ -25,7 +25,7 @@ public:
virtual void setVisibility(bool visible) virtual void setVisibility(bool visible)
{ {
}; };
virtual void setState(unsigned int curShowedLayer, MiniMax::stateNumberVarType curShowedState) virtual void setState(unsigned int curShowedLayer, MiniMax::StateNumberVarType curShowedState)
{ {
}; };
}; };
@ -64,7 +64,7 @@ protected:
miniMaxGuiField *pGuiField = nullptr; miniMaxGuiField *pGuiField = nullptr;
bool showingInspectionControls = false; bool showingInspectionControls = false;
unsigned int curShowedLayer = 0; // current showed layer unsigned int curShowedLayer = 0; // current showed layer
MiniMax::stateNumberVarType curShowedState = 0; // current showed state MiniMax::StateNumberVarType curShowedState = 0; // current showed state
const unsigned int scrollBarWidth = 20; const unsigned int scrollBarWidth = 20;
public: public:

View File

@ -44,7 +44,7 @@ bool MiniMax::calcKnotValuesByAlphaBeta(unsigned int layerNumber)
// Name: saveKnotValueInDatabase() // Name: saveKnotValueInDatabase()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void MiniMax::alphaBetaSaveInDatabase(unsigned int threadNo, unsigned int layerNumber, unsigned int stateNumber, twoBit knotValue, plyInfoVarType plyValue, bool invertValue) void MiniMax::alphaBetaSaveInDatabase(unsigned int threadNo, unsigned int layerNumber, unsigned int stateNumber, TwoBit knotValue, PlyInfoVarType plyValue, bool invertValue)
{ {
// locals // locals
unsigned int *symStateNumbers = nullptr; unsigned int *symStateNumbers = nullptr;
@ -160,8 +160,8 @@ DWORD MiniMax::initAlphaBetaThreadProc(void *pParameter, int index)
MiniMax *m = iabVars->pMiniMax; MiniMax *m = iabVars->pMiniMax;
float floatValue; // dummy variable for calls of getValueOfSituation() float floatValue; // dummy variable for calls of getValueOfSituation()
StateAdress curState; // current state counter for loops StateAdress curState; // current state counter for loops
twoBit curStateValue = 0; // for calls of getValueOfSituation() TwoBit curStateValue = 0; // for calls of getValueOfSituation()
plyInfoVarType plyInfo; // depends on the curStateValue PlyInfoVarType plyInfo; // depends on the curStateValue
curState.layerNumber = iabVars->layerNumber; curState.layerNumber = iabVars->layerNumber;
curState.stateNumber = index; curState.stateNumber = index;
@ -175,7 +175,7 @@ DWORD MiniMax::initAlphaBetaThreadProc(void *pParameter, int index)
// layer initialization already done ? if so, then read from file // layer initialization already done ? if so, then read from file
if (iabVars->initAlreadyDone) { if (iabVars->initAlreadyDone) {
if (!iabVars->bufferedFile->readBytes(iabVars->curThreadNo, index * sizeof(twoBit), sizeof(twoBit), (unsigned char *)&curStateValue)) { if (!iabVars->bufferedFile->readBytes(iabVars->curThreadNo, index * sizeof(TwoBit), sizeof(TwoBit), (unsigned char *)&curStateValue)) {
PRINT(0, m, "ERROR: initArray->takeBytes() failed"); PRINT(0, m, "ERROR: initArray->takeBytes() failed");
return m->falseOrStop(); return m->falseOrStop();
} }
@ -205,7 +205,7 @@ DWORD MiniMax::initAlphaBetaThreadProc(void *pParameter, int index)
// write data to file // write data to file
if (!iabVars->initAlreadyDone) { if (!iabVars->initAlreadyDone) {
if (!iabVars->bufferedFile->writeBytes(iabVars->curThreadNo, index * sizeof(twoBit), sizeof(twoBit), (unsigned char *)&curStateValue)) { if (!iabVars->bufferedFile->writeBytes(iabVars->curThreadNo, index * sizeof(TwoBit), sizeof(TwoBit), (unsigned char *)&curStateValue)) {
PRINT(0, m, "ERROR: bufferedFile->writeBytes failed!"); PRINT(0, m, "ERROR: bufferedFile->writeBytes failed!");
return m->falseOrStop(); return m->falseOrStop();
} }
@ -271,7 +271,7 @@ DWORD MiniMax::runAlphaBetaThreadProc(void *pParameter, int index)
MiniMax *m = rabVars->pMiniMax; MiniMax *m = rabVars->pMiniMax;
StateAdress curState; // current state counter for loops StateAdress curState; // current state counter for loops
Node root; // Node root; //
plyInfoVarType plyInfo; // depends on the curStateValue PlyInfoVarType plyInfo; // depends on the curStateValue
curState.layerNumber = rabVars->layerNumber; curState.layerNumber = rabVars->layerNumber;
curState.stateNumber = index; curState.stateNumber = index;
@ -392,8 +392,8 @@ bool MiniMax::alphaBetaTryDataBase(Node *knot, RunAlphaBetaVars *rabVars, unsign
// locals // locals
bool invalidLayerOrStateNumber; bool invalidLayerOrStateNumber;
bool subLayerInDatabaseAndCompleted; bool subLayerInDatabaseAndCompleted;
twoBit shortKnotValue = SKV_VALUE_INVALID; TwoBit shortKnotValue = SKV_VALUE_INVALID;
plyInfoVarType plyInfo = PLYINFO_VALUE_UNCALCULATED; PlyInfoVarType plyInfo = PLYINFO_VALUE_UNCALCULATED;
// use database ? // use database ?
if (hFilePlyInfo != nullptr && hFileShortKnotValues != nullptr && (calcDatabase || layerInDatabase)) { if (hFilePlyInfo != nullptr && hFileShortKnotValues != nullptr && (calcDatabase || layerInDatabase)) {
@ -553,8 +553,8 @@ void MiniMax::alphaBetaCalcPlyInfo(Node *knot)
// locals // locals
unsigned int i; unsigned int i;
unsigned int maxBranch; unsigned int maxBranch;
plyInfoVarType maxPlyInfo; PlyInfoVarType maxPlyInfo;
twoBit shortKnotValue; TwoBit shortKnotValue;
// //
if (knot->shortValue == SKV_VALUE_GAME_DRAWN) { if (knot->shortValue == SKV_VALUE_GAME_DRAWN) {

View File

@ -325,7 +325,7 @@ void MiniMax::openPlyInfoFile(const char *directory)
plyInfos[i].plyInfoCompressed = nullptr; plyInfos[i].plyInfoCompressed = nullptr;
plyInfos[i].plyInfoIsLoaded = false; plyInfos[i].plyInfoIsLoaded = false;
plyInfos[i].plyInfoIsCompletedAndInFile = false; plyInfos[i].plyInfoIsCompletedAndInFile = false;
plyInfos[i].sizeInBytes = plyInfos[i].knotsInLayer * sizeof(plyInfoVarType); plyInfos[i].sizeInBytes = plyInfos[i].knotsInLayer * sizeof(PlyInfoVarType);
} }
for (i = 1; i < plyInfoHeader.numLayers; i++) { for (i = 1; i < plyInfoHeader.numLayers; i++) {
@ -407,7 +407,7 @@ inline void MiniMax::measureIops(long long &numOperations, LARGE_INTEGER &interv
// Name: readKnotValueFromDatabase() // Name: readKnotValueFromDatabase()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void MiniMax::readKnotValueFromDatabase(unsigned int threadNo, unsigned int &layerNumber, unsigned int &stateNumber, twoBit &knotValue, bool &invalidLayerOrStateNumber, bool &layerInDatabaseAndCompleted) void MiniMax::readKnotValueFromDatabase(unsigned int threadNo, unsigned int &layerNumber, unsigned int &stateNumber, TwoBit &knotValue, bool &invalidLayerOrStateNumber, bool &layerInDatabaseAndCompleted)
{ {
// get state number, since this is the address, where the value is saved // get state number, since this is the address, where the value is saved
getLayerAndStateNumber(threadNo, layerNumber, stateNumber); getLayerAndStateNumber(threadNo, layerNumber, stateNumber);
@ -436,12 +436,12 @@ void MiniMax::readKnotValueFromDatabase(unsigned int threadNo, unsigned int &lay
// Name: readKnotValueFromDatabase() // Name: readKnotValueFromDatabase()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void MiniMax::readKnotValueFromDatabase(unsigned int layerNumber, unsigned int stateNumber, twoBit &knotValue) void MiniMax::readKnotValueFromDatabase(unsigned int layerNumber, unsigned int stateNumber, TwoBit &knotValue)
{ {
// locals // locals
twoBit databaseByte; TwoBit databaseByte;
long long bytesAllocated; long long bytesAllocated;
twoBit defValue = SKV_WHOLE_BYTE_IS_INVALID; TwoBit defValue = SKV_WHOLE_BYTE_IS_INVALID;
LayerStats *myLss = &layerStats[layerNumber]; LayerStats *myLss = &layerStats[layerNumber];
// valid state and layer number ? // valid state and layer number ?
@ -502,11 +502,11 @@ void MiniMax::readKnotValueFromDatabase(unsigned int layerNumber, unsigned int s
// Name: readPlyInfoFromDatabase() // Name: readPlyInfoFromDatabase()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void MiniMax::readPlyInfoFromDatabase(unsigned int layerNumber, unsigned int stateNumber, plyInfoVarType &value) void MiniMax::readPlyInfoFromDatabase(unsigned int layerNumber, unsigned int stateNumber, PlyInfoVarType &value)
{ {
// locals // locals
unsigned int curKnot; unsigned int curKnot;
plyInfoVarType defValue = PLYINFO_VALUE_UNCALCULATED; PlyInfoVarType defValue = PLYINFO_VALUE_UNCALCULATED;
long long bytesAllocated; long long bytesAllocated;
PlyInfo *myPis = &plyInfos[layerNumber]; PlyInfo *myPis = &plyInfos[layerNumber];
@ -520,7 +520,7 @@ void MiniMax::readPlyInfoFromDatabase(unsigned int layerNumber, unsigned int sta
// if database is complete get whole byte from file // if database is complete get whole byte from file
if (plyInfoHeader.plyInfoCompleted || layerInDatabase || myPis->plyInfoIsCompletedAndInFile) { if (plyInfoHeader.plyInfoCompleted || layerInDatabase || myPis->plyInfoIsCompletedAndInFile) {
EnterCriticalSection(&csDatabase); EnterCriticalSection(&csDatabase);
loadBytesFromFile(hFilePlyInfo, plyInfoHeader.headerAndPlyInfosSize + myPis->layerOffset + sizeof(plyInfoVarType) * stateNumber, sizeof(plyInfoVarType), &value); loadBytesFromFile(hFilePlyInfo, plyInfoHeader.headerAndPlyInfosSize + myPis->layerOffset + sizeof(PlyInfoVarType) * stateNumber, sizeof(PlyInfoVarType), &value);
LeaveCriticalSection(&csDatabase); LeaveCriticalSection(&csDatabase);
} else { } else {
@ -529,7 +529,7 @@ void MiniMax::readPlyInfoFromDatabase(unsigned int layerNumber, unsigned int sta
EnterCriticalSection(&csDatabase); EnterCriticalSection(&csDatabase);
if (!myPis->plyInfoIsLoaded) { if (!myPis->plyInfoIsLoaded) {
// if layer is in database and completed, then load layer from file into memory; set default value otherwise // if layer is in database and completed, then load layer from file into memory; set default value otherwise
myPis->plyInfo = new plyInfoVarType[myPis->knotsInLayer]; myPis->plyInfo = new PlyInfoVarType[myPis->knotsInLayer];
if (myPis->plyInfoIsCompletedAndInFile) { if (myPis->plyInfoIsCompletedAndInFile) {
loadBytesFromFile(hFilePlyInfo, plyInfoHeader.headerAndPlyInfosSize + myPis->layerOffset, myPis->sizeInBytes, myPis->plyInfo); loadBytesFromFile(hFilePlyInfo, plyInfoHeader.headerAndPlyInfosSize + myPis->layerOffset, myPis->sizeInBytes, myPis->plyInfo);
} else { } else {
@ -564,11 +564,11 @@ void MiniMax::readPlyInfoFromDatabase(unsigned int layerNumber, unsigned int sta
// Name: saveKnotValueInDatabase() // Name: saveKnotValueInDatabase()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void MiniMax::saveKnotValueInDatabase(unsigned int layerNumber, unsigned int stateNumber, twoBit knotValue) void MiniMax::saveKnotValueInDatabase(unsigned int layerNumber, unsigned int stateNumber, TwoBit knotValue)
{ {
// locals // locals
long long bytesAllocated; long long bytesAllocated;
twoBit defValue = SKV_WHOLE_BYTE_IS_INVALID; TwoBit defValue = SKV_WHOLE_BYTE_IS_INVALID;
LayerStats *myLss = &layerStats[layerNumber]; LayerStats *myLss = &layerStats[layerNumber];
// valid state and layer number ? // valid state and layer number ?
@ -589,7 +589,7 @@ void MiniMax::saveKnotValueInDatabase(unsigned int layerNumber, unsigned int sta
EnterCriticalSection(&csDatabase); EnterCriticalSection(&csDatabase);
if (!myLss->layerIsLoaded) { if (!myLss->layerIsLoaded) {
// reserve memory for this layer & create array for ply info with default value // reserve memory for this layer & create array for ply info with default value
myLss->shortKnotValueByte = new twoBit[myLss->sizeInBytes]; myLss->shortKnotValueByte = new TwoBit[myLss->sizeInBytes];
memset(myLss->shortKnotValueByte, SKV_WHOLE_BYTE_IS_INVALID, myLss->sizeInBytes); memset(myLss->shortKnotValueByte, SKV_WHOLE_BYTE_IS_INVALID, myLss->sizeInBytes);
bytesAllocated = myLss->sizeInBytes; bytesAllocated = myLss->sizeInBytes;
arrayInfos.addArray(layerNumber, ArrayInfo::arrayType_layerStats, myLss->sizeInBytes, 0); arrayInfos.addArray(layerNumber, ArrayInfo::arrayType_layerStats, myLss->sizeInBytes, 0);
@ -627,11 +627,11 @@ void MiniMax::saveKnotValueInDatabase(unsigned int layerNumber, unsigned int sta
// Name: savePlyInfoInDatabase() // Name: savePlyInfoInDatabase()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void MiniMax::savePlyInfoInDatabase(unsigned int layerNumber, unsigned int stateNumber, plyInfoVarType value) void MiniMax::savePlyInfoInDatabase(unsigned int layerNumber, unsigned int stateNumber, PlyInfoVarType value)
{ {
// locals // locals
unsigned int curKnot; unsigned int curKnot;
plyInfoVarType defValue = PLYINFO_VALUE_UNCALCULATED; PlyInfoVarType defValue = PLYINFO_VALUE_UNCALCULATED;
long long bytesAllocated; long long bytesAllocated;
PlyInfo *myPis = &plyInfos[layerNumber]; PlyInfo *myPis = &plyInfos[layerNumber];
@ -653,7 +653,7 @@ void MiniMax::savePlyInfoInDatabase(unsigned int layerNumber, unsigned int state
EnterCriticalSection(&csDatabase); EnterCriticalSection(&csDatabase);
if (!myPis->plyInfoIsLoaded) { if (!myPis->plyInfoIsLoaded) {
// reserve memory for this layer & create array for ply info with default value // reserve memory for this layer & create array for ply info with default value
myPis->plyInfo = new plyInfoVarType[myPis->knotsInLayer]; myPis->plyInfo = new PlyInfoVarType[myPis->knotsInLayer];
for (curKnot = 0; curKnot < myPis->knotsInLayer; curKnot++) { for (curKnot = 0; curKnot < myPis->knotsInLayer; curKnot++) {
myPis->plyInfo[curKnot] = defValue; myPis->plyInfo[curKnot] = defValue;
} }

View File

@ -92,8 +92,8 @@ freeMem:
} }
for (curLayer = 0; curLayer < layersToCalculate.size(); curLayer++) { for (curLayer = 0; curLayer < layersToCalculate.size(); curLayer++) {
if (retroVars.countArrays[curLayer] != nullptr) { if (retroVars.countArrays[curLayer] != nullptr) {
memoryUsed2 -= layerStats[layersToCalculate[curLayer]].knotsInLayer * sizeof(countArrayVarType); memoryUsed2 -= layerStats[layersToCalculate[curLayer]].knotsInLayer * sizeof(CountArrayVarType);
arrayInfos.removeArray(layersToCalculate[curLayer], ArrayInfo::arrayType_countArray, layerStats[layersToCalculate[curLayer]].knotsInLayer * sizeof(countArrayVarType), 0); arrayInfos.removeArray(layersToCalculate[curLayer], ArrayInfo::arrayType_countArray, layerStats[layersToCalculate[curLayer]].knotsInLayer * sizeof(CountArrayVarType), 0);
} }
SAFE_DELETE_ARRAY(retroVars.countArrays[curLayer]); SAFE_DELETE_ARRAY(retroVars.countArrays[curLayer]);
} }
@ -191,7 +191,7 @@ DWORD MiniMax::initRetroAnalysisThreadProc(void *pParameter, int index)
MiniMax *m = iraVars->pMiniMax; MiniMax *m = iraVars->pMiniMax;
float floatValue; // dummy variable for calls of getValueOfSituation() float floatValue; // dummy variable for calls of getValueOfSituation()
StateAdress curState; // current state counter for loops StateAdress curState; // current state counter for loops
twoBit curStateValue; // for calls of getValueOfSituation() TwoBit curStateValue; // for calls of getValueOfSituation()
curState.layerNumber = iraVars->layerNumber; curState.layerNumber = iraVars->layerNumber;
curState.stateNumber = index; curState.stateNumber = index;
@ -205,7 +205,7 @@ DWORD MiniMax::initRetroAnalysisThreadProc(void *pParameter, int index)
// layer initialization already done ? if so, then read from file // layer initialization already done ? if so, then read from file
if (iraVars->initAlreadyDone) { if (iraVars->initAlreadyDone) {
if (!iraVars->bufferedFile->readBytes(iraVars->curThreadNo, index * sizeof(twoBit), sizeof(twoBit), (unsigned char *)&curStateValue)) { if (!iraVars->bufferedFile->readBytes(iraVars->curThreadNo, index * sizeof(TwoBit), sizeof(TwoBit), (unsigned char *)&curStateValue)) {
PRINT(0, m, "ERROR: initArray->takeBytes() failed"); PRINT(0, m, "ERROR: initArray->takeBytes() failed");
return m->falseOrStop(); return m->falseOrStop();
} }
@ -242,7 +242,7 @@ DWORD MiniMax::initRetroAnalysisThreadProc(void *pParameter, int index)
// write data to file // write data to file
if (!iraVars->initAlreadyDone) { if (!iraVars->initAlreadyDone) {
// curStateValue sollte 2 sein bei index == 1329322 // curStateValue sollte 2 sein bei index == 1329322
if (!iraVars->bufferedFile->writeBytes(iraVars->curThreadNo, index * sizeof(twoBit), sizeof(twoBit), (unsigned char *)&curStateValue)) { if (!iraVars->bufferedFile->writeBytes(iraVars->curThreadNo, index * sizeof(TwoBit), sizeof(TwoBit), (unsigned char *)&curStateValue)) {
PRINT(0, m, "ERROR: bufferedFile->writeBytes failed!"); PRINT(0, m, "ERROR: bufferedFile->writeBytes failed!");
return m->falseOrStop(); return m->falseOrStop();
} }
@ -262,7 +262,7 @@ bool MiniMax::prepareCountArrays(retroAnalysisGlobalVars &retroVars)
unsigned int numKnotsInCurLayer; unsigned int numKnotsInCurLayer;
StateAdress curState; // current state counter for loops StateAdress curState; // current state counter for loops
unsigned int curLayer = 0; // Counter variable unsigned int curLayer = 0; // Counter variable
countArrayVarType defValue = 0; // default counter array value CountArrayVarType defValue = 0; // default counter array value
DWORD dwWritten; DWORD dwWritten;
DWORD dwRead; DWORD dwRead;
LARGE_INTEGER fileSize; LARGE_INTEGER fileSize;
@ -288,9 +288,9 @@ bool MiniMax::prepareCountArrays(retroAnalysisGlobalVars &retroVars)
// allocate memory for count arrays // allocate memory for count arrays
for (curLayer = 0; curLayer < retroVars.layersToCalculate.size(); curLayer++) { for (curLayer = 0; curLayer < retroVars.layersToCalculate.size(); curLayer++) {
numKnotsInCurLayer = layerStats[retroVars.layersToCalculate[curLayer]].knotsInLayer; numKnotsInCurLayer = layerStats[retroVars.layersToCalculate[curLayer]].knotsInLayer;
retroVars.countArrays[curLayer] = new countArrayVarType[numKnotsInCurLayer]; retroVars.countArrays[curLayer] = new CountArrayVarType[numKnotsInCurLayer];
memoryUsed2 += numKnotsInCurLayer * sizeof(countArrayVarType); memoryUsed2 += numKnotsInCurLayer * sizeof(CountArrayVarType);
arrayInfos.addArray(retroVars.layersToCalculate[curLayer], ArrayInfo::arrayType_countArray, numKnotsInCurLayer * sizeof(countArrayVarType), 0); arrayInfos.addArray(retroVars.layersToCalculate[curLayer], ArrayInfo::arrayType_countArray, numKnotsInCurLayer * sizeof(CountArrayVarType), 0);
} }
// load file if already existend // load file if already existend
@ -299,8 +299,8 @@ bool MiniMax::prepareCountArrays(retroAnalysisGlobalVars &retroVars)
for (curLayer = 0; curLayer < retroVars.layersToCalculate.size(); curLayer++) { for (curLayer = 0; curLayer < retroVars.layersToCalculate.size(); curLayer++) {
numKnotsInCurLayer = layerStats[retroVars.layersToCalculate[curLayer]].knotsInLayer; numKnotsInCurLayer = layerStats[retroVars.layersToCalculate[curLayer]].knotsInLayer;
if (!ReadFile(hFileCountArray, retroVars.countArrays[curLayer], numKnotsInCurLayer * sizeof(countArrayVarType), &dwRead, nullptr)) return falseOrStop(); if (!ReadFile(hFileCountArray, retroVars.countArrays[curLayer], numKnotsInCurLayer * sizeof(CountArrayVarType), &dwRead, nullptr)) return falseOrStop();
if (dwRead != numKnotsInCurLayer * sizeof(countArrayVarType)) return falseOrStop(); if (dwRead != numKnotsInCurLayer * sizeof(CountArrayVarType)) return falseOrStop();
} }
// else calculate number of succedding states // else calculate number of succedding states
@ -323,8 +323,8 @@ bool MiniMax::prepareCountArrays(retroAnalysisGlobalVars &retroVars)
// save to file // save to file
for (curLayer = 0, dwWritten = 0; curLayer < retroVars.layersToCalculate.size(); curLayer++) { for (curLayer = 0, dwWritten = 0; curLayer < retroVars.layersToCalculate.size(); curLayer++) {
numKnotsInCurLayer = layerStats[retroVars.layersToCalculate[curLayer]].knotsInLayer; numKnotsInCurLayer = layerStats[retroVars.layersToCalculate[curLayer]].knotsInLayer;
if (!WriteFile(hFileCountArray, retroVars.countArrays[curLayer], numKnotsInCurLayer * sizeof(countArrayVarType), &dwWritten, nullptr)) return falseOrStop(); if (!WriteFile(hFileCountArray, retroVars.countArrays[curLayer], numKnotsInCurLayer * sizeof(CountArrayVarType), &dwWritten, nullptr)) return falseOrStop();
if (dwWritten != numKnotsInCurLayer * sizeof(countArrayVarType)) return falseOrStop(); if (dwWritten != numKnotsInCurLayer * sizeof(CountArrayVarType)) return falseOrStop();
} }
PRINT(2, this, " Count array saved to file: " << ssCountArrayFilePath.str()); PRINT(2, this, " Count array saved to file: " << ssCountArrayFilePath.str());
} }
@ -440,15 +440,15 @@ DWORD MiniMax::addNumSuccedorsThreadProc(void *pParameter, int index)
unsigned int curLayerId; // current processed layer within 'layersToCalculate' unsigned int curLayerId; // current processed layer within 'layersToCalculate'
unsigned int amountOfPred; unsigned int amountOfPred;
unsigned int curPred; unsigned int curPred;
countArrayVarType countValue; CountArrayVarType countValue;
StateAdress predState; StateAdress predState;
StateAdress curState; StateAdress curState;
twoBit curStateValue; TwoBit curStateValue;
plyInfoVarType numPlies; // number of plies of the current considered succeding state PlyInfoVarType numPlies; // number of plies of the current considered succeding state
bool cuStateAddedToProcessQueue = false; bool cuStateAddedToProcessQueue = false;
curState.layerNumber = ansVars->layerNumber; curState.layerNumber = ansVars->layerNumber;
curState.stateNumber = (stateNumberVarType)index; curState.stateNumber = (StateNumberVarType)index;
// print status // print status
ansVars->statesProcessed++; ansVars->statesProcessed++;
@ -491,14 +491,14 @@ DWORD MiniMax::addNumSuccedorsThreadProc(void *pParameter, int index)
} }
// add this state as possible move // add this state as possible move
long *pCountValue = ((long *)ansVars->retroVars->countArrays[curLayerId]) + predState.stateNumber / (sizeof(long) / sizeof(countArrayVarType)); long *pCountValue = ((long *)ansVars->retroVars->countArrays[curLayerId]) + predState.stateNumber / (sizeof(long) / sizeof(CountArrayVarType));
long numBitsToShift = sizeof(countArrayVarType) * 8 * (predState.stateNumber % (sizeof(long) / sizeof(countArrayVarType))); // little-endian byte-order long numBitsToShift = sizeof(CountArrayVarType) * 8 * (predState.stateNumber % (sizeof(long) / sizeof(CountArrayVarType))); // little-endian byte-order
long mask = 0x000000ff << numBitsToShift; long mask = 0x000000ff << numBitsToShift;
long curCountLong, newCountLong; long curCountLong, newCountLong;
do { do {
curCountLong = *pCountValue; curCountLong = *pCountValue;
countValue = (countArrayVarType)((curCountLong & mask) >> numBitsToShift); countValue = (CountArrayVarType)((curCountLong & mask) >> numBitsToShift);
if (countValue == 255) { if (countValue == 255) {
PRINT(0, m, "ERROR: maximum value for Count[] reached!"); PRINT(0, m, "ERROR: maximum value for Count[] reached!");
return TM_RETURN_VALUE_TERMINATE_ALL_THREADS; return TM_RETURN_VALUE_TERMINATE_ALL_THREADS;
@ -521,7 +521,7 @@ bool MiniMax::performRetroAnalysis(retroAnalysisGlobalVars &retroVars)
{ {
// locals // locals
StateAdress curState; // current state counter for loops StateAdress curState; // current state counter for loops
twoBit curStateValue; // current state value TwoBit curStateValue; // current state value
unsigned int curLayerId; // current processed layer within 'layersToCalculate' unsigned int curLayerId; // current processed layer within 'layersToCalculate'
PRINT(2, this, " *** Begin Iteration ***"); PRINT(2, this, " *** Begin Iteration ***");
@ -576,21 +576,21 @@ DWORD MiniMax::performRetroAnalysisThreadProc(void *pParameter)
unsigned int threadNo = m->threadManager.getThreadNumber(); unsigned int threadNo = m->threadManager.getThreadNumber();
RetroAnalysisThreadVars *threadVars = &retroVars->thread[threadNo]; RetroAnalysisThreadVars *threadVars = &retroVars->thread[threadNo];
twoBit predStateValue; TwoBit predStateValue;
unsigned int curLayerId; // current processed layer within 'layersToCalculate' unsigned int curLayerId; // current processed layer within 'layersToCalculate'
unsigned int amountOfPred; // total numbers of predecessors and current considered one unsigned int amountOfPred; // total numbers of predecessors and current considered one
unsigned int curPred; unsigned int curPred;
unsigned int threadCounter; unsigned int threadCounter;
long long numStatesProcessed; long long numStatesProcessed;
long long totalNumStatesToProcess; long long totalNumStatesToProcess;
plyInfoVarType curNumPlies; PlyInfoVarType curNumPlies;
plyInfoVarType numPliesTillCurState; PlyInfoVarType numPliesTillCurState;
plyInfoVarType numPliesTillPredState; PlyInfoVarType numPliesTillPredState;
countArrayVarType countValue; CountArrayVarType countValue;
StateAdress predState; StateAdress predState;
StateAdress curState; // current state counter for while-loop StateAdress curState; // current state counter for while-loop
twoBit curStateValue; // current state value TwoBit curStateValue; // current state value
retroAnalysisPredVars predVars[MAX_NUM_PREDECESSORS]; RetroAnalysisPredVars predVars[MAX_NUM_PREDECESSORS];
for (numStatesProcessed = 0, curNumPlies = 0; curNumPlies < threadVars->statesToProcess.size(); curNumPlies++) { for (numStatesProcessed = 0, curNumPlies = 0; curNumPlies < threadVars->statesToProcess.size(); curNumPlies++) {
@ -672,14 +672,14 @@ DWORD MiniMax::performRetroAnalysisThreadProc(void *pParameter)
// if current state is a won game, then this state is not an option any more for all predecessors // if current state is a won game, then this state is not an option any more for all predecessors
} else { } else {
// reduce count value by one // reduce count value by one
long *pCountValue = ((long *)retroVars->countArrays[curLayerId]) + predState.stateNumber / (sizeof(long) / sizeof(countArrayVarType)); long *pCountValue = ((long *)retroVars->countArrays[curLayerId]) + predState.stateNumber / (sizeof(long) / sizeof(CountArrayVarType));
long numBitsToShift = sizeof(countArrayVarType) * 8 * (predState.stateNumber % (sizeof(long) / sizeof(countArrayVarType))); // little-endian byte-order long numBitsToShift = sizeof(CountArrayVarType) * 8 * (predState.stateNumber % (sizeof(long) / sizeof(CountArrayVarType))); // little-endian byte-order
long mask = 0x000000ff << numBitsToShift; long mask = 0x000000ff << numBitsToShift;
long curCountLong, newCountLong; long curCountLong, newCountLong;
do { do {
curCountLong = *pCountValue; curCountLong = *pCountValue;
countValue = (countArrayVarType)((curCountLong & mask) >> numBitsToShift); countValue = (CountArrayVarType)((curCountLong & mask) >> numBitsToShift);
if (countValue > 0) { if (countValue > 0) {
countValue--; countValue--;
newCountLong = (curCountLong & (~mask)) + (countValue << numBitsToShift); newCountLong = (curCountLong & (~mask)) + (countValue << numBitsToShift);

View File

@ -8,8 +8,8 @@
struct RetroAnalysisQueueState struct RetroAnalysisQueueState
{ {
stateNumberVarType stateNumber; // state stored in the retro analysis queue. the queue is a buffer containing states to be passed to 'RetroAnalysisThreadVars::statesToProcess' StateNumberVarType stateNumber; // state stored in the retro analysis queue. the queue is a buffer containing states to be passed to 'RetroAnalysisThreadVars::statesToProcess'
plyInfoVarType numPliesTillCurState; // ply number for the stored state PlyInfoVarType numPliesTillCurState; // ply number for the stored state
}; };
struct RetroAnalysisThreadVars // thread specific variables for each thread in the retro analysis struct RetroAnalysisThreadVars // thread specific variables for each thread in the retro analysis
@ -20,9 +20,9 @@ struct RetroAnalysisThreadVars // thread specific variables for each t
unsigned int threadNo; unsigned int threadNo;
}; };
struct retroAnalysisVars // constant during calculation struct RetroAnalysisVars // constant during calculation
{ {
vector<countArrayVarType *> countArrays; // One count array for each layer in 'layersToCalculate'. (For the nine men's morris game two layers have to considered at once.) vector<CountArrayVarType *> countArrays; // One count array for each layer in 'layersToCalculate'. (For the nine men's morris game two layers have to considered at once.)
vector<compressorClass::compressedArrayClass *> countArraysCompr; // '' but compressed vector<compressorClass::compressedArrayClass *> countArraysCompr; // '' but compressed
vector<bool> layerInitialized; // vector<bool> layerInitialized; //
vector<unsigned int> layersToCalculate; // layers which shall be calculated vector<unsigned int> layersToCalculate; // layers which shall be calculated
@ -39,7 +39,7 @@ struct InitRetroAnalysisVars
LONGLONG statesProcessed; LONGLONG statesProcessed;
unsigned int statsValueCounter[SKV_NUM_VALUES]; unsigned int statsValueCounter[SKV_NUM_VALUES];
BufferedFile *bufferedFile; BufferedFile *bufferedFile;
retroAnalysisVars *retroVars; RetroAnalysisVars *retroVars;
bool initAlreadyDone; // true if the initialization information is already available in a file bool initAlreadyDone; // true if the initialization information is already available in a file
}; };
@ -49,10 +49,10 @@ struct addSuccLayersVars
unsigned int curThreadNo; unsigned int curThreadNo;
unsigned int statsValueCounter[SKV_NUM_VALUES]; unsigned int statsValueCounter[SKV_NUM_VALUES];
unsigned int layerNumber; unsigned int layerNumber;
retroAnalysisVars *retroVars; RetroAnalysisVars *retroVars;
}; };
struct retroAnalysisPredVars struct RetroAnalysisPredVars
{ {
unsigned int predStateNumbers; unsigned int predStateNumbers;
unsigned int predLayerNumbers; unsigned int predLayerNumbers;
@ -66,6 +66,6 @@ struct AddNumSuccedorsVars
unsigned int curThreadNo; unsigned int curThreadNo;
unsigned int layerNumber; unsigned int layerNumber;
LONGLONG statesProcessed; LONGLONG statesProcessed;
retroAnalysisVars *retroVars; RetroAnalysisVars *retroVars;
retroAnalysisPredVars *predVars; RetroAnalysisPredVars *predVars;
}; };

View File

@ -61,7 +61,7 @@ long long MiniMax::getLayerSizeInBytes(unsigned int layerNum)
// Name: getNumWonStates() // Name: getNumWonStates()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
MiniMax::stateNumberVarType MiniMax::getNumWonStates(unsigned int layerNum) MiniMax::StateNumberVarType MiniMax::getNumWonStates(unsigned int layerNum)
{ {
if (layerStats == nullptr) return 0; if (layerStats == nullptr) return 0;
return layerStats[layerNum].numWonStates; return layerStats[layerNum].numWonStates;
@ -71,7 +71,7 @@ MiniMax::stateNumberVarType MiniMax::getNumWonStates(unsigned int layerNum)
// Name: getNumLostStates() // Name: getNumLostStates()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
MiniMax::stateNumberVarType MiniMax::getNumLostStates(unsigned int layerNum) MiniMax::StateNumberVarType MiniMax::getNumLostStates(unsigned int layerNum)
{ {
if (layerStats == nullptr) return 0; if (layerStats == nullptr) return 0;
return layerStats[layerNum].numLostStates; return layerStats[layerNum].numLostStates;
@ -81,7 +81,7 @@ MiniMax::stateNumberVarType MiniMax::getNumLostStates(unsigned int layerNum)
// Name: getNumDrawnStates() // Name: getNumDrawnStates()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
MiniMax::stateNumberVarType MiniMax::getNumDrawnStates(unsigned int layerNum) MiniMax::StateNumberVarType MiniMax::getNumDrawnStates(unsigned int layerNum)
{ {
if (layerStats == nullptr) return 0; if (layerStats == nullptr) return 0;
return layerStats[layerNum].numDrawnStates; return layerStats[layerNum].numDrawnStates;
@ -91,7 +91,7 @@ MiniMax::stateNumberVarType MiniMax::getNumDrawnStates(unsigned int layerNum)
// Name: getNumInvalidStates() // Name: getNumInvalidStates()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
MiniMax::stateNumberVarType MiniMax::getNumInvalidStates(unsigned int layerNum) MiniMax::StateNumberVarType MiniMax::getNumInvalidStates(unsigned int layerNum)
{ {
if (layerStats == nullptr) return 0; if (layerStats == nullptr) return 0;
return layerStats[layerNum].numInvalidStates; return layerStats[layerNum].numInvalidStates;
@ -137,7 +137,7 @@ void MiniMax::showLayerStats(unsigned int layerNumber)
// locals // locals
StateAdress curState; StateAdress curState;
unsigned int statsValueCounter[] = { 0,0,0,0 }; unsigned int statsValueCounter[] = { 0,0,0,0 };
twoBit curStateValue; TwoBit curStateValue;
// calc and show statistics // calc and show statistics
for (curState.layerNumber = layerNumber, curState.stateNumber = 0; curState.stateNumber < layerStats[curState.layerNumber].knotsInLayer; curState.stateNumber++) { for (curState.layerNumber = layerNumber, curState.stateNumber = 0; curState.stateNumber < layerStats[curState.layerNumber].knotsInLayer; curState.stateNumber++) {
@ -172,7 +172,7 @@ bool MiniMax::calcLayerStatistics(char *statisticsFileName)
DWORD dwBytesWritten; DWORD dwBytesWritten;
StateAdress curState; StateAdress curState;
unsigned int *statsValueCounter; unsigned int *statsValueCounter;
twoBit curStateValue; TwoBit curStateValue;
char line[10000]; char line[10000];
string text(""); string text("");

View File

@ -40,8 +40,8 @@ bool MiniMax::testLayer(unsigned int layerNumber)
tlVars[curThreadNo].pMiniMax = this; tlVars[curThreadNo].pMiniMax = this;
tlVars[curThreadNo].layerNumber = layerNumber; tlVars[curThreadNo].layerNumber = layerNumber;
tlVars[curThreadNo].statesProcessed = 0; tlVars[curThreadNo].statesProcessed = 0;
tlVars[curThreadNo].subValueInDatabase = new twoBit[maxNumBranches]; tlVars[curThreadNo].subValueInDatabase = new TwoBit[maxNumBranches];
tlVars[curThreadNo].subPlyInfos = new plyInfoVarType[maxNumBranches]; tlVars[curThreadNo].subPlyInfos = new PlyInfoVarType[maxNumBranches];
tlVars[curThreadNo].hasCurPlayerChanged = new bool[maxNumBranches]; tlVars[curThreadNo].hasCurPlayerChanged = new bool[maxNumBranches];
} }
@ -93,14 +93,14 @@ DWORD MiniMax::testLayerThreadProc(void *pParameter, int index)
unsigned int layerNumber = tlVars->layerNumber; unsigned int layerNumber = tlVars->layerNumber;
unsigned int stateNumber = index; unsigned int stateNumber = index;
unsigned int threadNo = tlVars->curThreadNo; unsigned int threadNo = tlVars->curThreadNo;
twoBit *subValueInDatabase = tlVars->subValueInDatabase; TwoBit *subValueInDatabase = tlVars->subValueInDatabase;
plyInfoVarType *subPlyInfos = tlVars->subPlyInfos; PlyInfoVarType *subPlyInfos = tlVars->subPlyInfos;
bool *hasCurPlayerChanged = tlVars->hasCurPlayerChanged; bool *hasCurPlayerChanged = tlVars->hasCurPlayerChanged;
twoBit shortValueInDatabase; TwoBit shortValueInDatabase;
plyInfoVarType numPliesTillCurState; PlyInfoVarType numPliesTillCurState;
twoBit shortValueInGame; TwoBit shortValueInGame;
float floatValueInGame; float floatValueInGame;
plyInfoVarType min, max; PlyInfoVarType min, max;
unsigned int numPossibilities; unsigned int numPossibilities;
unsigned int i, j; unsigned int i, j;
unsigned int tmpStateNumber, tmpLayerNumber; unsigned int tmpStateNumber, tmpLayerNumber;
@ -319,8 +319,8 @@ bool MiniMax::testState(unsigned int layerNumber, unsigned int stateNumber)
tlVars.pMiniMax = this; tlVars.pMiniMax = this;
tlVars.layerNumber = layerNumber; tlVars.layerNumber = layerNumber;
tlVars.statesProcessed = 0; tlVars.statesProcessed = 0;
tlVars.subValueInDatabase = new twoBit[maxNumBranches]; tlVars.subValueInDatabase = new TwoBit[maxNumBranches];
tlVars.subPlyInfos = new plyInfoVarType[maxNumBranches]; tlVars.subPlyInfos = new PlyInfoVarType[maxNumBranches];
tlVars.hasCurPlayerChanged = new bool[maxNumBranches]; tlVars.hasCurPlayerChanged = new bool[maxNumBranches];
if (testLayerThreadProc(&tlVars, stateNumber) != TM_RETURN_VALUE_OK) result = false; if (testLayerThreadProc(&tlVars, stateNumber) != TM_RETURN_VALUE_OK) result = false;
@ -355,8 +355,8 @@ bool MiniMax::testSetSituationAndGetPoss(unsigned int layerNumber)
tlVars[curThreadNo].pMiniMax = this; tlVars[curThreadNo].pMiniMax = this;
tlVars[curThreadNo].layerNumber = layerNumber; tlVars[curThreadNo].layerNumber = layerNumber;
tlVars[curThreadNo].statesProcessed = 0; tlVars[curThreadNo].statesProcessed = 0;
tlVars[curThreadNo].subValueInDatabase = new twoBit[maxNumBranches]; tlVars[curThreadNo].subValueInDatabase = new TwoBit[maxNumBranches];
tlVars[curThreadNo].subPlyInfos = new plyInfoVarType[maxNumBranches]; tlVars[curThreadNo].subPlyInfos = new PlyInfoVarType[maxNumBranches];
tlVars[curThreadNo].hasCurPlayerChanged = new bool[maxNumBranches]; tlVars[curThreadNo].hasCurPlayerChanged = new bool[maxNumBranches];
} }
@ -413,7 +413,7 @@ DWORD MiniMax::testSetSituationThreadProc(void *pParameter, int index)
StateAdress curState; StateAdress curState;
StateAdress subState; StateAdress subState;
Node knot; Node knot;
twoBit shortKnotValue = SKV_VALUE_GAME_DRAWN; TwoBit shortKnotValue = SKV_VALUE_GAME_DRAWN;
curState.layerNumber = tlVars->layerNumber; curState.layerNumber = tlVars->layerNumber;
curState.stateNumber = index; curState.stateNumber = index;
@ -485,10 +485,10 @@ bool MiniMax::testIfSymStatesHaveSameValue(unsigned int layerNumber)
{ {
// Locals // Locals
unsigned int threadNo = 0; unsigned int threadNo = 0;
twoBit shortValueInDatabase; TwoBit shortValueInDatabase;
twoBit shortValueOfSymState; TwoBit shortValueOfSymState;
plyInfoVarType numPliesTillCurState; PlyInfoVarType numPliesTillCurState;
plyInfoVarType numPliesTillSymState; PlyInfoVarType numPliesTillSymState;
unsigned int stateNumber = 0; unsigned int stateNumber = 0;
unsigned int *symStateNumbers = nullptr; unsigned int *symStateNumbers = nullptr;
unsigned int numSymmetricStates; unsigned int numSymmetricStates;

View File

@ -206,8 +206,8 @@ perfectAI::perfectAI(const char *directory)
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;
threadVars[curThread].possibilities = new possibilityStruct[MAX_DEPTH_OF_TREE + 1]; threadVars[curThread].possibilities = new Possibility[MAX_DEPTH_OF_TREE + 1];
threadVars[curThread].oldStates = new backupStruct[MAX_DEPTH_OF_TREE + 1]; threadVars[curThread].oldStates = new Backup[MAX_DEPTH_OF_TREE + 1];
threadVars[curThread].idPossibilities = new unsigned int[(MAX_DEPTH_OF_TREE + 1) * MAX_NUM_POS_MOVES]; threadVars[curThread].idPossibilities = new unsigned int[(MAX_DEPTH_OF_TREE + 1) * MAX_NUM_POS_MOVES];
} }
@ -235,7 +235,7 @@ perfectAI::perfectAI(const char *directory)
ReadFile(hFilePreCalcVars, concSymOperation, sizeof(unsigned int) * NUM_SYM_OPERATIONS * NUM_SYM_OPERATIONS, &dwBytesRead, nullptr); ReadFile(hFilePreCalcVars, concSymOperation, sizeof(unsigned int) * NUM_SYM_OPERATIONS * NUM_SYM_OPERATIONS, &dwBytesRead, nullptr);
ReadFile(hFilePreCalcVars, mOverN, sizeof(unsigned int) * (fieldStruct::size + 1) * (fieldStruct::size + 1), &dwBytesRead, nullptr); ReadFile(hFilePreCalcVars, mOverN, sizeof(unsigned int) * (fieldStruct::size + 1) * (fieldStruct::size + 1), &dwBytesRead, nullptr);
ReadFile(hFilePreCalcVars, valueOfMove, sizeof(unsigned char) * fieldStruct::size * fieldStruct::size, &dwBytesRead, nullptr); ReadFile(hFilePreCalcVars, valueOfMove, sizeof(unsigned char) * fieldStruct::size * fieldStruct::size, &dwBytesRead, nullptr);
ReadFile(hFilePreCalcVars, plyInfoForOutput, sizeof(plyInfoVarType) * fieldStruct::size * fieldStruct::size, &dwBytesRead, nullptr); ReadFile(hFilePreCalcVars, plyInfoForOutput, sizeof(PlyInfoVarType) * fieldStruct::size * fieldStruct::size, &dwBytesRead, nullptr);
ReadFile(hFilePreCalcVars, incidencesValuesSubMoves, sizeof(unsigned int) * 4 * fieldStruct::size * fieldStruct::size, &dwBytesRead, nullptr); ReadFile(hFilePreCalcVars, incidencesValuesSubMoves, sizeof(unsigned int) * 4 * fieldStruct::size * fieldStruct::size, &dwBytesRead, nullptr);
// process originalStateAB[][] // process originalStateAB[][]
@ -601,7 +601,7 @@ perfectAI::perfectAI(const char *directory)
WriteFile(hFilePreCalcVars, concSymOperation, sizeof(unsigned int) * NUM_SYM_OPERATIONS * NUM_SYM_OPERATIONS, &dwBytesWritten, nullptr); WriteFile(hFilePreCalcVars, concSymOperation, sizeof(unsigned int) * NUM_SYM_OPERATIONS * NUM_SYM_OPERATIONS, &dwBytesWritten, nullptr);
WriteFile(hFilePreCalcVars, mOverN, sizeof(unsigned int) * (fieldStruct::size + 1) * (fieldStruct::size + 1), &dwBytesWritten, nullptr); WriteFile(hFilePreCalcVars, mOverN, sizeof(unsigned int) * (fieldStruct::size + 1) * (fieldStruct::size + 1), &dwBytesWritten, nullptr);
WriteFile(hFilePreCalcVars, valueOfMove, sizeof(unsigned char) * fieldStruct::size * fieldStruct::size, &dwBytesWritten, nullptr); WriteFile(hFilePreCalcVars, valueOfMove, sizeof(unsigned char) * fieldStruct::size * fieldStruct::size, &dwBytesWritten, nullptr);
WriteFile(hFilePreCalcVars, plyInfoForOutput, sizeof(plyInfoVarType) * fieldStruct::size * fieldStruct::size, &dwBytesWritten, nullptr); WriteFile(hFilePreCalcVars, plyInfoForOutput, sizeof(PlyInfoVarType) * fieldStruct::size * fieldStruct::size, &dwBytesWritten, nullptr);
WriteFile(hFilePreCalcVars, incidencesValuesSubMoves, sizeof(unsigned int) * 4 * fieldStruct::size * fieldStruct::size, &dwBytesWritten, nullptr); WriteFile(hFilePreCalcVars, incidencesValuesSubMoves, sizeof(unsigned int) * 4 * fieldStruct::size * fieldStruct::size, &dwBytesWritten, nullptr);
// process originalStateAB[][] // process originalStateAB[][]
@ -683,7 +683,7 @@ void perfectAI::play(fieldStruct *theField, unsigned int *pushFrom, unsigned int
} }
// start the miniMax-algorithmn // start the miniMax-algorithmn
possibilityStruct *rootPossibilities = (possibilityStruct *)getBestChoice(threadVars[0].depthOfFullTree, &bestChoice, MAX_NUM_POS_MOVES); Possibility *rootPossibilities = (Possibility *)getBestChoice(threadVars[0].depthOfFullTree, &bestChoice, MAX_NUM_POS_MOVES);
// decode the best choice // decode the best choice
if (threadVars[0].field->stoneMustBeRemoved) { if (threadVars[0].field->stoneMustBeRemoved) {
@ -863,7 +863,7 @@ unsigned int *perfectAI::threadVarsStruct::getPossNormalMove(unsigned int *numPo
// locals // locals
unsigned int from, to, dir; unsigned int from, to, dir;
unsigned int *idPossibility = &idPossibilities[curSearchDepth * MAX_NUM_POS_MOVES]; unsigned int *idPossibility = &idPossibilities[curSearchDepth * MAX_NUM_POS_MOVES];
possibilityStruct *possibility = &possibilities[curSearchDepth]; Possibility *possibility = &possibilities[curSearchDepth];
// if he is not allowed to spring // if he is not allowed to spring
if (field->curPlayer->numStones > 3) { if (field->curPlayer->numStones > 3) {
@ -981,7 +981,7 @@ 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]; threadVarsStruct *tv = &threadVars[threadNo];
floatValue = tv->floatValue; floatValue = tv->floatValue;
@ -1004,7 +1004,7 @@ void perfectAI::undo(unsigned int threadNo, unsigned int idPossibility, bool opp
{ {
// locals // locals
threadVarsStruct *tv = &threadVars[threadNo]; threadVarsStruct *tv = &threadVars[threadNo];
backupStruct *oldState = (backupStruct *)pBackup; Backup *oldState = (Backup *)pBackup;
// reset old value // reset old value
tv->floatValue = oldState->floatValue; tv->floatValue = oldState->floatValue;
@ -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, backupStruct *backup) inline void perfectAI::threadVarsStruct::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, backupStruct
// Name: normalMove() // Name: normalMove()
// Desc: // Desc:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
inline void perfectAI::threadVarsStruct::normalMove(unsigned int from, unsigned int to, backupStruct *backup) inline void perfectAI::threadVarsStruct::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, backupStruct *backup) inline void perfectAI::threadVarsStruct::removeStone(unsigned int from, Backup *backup)
{ {
// backup // backup
backup->from = from; backup->from = from;
@ -1208,8 +1208,8 @@ void perfectAI::move(unsigned int threadNo, unsigned int idPossibility, bool opp
{ {
// locals // locals
threadVarsStruct *tv = &threadVars[threadNo]; threadVarsStruct *tv = &threadVars[threadNo];
backupStruct *oldState = &tv->oldStates[tv->curSearchDepth]; Backup *oldState = &tv->oldStates[tv->curSearchDepth];
possibilityStruct *tmpPossibility = (possibilityStruct *)pPossibilities; Possibility *tmpPossibility = (Possibility *)pPossibilities;
Player *tmpPlayer; Player *tmpPlayer;
unsigned int i; unsigned int i;
@ -1274,12 +1274,12 @@ 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]; threadVarsStruct *tv = &threadVars[threadNo];
unsigned int index; unsigned int index;
possibilityStruct *tmpPossibility = (possibilityStruct *)pPossibilities; Possibility *tmpPossibility = (Possibility *)pPossibilities;
if (tv->field->stoneMustBeRemoved) index = idPossibility; if (tv->field->stoneMustBeRemoved) index = idPossibility;
else if (tv->field->settingPhase) index = idPossibility; else if (tv->field->settingPhase) index = idPossibility;
@ -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
@ -1375,7 +1375,7 @@ void perfectAI::getValueOfMoves(unsigned char *moveValue, unsigned int *freqValu
// copy // copy
memcpy(moveQuality, moveQualities, sizeof(unsigned int) * fieldStruct::size * fieldStruct::size); memcpy(moveQuality, moveQualities, sizeof(unsigned int) * fieldStruct::size * fieldStruct::size);
memcpy(plyInfo, plyInfoForOutput, sizeof(plyInfoVarType) * fieldStruct::size * fieldStruct::size); memcpy(plyInfo, plyInfoForOutput, sizeof(PlyInfoVarType) * fieldStruct::size * fieldStruct::size);
memcpy(moveValue, valueOfMove, sizeof(unsigned char) * fieldStruct::size * fieldStruct::size); memcpy(moveValue, valueOfMove, sizeof(unsigned char) * fieldStruct::size * fieldStruct::size);
memcpy(freqValuesSubMoves, incidencesValuesSubMoves, sizeof(unsigned int) * fieldStruct::size * fieldStruct::size * 4); memcpy(freqValuesSubMoves, incidencesValuesSubMoves, sizeof(unsigned int) * fieldStruct::size * fieldStruct::size * 4);
} }
@ -1388,7 +1388,7 @@ void perfectAI::printMoveInformation(unsigned int threadNo, unsigned int idPossi
{ {
// locals // locals
threadVarsStruct *tv = &threadVars[threadNo]; threadVarsStruct *tv = &threadVars[threadNo];
possibilityStruct *tmpPossibility = (possibilityStruct *)pPossibilities; Possibility *tmpPossibility = (Possibility *)pPossibilities;
// move // move
if (tv->field->stoneMustBeRemoved) cout << "remove stone from " << (char)(idPossibility + 97); if (tv->field->stoneMustBeRemoved) cout << "remove stone from " << (char)(idPossibility + 97);
@ -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::threadVarsStruct::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:
@ -2397,7 +2397,7 @@ bool perfectAI::checkGetPossThanGetPred()
bool isOpponentLevel; bool isOpponentLevel;
void *pPossibilities; void *pPossibilities;
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]; threadVarsStruct *tv = &threadVars[threadNo];
@ -2480,7 +2480,7 @@ bool perfectAI::checkGetPredThanGetPoss()
void *pPossibilities; void *pPossibilities;
void *pBackup; void *pBackup;
int symField[fieldStruct::size]; int symField[fieldStruct::size];
retroAnalysisPredVars predVars[MAX_NUM_PREDECESSORS]; RetroAnalysisPredVars predVars[MAX_NUM_PREDECESSORS];
// test if each predecessor from getPredecessors() leads to the original state using getPossibilities() // test if each predecessor from getPredecessors() leads to the original state using getPossibilities()
for (layerNum = 0; layerNum < NUM_LAYERS; layerNum++) { for (layerNum = 0; layerNum < NUM_LAYERS; layerNum++) {

View File

@ -98,16 +98,16 @@ protected:
subLayerStruct subLayer[MAX_NUM_SUB_LAYERS]; subLayerStruct subLayer[MAX_NUM_SUB_LAYERS];
}; };
struct possibilityStruct struct Possibility
{ {
unsigned int from[MAX_NUM_POS_MOVES]; unsigned int from[MAX_NUM_POS_MOVES];
unsigned int to[MAX_NUM_POS_MOVES]; unsigned int to[MAX_NUM_POS_MOVES];
}; };
struct backupStruct struct Backup
{ {
float floatValue; float floatValue;
twoBit shortValue; TwoBit shortValue;
bool gameHasFinished; bool gameHasFinished;
bool settingPhase; bool settingPhase;
int fieldFrom, fieldTo; // value of board int fieldFrom, fieldTo; // value of board
@ -154,14 +154,14 @@ protected:
public: public:
fieldStruct *field; // pointer of the current board [changed by move()] fieldStruct *field; // pointer of the current board [changed by move()]
float floatValue; // value of current situation for board->currentPlayer float floatValue; // value of current situation for board->currentPlayer
twoBit shortValue; // '' TwoBit shortValue; // ''
bool gameHasFinished; // someone has won or current board is full bool gameHasFinished; // someone has won or current board is full
int ownId; // id of the player who called the play()-function int ownId; // id of the player who called the play()-function
unsigned int curSearchDepth; // current level unsigned int curSearchDepth; // current level
unsigned int depthOfFullTree; // search depth where the whole tree is explored unsigned int depthOfFullTree; // search depth where the whole tree is explored
unsigned int *idPossibilities; // returned pointer of getPossibilities()-function unsigned int *idPossibilities; // returned pointer of getPossibilities()-function
backupStruct *oldStates; // for undo()-function Backup *oldStates; // for undo()-function
possibilityStruct *possibilities; // for getPossNormalMove()-function Possibility *possibilities; // for getPossNormalMove()-function
perfectAI *parent; // perfectAI *parent; //
// constructor // constructor
@ -176,16 +176,16 @@ protected:
inline void updatePossibleMoves(unsigned int stone, Player *stoneOwner, bool stoneRemoved, unsigned int ignoreStone); inline void updatePossibleMoves(unsigned int stone, Player *stoneOwner, bool stoneRemoved, unsigned int ignoreStone);
inline void updateWarning(unsigned int firstStone, unsigned int secondStone); inline void updateWarning(unsigned int firstStone, unsigned int secondStone);
inline void setWarning(unsigned int stoneOne, unsigned int stoneTwo, unsigned int stoneThree); inline void setWarning(unsigned int stoneOne, unsigned int stoneTwo, unsigned int stoneThree);
inline void removeStone(unsigned int from, backupStruct *backup); inline void removeStone(unsigned int from, Backup *backup);
inline void setStone(unsigned int to, backupStruct *backup); inline void setStone(unsigned int to, Backup *backup);
inline void normalMove(unsigned int from, unsigned int to, backupStruct *backup); inline void normalMove(unsigned int from, unsigned int to, Backup *backup);
// database functions // database functions
unsigned int getLayerAndStateNumber(unsigned int &layerNum, unsigned int &stateNumber); unsigned int getLayerAndStateNumber(unsigned int &layerNum, unsigned int &stateNumber);
void setWarningAndMill(unsigned int stone, unsigned int firstNeighbour, unsigned int secondNeighbour); void setWarningAndMill(unsigned int stone, unsigned int firstNeighbour, unsigned int secondNeighbour);
bool fieldIntegrityOK(unsigned int numberOfMillsCurrentPlayer, unsigned int numberOfMillsOpponentPlayer, bool aStoneCanBeRemovedFromCurPlayer); bool fieldIntegrityOK(unsigned int numberOfMillsCurrentPlayer, unsigned int numberOfMillsOpponentPlayer, bool aStoneCanBeRemovedFromCurPlayer);
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; threadVarsStruct *threadVars;
@ -197,7 +197,7 @@ protected:
bool isSymOperationInvariantOnGroupCD(unsigned int symmetryOperation, int *theField); bool isSymOperationInvariantOnGroupCD(unsigned int symmetryOperation, int *theField);
bool shallRetroAnalysisBeUsed(unsigned int layerNum); bool shallRetroAnalysisBeUsed(unsigned int layerNum);
void getSuccLayers(unsigned int layerNum, unsigned int *amountOfSuccLayers, unsigned int *succLayers); void getSuccLayers(unsigned int layerNum, unsigned int *amountOfSuccLayers, unsigned int *succLayers);
void getPredecessors(unsigned int threadNo, unsigned int *amountOfPred, retroAnalysisPredVars *predVars); void getPredecessors(unsigned int threadNo, unsigned int *amountOfPred, RetroAnalysisPredVars *predVars);
bool setSituation(unsigned int threadNo, unsigned int layerNum, unsigned int stateNumber); bool setSituation(unsigned int threadNo, unsigned int layerNum, unsigned int stateNumber);
unsigned int getLayerNumber(unsigned int threadNo); unsigned int getLayerNumber(unsigned int threadNo);
unsigned int getLayerAndStateNumber(unsigned int threadNo, unsigned int &layerNum, unsigned int &stateNumber); unsigned int getLayerAndStateNumber(unsigned int threadNo, unsigned int &layerNum, unsigned int &stateNumber);
@ -209,7 +209,7 @@ protected:
// Virtual Functions // Virtual Functions
void prepareBestChoiceCalculation(); void prepareBestChoiceCalculation();
void getValueOfSituation(unsigned int threadNo, float &floatValue, twoBit &shortValue); void getValueOfSituation(unsigned int threadNo, float &floatValue, TwoBit &shortValue);
void setOpponentLevel(unsigned int threadNo, bool isOpponentLevel); void setOpponentLevel(unsigned int threadNo, bool isOpponentLevel);
bool getOpponentLevel(unsigned int threadNo); bool getOpponentLevel(unsigned int threadNo);
void deletePossibilities(unsigned int threadNo, void *pPossibilities); void deletePossibilities(unsigned int threadNo, void *pPossibilities);
@ -217,7 +217,7 @@ protected:
void undo(unsigned int threadNo, unsigned int idPossibility, bool opponentsMove, void *pBackup, void *pPossibilities); void undo(unsigned int threadNo, unsigned int idPossibility, bool opponentsMove, void *pBackup, void *pPossibilities);
void move(unsigned int threadNo, unsigned int idPossibility, bool opponentsMove, void **pBackup, void *pPossibilities); void move(unsigned int threadNo, unsigned int idPossibility, bool opponentsMove, void **pBackup, void *pPossibilities);
void printMoveInformation(unsigned int threadNo, unsigned int idPossibility, void *pPossibilities); void printMoveInformation(unsigned int threadNo, unsigned int idPossibility, void *pPossibilities);
void storeValueOfMove(unsigned int threadNo, unsigned int idPossibility, void *pPossibilities, unsigned char value, unsigned int *freqValuesSubMoves, plyInfoVarType plyInfo); void storeValueOfMove(unsigned int threadNo, unsigned int idPossibility, void *pPossibilities, unsigned char value, unsigned int *freqValuesSubMoves, PlyInfoVarType plyInfo);
void getSymStateNumWithDoubles(unsigned int threadNo, unsigned int *numSymmetricStates, unsigned int **symStateNumbers); void getSymStateNumWithDoubles(unsigned int threadNo, unsigned int *numSymmetricStates, unsigned int **symStateNumbers);
void printField(unsigned int threadNo, unsigned char value); void printField(unsigned int threadNo, unsigned char value);
string getOutputInformation(unsigned int layerNum); string getOutputInformation(unsigned int layerNum);
@ -233,7 +233,7 @@ public:
// Functions // Functions
bool setDatabasePath(const char *directory); bool setDatabasePath(const char *directory);
void play(fieldStruct *theField, unsigned int *pushFrom, unsigned int *pushTo); void play(fieldStruct *theField, unsigned int *pushFrom, unsigned int *pushTo);
void getValueOfMoves(unsigned char *moveValue, unsigned int *freqValuesSubMoves, plyInfoVarType *plyInfo, unsigned int *moveQuality, unsigned char &knotValue, plyInfoVarType &bestAmountOfPlies); void getValueOfMoves(unsigned char *moveValue, unsigned int *freqValuesSubMoves, PlyInfoVarType *plyInfo, unsigned int *moveQuality, unsigned char &knotValue, PlyInfoVarType &bestAmountOfPlies);
void getField(unsigned int layerNum, unsigned int stateNumber, fieldStruct *field, bool *gameHasFinished); void getField(unsigned int layerNum, unsigned int stateNumber, fieldStruct *field, bool *gameHasFinished);
void getLayerAndStateNumber(unsigned int &layerNum, unsigned int &stateNumber); void getLayerAndStateNumber(unsigned int &layerNum, unsigned int &stateNumber);