IEnumerator CheckResult() { int score = TicTacToeScore.getScoreState(TicTacToeScore.CovertToMatrix(currentMove.matrix, 3), playerX?"X":"O"); if (score == StateTree.victoryScore) { TurnOffButtons(); yield return(new WaitForSeconds(1)); onVictory.Invoke(); } else if (score == StateTree.victoryScore * -1) { TurnOffButtons(); yield return(new WaitForSeconds(1)); onLose.Invoke(); } else if (Tie()) { TurnOffButtons(); yield return(new WaitForSeconds(1)); onTie.Invoke(); } }
public void FillStates(Node node, bool x, string player, int numSearch = 0, bool min = false) { node.score = TicTacToeScore.getScoreState(TicTacToeScore.CovertToMatrix(node.matrix, 3), player); if ((depthOfSearch > 0 && numSearch > depthOfSearch) || Mathf.Abs(node.score) == victoryScore) { return; } bool fillLeft = false; for (int i = 0; i < node.matrix.Length; i++) { if (string.IsNullOrEmpty(node.matrix[i])) { Node newNode = new Node(); node.matrix.CopyTo(newNode.matrix, 0); newNode.matrix[i] = x?"X":"O"; node.childs.Add(newNode); newNode.parent = node; FillStates(newNode, !x, player, numSearch + 1, !min); if (!fillLeft) { fillLeft = true; node.score = newNode.score; node.result = newNode; if (min && CutMinScore(node.score)) { return; } else if (!min && CutMaxScore(node.score)) { return; } } else { if (min && AlphaBetaMin(node, newNode)) { return; } else if (!min && AlphaBetaMax(node, newNode)) { return; } } } } }