private Coordinate PostShotRoutine(Coordinate shot) { PotentialShots.Remove(shot); if (CurrentHits.Count == CurrentShipSize) { ClearCurrentAndPotentials(); } return(shot); }
private void RemoveMadeShots() { foreach (Coordinate shot in Computer.ShotsTaken) { if (PotentialShots.Contains(shot)) { PotentialShots.Remove(shot); } } }
private void GenerateAllPotentials(Coordinate hitShot) { //Potential next shots can go 4 ways: up, down, left and right. PotentialShots.Add(new Coordinate(hitShot.Column, hitShot.Row - 1)); PotentialShots.Add(new Coordinate(hitShot.Column, hitShot.Row + 1)); PotentialShots.Add(new Coordinate(hitShot.Column - 1, hitShot.Row)); PotentialShots.Add(new Coordinate(hitShot.Column + 1, hitShot.Row)); RemoveBadCoords(); RemoveMadeShots(); }
private void RemoveBadCoords() { for (int i = 0; i < PotentialShots.Count; i++) { if (PotentialShots[i].Column > 9 || PotentialShots[i].Column < 0 || PotentialShots[i].Row > 9 || PotentialShots[i].Row < 0) { PotentialShots.Remove(PotentialShots[i]); } } }
private void GenerateDirectionPotentials() { //Once the direction is set we can generate potential shots based on the direction if (CurrentOrientation == Orientation.Horizontal) { var columns = CurrentHits.Select(c => c.Column).ToList(); PotentialShots.Add(new Coordinate(columns.Max() + 1, CurrentHits[0].Row)); PotentialShots.Add(new Coordinate(columns.Min() - 1, CurrentHits[0].Row)); } else { var rows = CurrentHits.Select(c => c.Row).ToList(); PotentialShots.Add(new Coordinate(CurrentHits[0].Column, rows.Max() + 1)); PotentialShots.Add(new Coordinate(CurrentHits[0].Column, rows.Min() - 1)); } RemoveBadCoords(); RemoveMadeShots(); }
public Coordinate Shoot() { if (PotentialShots.Count == 0) { return(IfHit(RandomShot())); } var shot = PotentialShots[Rand.Next(PotentialShots.Count)]; if (PotentialShots.Count > 0 && CurrentHits.Count == 1) { IfHit(AimedShot(shot)); if (CurrentHits.Count == 2) { CurrentOrientation = CalculateOrientation(); PotentialShots.Clear(); GenerateDirectionPotentials(); } return(PostShotRoutine(shot)); } IfHitAfter2Hits(AimedShot(shot)); return(PostShotRoutine(shot)); }
private void ClearCurrentAndPotentials() { CurrentHits.Clear(); PotentialShots.Clear(); }