// Finds the ship position with the greatest probability private string SelectBestBelief(LabelledDCNode ship, List <List <Point> > allPossiblePos) { List <double> beliefs = new List <double>(); List <string> startCoords = new List <string>(); double bestBelief = 0; string startCoord = ""; long beliefIndex; // Runs through all possible ship positions foreach (List <Point> list in allPossiblePos) { // Enters if the two first Y-coordinates have the same value if (list[0].Y - list[1].Y == 0) { startCoord = $"H_{list[0].X}{list[0].Y}"; } else { startCoord = $"V_{list[0].X}{list[0].Y}"; } beliefIndex = ship.GetStateIndex(startCoord); beliefs.Add(ship.GetBelief((ulong)beliefIndex)); startCoords.Add(startCoord); } for (int i = 0; i < beliefs.Count; i++) { // Enters if the probability is greater than those already found if (beliefs[i] > bestBelief) { bestBelief = beliefs[i]; startCoord = startCoords[i]; } } if (startCoord != "") { return(startCoord); } throw new ArgumentException("Something went wrong while trying to find sunken ship's start coordinate."); }