private PossiblePath BestPossiblePath(PossiblePath a, PossiblePath b) { if (a == null) { return(b); } if (b == null) { return(a); } if (a.Value > b.Value) { return(a); } return(b); }
private PossiblePath GetBestPath(AlphaBetaBoard board, Location startLocation, int depth) { Plot plot = board[startLocation]; if (depth > 3 || plot.Player_Count == 1) { var path = new Stack <Location>(); path.Push(startLocation); return(new PossiblePath(plot.Hex, path)); } // PossiblePath bestPath = null; var possibleMoves = PossibleMoves(startLocation.x, startLocation.y, board); if (possibleMoves.Count() != 0) { PossiblePath bestPath = null; foreach (var location in possibleMoves) { AlphaBetaBoard cloneBoard = new AlphaBetaBoard(board); if (cloneBoard.GetHexBoard()[location.x, location.y].Player != -1) { cloneBoard.GetHexBoard()[location.x, location.y].Player = -2; cloneBoard.GetHexBoard()[location.x, location.y].Player_Count = cloneBoard.GetHexBoard()[startLocation.x, startLocation.y].Player_Count - 1; PossiblePath tempPath = GetBestPath(cloneBoard, location, depth + 1); tempPath.Value = board.GetHexBoard()[location.x, location.y].Hex; bestPath = BestPossiblePath(tempPath, bestPath); } else { if (IsItWorthIt(startLocation, location, cloneBoard)) { cloneBoard.GetHexBoard()[location.x, location.y].Player = -2; cloneBoard.GetHexBoard()[location.x, location.y].Player_Count = cloneBoard.GetHexBoard()[startLocation.x, startLocation.y].Player_Count - 1; // in assamption that AI wins PossiblePath tempPath = GetBestPath(cloneBoard, location, depth + 1); tempPath.Value = board.GetHexBoard()[location.x, location.y].Hex; bestPath = tempPath; // need to add new bestpossiblepath that calculates with its wirth to attack } else { var path = new Stack <Location>(); path.Push(startLocation); return(new PossiblePath(plot.Hex, path)); } } } bestPath.Path.Push(startLocation); bestPath.Value += plot.Hex; return(bestPath); } else { var path = new Stack <Location>(); path.Push(startLocation); return(new PossiblePath(plot.Hex, path)); } }