private Orientation CalculateOrientation() { if (CurrentHits.ToList()[0].Column != CurrentHits.ToList()[1].Column) { return(Orientation.Horizontal); } return(Orientation.Vertical); }
private void IfHitAfter2Hits(Coordinate coord) { if (Opponent.Ships.Where(s => !s.IsSunk).SelectMany(s => s.Placement).Contains(coord)) { CurrentHits.Add(coord); GenerateDirectionPotentials(); CurrentShipSize = FindShipSize(coord); } }
private Coordinate IfHit(Coordinate coord) { if (Opponent.Ships.Where(s => !s.IsSunk).SelectMany(s => s.Placement).Contains(coord)) { CurrentHits.Add(coord); GenerateAllPotentials(coord); CurrentShipSize = FindShipSize(coord); } return(coord); }
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(); }
private void ClearCurrentAndPotentials() { CurrentHits.Clear(); PotentialShots.Clear(); }