private static ValueAndAction MinValue(Board board, Node node, ref int alpha, ref int beta, int depth) { if (Agent.CutOff(depth)) { node.Value = Agent.Evaluate(node); if (node.Value != 0) { UnityEngine.Debug.Log(node.ToString() + " at depth= " + depth + " has value = " + node.Value); } return(new ValueAndAction(node.Value, node.Move)); } int tempVal = int.MaxValue; ActionFunction tempAction = new ActionFunction(); Agent.GenerateSuccessors(node); foreach (Node child in node.Children) { board.ExecuteFunction(child.Move); var retValAction = MaxValue(board, child, ref alpha, ref beta, depth + 1); board.ExecuteFunction(child.Undo); if (retValAction.value < tempVal) { tempVal = retValAction.value; tempAction = child.Move; if (retValAction.value <= alpha) { retValAction.action = child.Move; return(retValAction); } beta = Math.Min(beta, retValAction.value); } } return(new ValueAndAction(tempVal, tempAction)); }
private IEnumerator AITurn(int playerNum) /// AI Controls { MessageText.text = ""; //move or choose wall playerStatus[playerNum].currentTurn = true; playersTurnText.text = "Player " + (playerNum + 1) + "'s Turn!"; Assets.Scripts.ActionFunction action = MyAgent.NextMove(MainBoard, playerNum); // <- currently has an issue if (action.function == null) { Debug.LogError("Agent action is null. Something is wrong. Agent just skip his move"); yield break; } if (action.function.Method.Name == "MovePawn") { RenderPawnPosition(action.player, action.x, action.y); } else if (action.function.Method.Name == "PlaceHorizontalWall") { RenderWall(action.x, action.y, true); } else if (action.function.Method.Name == "PlaceVerticalWall") { RenderWall(action.x, action.y, false); } else { Debug.LogError("Agent returning a non-supported action"); } MainBoard.ExecuteFunction(action); UpdateWallRemTxt(); //Update UI anyway because it doesn't matter yield return(null); }