void ChooseBestMove() { int indexOfHighestValue = Array.IndexOf(movesTree.chancesOfChildren, movesTree.chancesOfChildren.Max()); gameUIScript.SetComputerProbability(movesTree.chancesOfChildren[indexOfHighestValue]); switch (indexOfHighestValue) { case 0: movesTree = movesTree.leftBranch; levelScript.ChoosingForAI(movesTree.takenMatchesCount); break; case 1: movesTree = movesTree.centerBranch; levelScript.ChoosingForAI(movesTree.takenMatchesCount); break; case 2: movesTree = movesTree.rightBranch; levelScript.ChoosingForAI(movesTree.takenMatchesCount); break; default: print("Error in choosing best move"); break; } }
void CreateMovesTree(int matchesCount, int matchesTakenLastMove) { millisecondsTimer.Start(); movesTree = new branchBehaviour(matchesCount, matchesTakenLastMove, true); millisecondsTimer.Stop(); print("Create tree time: " + millisecondsTimer.ElapsedMilliseconds); millisecondsTimer.Reset(); millisecondsTimer.Start(); movesTree.CalculateProbability(); millisecondsTimer.Stop(); print("Calculating probability time: " + millisecondsTimer.ElapsedMilliseconds); }
public branchBehaviour(int matchesCount, int takenMatchesCount, bool wasHumanMove) { this.matchesCount = matchesCount; this.takenMatchesCount = takenMatchesCount; this.isComputerMove = !wasHumanMove; if (matchesCount > 0) { if (takenMatchesCount - 1 > 0) { leftBranch = new branchBehaviour((matchesCount - takenMatchesCount + 1), (takenMatchesCount - 1), isComputerMove); } else { leftBranch = null; } centerBranch = new branchBehaviour(matchesCount - takenMatchesCount, takenMatchesCount, isComputerMove); rightBranch = new branchBehaviour((matchesCount - takenMatchesCount - 1), (takenMatchesCount + 1), isComputerMove); } }
void PlayerMadeMove(int matchesTakenLastMove) { if (movesTree.leftBranch != null && matchesTakenLastMove == movesTree.leftBranch.takenMatchesCount) { movesTree = movesTree.leftBranch; } else if (matchesTakenLastMove == movesTree.centerBranch.takenMatchesCount) { movesTree = movesTree.centerBranch; } else if (matchesTakenLastMove == movesTree.rightBranch.takenMatchesCount) { movesTree = movesTree.rightBranch; } else { print("Error in player move (AI message)"); } gameUIScript.SetComputerProbability(movesTree.chancesOfChildren.Max()); }