private static INode <ITicTacToeGame> KeepPlayingUntilEndOfGame(MinMaxAlgorithm <ITicTacToeGame> engine, INode <ITicTacToeGame> gamePosition) { while (true) { var currentPositionEvaluation = engine.Evaluate(gamePosition); PrintGame(gamePosition.Value, currentPositionEvaluation.Score); if (currentPositionEvaluation.BestNode == null) { break; } var positionToPlay = ReadNumber(); if (positionToPlay != -1) { var row = Convert.ToInt32(Math.Floor((double)(positionToPlay / BOARD_SIZE))); var column = positionToPlay % BOARD_SIZE; gamePosition = new TicTacToeNode(gamePosition.Value.PlayAt(row, column)); continue; } gamePosition = currentPositionEvaluation.BestNode; } return(gamePosition); }
private Position CacluateNode(MapNode[,] mapData) { List <Position> positionList; int bestValue = Int32.MinValue; tttNodeRoot = new TicTacToeNode(gameMode, 0); //최초값 초기화. positionList = GetPossibleMove(mapData); Position returnPos = positionList[0]; // Debug.Log("222"); foreach (Position pos in positionList) { var answer = FindMiniMax(pos, mapData, Int32.MinValue, Int32.MaxValue, true, 0); // Debug.Log("===================Pos:" + pos.X + "," + pos.Y + " ans:" + answer); if (answer > bestValue) { bestValue = answer; returnPos = pos; } } Debug.Log("===================returnPos" + returnPos.X + "," + returnPos.Y); return(returnPos); }