private static void SetLighthouses(RenderMap map, IEnumerable <Lighthouse> lighthouses) { foreach (Lighthouse lighthouse in lighthouses) { map.RenderGrid.Where(x => x.Position == lighthouse.Position).Single().Lighthouse = lighthouse; } }
private const int MAX_CELL_ENERGY = 100; //TODO: Add to config public static void Render(Map map, IEnumerable <ArenaPlayer> players, IEnumerable <Lighthouse> lighthouses) { RenderMap renderMap = new RenderMap(map.Size, map.Grid); SetRenderGrid(renderMap); SetPlayers(renderMap, players); SetLighthouses(renderMap, lighthouses); StringBuilder renderResult = RenderMap(renderMap); renderResult.AppendLine(); foreach (ArenaPlayer player in players) { renderResult.AppendLine(String.Format("Player {0} {1}", player.Id, player.Name)); renderResult.AppendLine(String.Format(" Position: [{0},{1}]", player.Position.X, player.Position.Y)); renderResult.AppendLine(String.Format(" Energy: {0}", player.Energy)); renderResult.AppendLine(String.Format(" Keys: {0}", player.Keys.Count())); renderResult.AppendLine(String.Format(" Lighthouses: {0}", lighthouses.Where(x => x.Owner?.Id == player.Id).Count())); renderResult.AppendLine(String.Format(" Operation (ms): {0}", player.OperationTime.LastOrDefault())); renderResult.AppendLine(String.Format(" Operation AVG (ms): {0}", (player.OperationTime.Any()) ? player.OperationTime.Average() : 0)); renderResult.AppendLine(String.Format(" Operation MAX (ms): {0}", (player.OperationTime.Any()) ? player.OperationTime.Max() : 0)); renderResult.AppendLine(); } renderResult.AppendLine("Scoring:"); foreach (ArenaPlayer player in players.OrderByDescending(x => x.Lighthouses.Count()).ThenBy(x => x.Energy)) { renderResult.AppendLine(String.Format("Player {0} {1}", player.Id, player.Name)); } Console.SetCursorPosition(0, 0); Console.Write(renderResult); }
private static void SetRenderGrid(RenderMap map) { IEnumerable <RendererCell> cells = map.Grid.Select(x => new RendererCell { Position = x.Position, IsPlayable = x.IsPlayable, Energy = x.Energy } ); map.RenderGrid = cells.ToList(); }
private static void SetPlayers(RenderMap map, IEnumerable <ArenaPlayer> players) { foreach (ArenaPlayer player in players) { RendererCell cell = map.RenderGrid.Where(x => x.Position == player.Position).Single(); if (cell.Players == null) { cell.Players = new List <ArenaPlayer>(); } cell.Players.Add(player); } }
private static StringBuilder RenderMap(RenderMap map) { StringBuilder strMap = new StringBuilder(); string scaleX = String.Format(CELLFORMAT, "XX"); for (int i = 0; i < map.Size.X; i++) { scaleX += String.Format(CELLFORMAT, i.ToString("00")); } strMap.AppendLine(scaleX); for (int i = 0; i < map.Size.Y; i++) { RendererCell[] row = map.RenderGrid.Where(c => c.Position.Y == i).ToArray(); strMap.AppendLine(RenderRow(row, i)); } return(strMap); }