Hi All,
I try to make a simple TicTacToe Game and have a Board in my Constructor from an TicTacToeActor and set all fields to “_” for empty:
Later in the script I call the method MiniMax from the AI.h and the FString Array is called like this:
Here is part of the Code from the TicTacToeActor with the method call:
if (CheckIfFieldIsEmpty(choiceX, choiceY)) //if (!GetIsGameFinished() && CheckIfFieldIsEmpty(choiceX, choiceY)) GetIsGameFinished is not working!!!
{
bIsPlayerTurn = 1;
FieldIsClickedChangeColor(ActorReference);
HashBoard[choiceX][choiceY] = playerX;
bIsPlayerTurn = 0;
MinimaxAI minimaxAI = MinimaxAI();
int32 choiceCpuX = -1;
int32 choiceCpuY = -1;
minimaxAI.FindBestMove(HashBoard, choiceCpuX, choiceCpuY);
HashBoard[choiceCpuX][choiceCpuY] = playerO;
Initalization in header:
private:
bool isGameFinished;
bool waitForTurn;
bool isPlayerTurn;
FString hashBoard[3][3];
This is the called method in the AI:
void MinimaxAI::FindBestMove(FString Board[3][3], int32 &choiceX, int32 &choiceY)
{
int32 bestValue = -1000;
int32 row = -1;
int32 col = -1;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
if (Board[i][j] == empty)
{
Board[i][j] = playerX;
int MoveValue = MiniMax(Board, 0, false);
Board[i][j] == empty;
if (MoveValue > bestValue)
{
row = i;
col = j;
bestValue = MoveValue;
}
}
}
}
choiceX = row;
choiceY = col;
}
And maybe one more question: I could not debug with VisualStudio (because I’m a super beginner and started 4 weeks ago with VS and Unreal) and so I started to read the documentation and built the engine from source. After I switched the build I tried to rebuild and always get a missing module error. I googled long times but still dont get it. In VS I can start a new instance with Debug Editor and see variables etc. But I would like to get the Editor open without building every time again (for example with Attach To Process).
In my Logfile I get the following error (only a part of the logfile because I couldn’t upload it):
LogXGEController: Cleaning working directory: C:/Users/tommy/AppData/Local/Temp/UnrealXGEWorkingDir/ LogInit: Warning: Incompatible or missing module: TicTacToe Running E:/UnrealEngineSource/UnrealEngine-release/Engine/Binaries/DotNET/UnrealBuildTool.exe Development Win64
-Project=“E:/UnrealEngine/TicTacToe/TicTacToe.uproject”
-TargetType=Editor -Progress -NoEngineChanges -NoHotReloadFromIDE Creating makefile for TicTacToeEditor (no existing makefile) @progress push 5% @progress pop ERROR: Building would modify the following engine files:
E:\UnrealEngineSource\UnrealEngine-release\Engine\Binaries\Win64\Android\UE4Editor.modules
E:\UnrealEngineSource\UnrealEngine-release\Engine\Binaries\Win64\IOS\UE4Editor.modules
E:\UnrealEngineSource\UnrealEngine-release\Engine\Binaries\Win64\Lumin\UE4Editor.modules
E:\UnrealEngineSource\UnrealEngine-release\Engine\Binaries\Win64\UE4Editor.exe
Thanks and sorry for the long question!
Best regards, Tommy