string GetText(Grid grid) { Boat[] boats = grid.boats; string t = ""; if (boats != null) { int units = 0; int sunk = 0; int hits = 0; int misses = grid.getMisses(); for (int i = 0; i < boats.Length; i++) { BoatConfiguration config = boats [i].config; units += config.size; hits += boats [i].HitCount(); if (boats [i].IsSunk()) { sunk++; } } t += "Segments hit: " + AsPercentage(hits, units) + "\n" + hits + " / " + units + "\n\n"; t += "Boats sunk: " + AsPercentage(sunk, boats.Length) + "\n" + sunk + " / " + boats.Length + "\n\n"; t += "Accuracy: " + AsPercentage(hits, hits + misses) + "\n" + hits + " / " + (hits + misses) + "\n\n"; } return(t); }
public void Deserialize(BinaryReader reader) { whose = (Whose)reader.ReadInt32(); boatConfigurationIndex = reader.ReadInt32(); config = Grid.fleet [boatConfigurationIndex]; hits = new int[config.size]; horizontal = reader.ReadBoolean(); Position position = new Position(); position.Deserialize(reader); positions = MakeBoatPositions(horizontal ? position.x : position.y, horizontal ? position.y : position.x, config.size, horizontal); }
void LogStats(Grid grid) { Boat[] boats = grid.boats; int units = 0; int sunk = 0; int hits = 0; int misses = grid.getMisses(); for (int i = 0; i < boats.Length; i++) { BoatConfiguration config = boats [i].config; units += config.size; hits += boats [i].HitCount(); if (boats [i].IsSunk()) { sunk++; } } gav4.LogEvent(CATEGORY, grid.whose.ToString() + "-HitsOutOf" + units, null, hits); gav4.LogEvent(CATEGORY, grid.whose.ToString() + "-SunkOutOf" + boats.Length, null, sunk); gav4.LogEvent(CATEGORY, grid.whose.ToString() + "-AccuracyPercent", null, AccuracyPercent(hits, misses)); }