public int[] Imprison(Player player, int time, Metric type, int cellNumber) { if (cellNumber == 0) { cellNumber = Cells.Keys.First(); foreach (var cell in Cells) { if (cell.Value.PrisonerCount < Cells[cellNumber].PrisonerCount) { cellNumber = cell.Key; } } } if (!Cells.ContainsKey(cellNumber)) { return new[] { -2, cellNumber } } ; if (Cells.Values.Any(cell => cell.HasPrisoner(player))) { return new[] { -1, cellNumber } } ; return(new[] { Cells[cellNumber].AddPrisoner(player, time, type, player.Entity.Position) == 1 ? 1 : 0, cellNumber }); }
public int[] AddCell(Vector3 position, int cellNumber = 0) { if (cellNumber == 0) { do { cellNumber++; }while (Cells.ContainsKey(cellNumber) && Cells[cellNumber].Area.GetPositions() == 2); } if (Cells.ContainsKey(cellNumber)) { switch (Cells[cellNumber].Area.GetPositions()) { case 0: Cells[cellNumber].Area.SetPosition(1, position); return(new[] { 1, cellNumber }); case 1: Cells[cellNumber].Area.SetPosition(2, position); return(new[] { 2, cellNumber }); case 2: return(new[] { 0, cellNumber }); } } Cells.Add(cellNumber, new Cell(position)); return(new[] { 1, cellNumber }); }
public void RandomLife() { Cells.Clear(); var rnd = new Random(); int t = rnd.Next(0, 50); for (int x = 0; x < Width / Cell.Size; x++) { for (int y = 0; y < Height / Cell.Size; y++) { int r = rnd.Next(0, 100); if (r <= t) { var c = new Cell(Cells, false) { Position = new Point(x * Cell.Size, y * Cell.Size) }; if (!Cells.ContainsKey(c.Position)) { Cells.Add(c.Position, c); } } } } Invalidate(); }
public void AddCellWithSteps(Point p, int wireNumber, int steps) { if (!Cells.ContainsKey(p)) { Cells[p] = new HashSet <Wire>(); Cells[p].Add( new Wire { WireNumber = wireNumber, Steps = steps } ); } else { // If this wire already has a record for having been in this cell. // This is filtering out wires that self-intersect. Removing this check // means that self intersections will be identified later on, when we check // the number of wires passing through a given cell. if (Cells[p].Select(x => x.WireNumber).Contains(wireNumber)) { return; } Cells[p].Add( new Wire { WireNumber = wireNumber, Steps = steps } ); } }
private static void CompareMaps() { var todelete = new List <string>(); foreach (var cell in Cells) { if (AbcCells.ContainsKey(cell.Value.CellNumber)) { continue; } todelete.Add(cell.Value.CellNumber); } foreach (var regnum in todelete) { Cells.Remove(regnum); } foreach (var abcCell in AbcCells) { if (Cells.ContainsKey(abcCell.Value.RegNum)) { continue; } var cell = new Cell { CellNumber = abcCell.Value.RegNum, Name = abcCell.Value.Label }; Cells.Add(cell.CellNumber, cell); } }
public List <Cell> GetUnexploredUnblockedNeighbors(Cell current) { var cells = new List <Cell>(); foreach (var direction in _directions) { var coordinates = direction(current.Coordinates).ToString(); if (!Cells.ContainsKey(coordinates)) { continue; } var cell = Cells[coordinates]; if (cell.IsExplored || cell.IsBlocked) { continue; } cells.Add(Cells[coordinates]); } return(cells); }
public void AddCell(XMLCell cell) { if (!Cells.ContainsKey(cell.Index)) { Cells.Add(cell.Index, cell); } }
public void RemoveCell(MapCoordinate mapCoordinate) { if (Cells.ContainsKey(mapCoordinate)) { Cells.Remove(mapCoordinate); InvalidateCache(); } }
public int RemoveCell(int cellNumber) { if (!Cells.ContainsKey(cellNumber)) { return(-1); } Cells.Remove(cellNumber); return(1); }
private Cell GetCell(int index, Site site) { if (!Cells.ContainsKey(index)) { Cells.Add(index, new Cell(site)); } return(Cells[index]); }
public void ClearCell(MapCoordinate coordinate) { if (Cells.ContainsKey(coordinate)) { Cells.Remove(coordinate); InvalidateCache(); } }
public HashSet <string> GetPrisoners(int cellNumber) { if (!Cells.ContainsKey(cellNumber)) { return(null); } var prisoners = Cells[cellNumber].GetPrisoners(); return(prisoners); }
public Cell GetCell(string currentLocation) { if (Cells.ContainsKey(currentLocation)) { return(Cells[currentLocation]); } var cell = new Cell(_workbook, currentLocation); Cells[currentLocation] = cell; return(cell); }
public CellState?GetValue(CubeKey key) { var str = key.ToString(); if (Cells.ContainsKey(key.ToString())) { return(Cells[str]); } return(CellState.Inactive); }
public IEntity CellAt(int lookupX, int lookupY) { var coordinate = new MapCoordinate(MapKey, lookupX, lookupY); if (Cells.ContainsKey(coordinate)) { return(Cells[coordinate]); } else { return(DefaultCell); } }
public C GetCell(K1 k1, K2 k2) { if (Keys1.ContainsSecond(k1) && Keys2.ContainsSecond(k2)) { var i1 = Keys1.GetBySecond(k1); var i2 = Keys2.GetBySecond(k2); var tuple = new Tuple <int, int>(i1, i2); if (Cells.ContainsKey(tuple)) { return(Cells[tuple]); } } return(default(C)); }
private void MarkNumber(int number) { LastCalledNumber = number; if (!Cells.ContainsKey(number)) { return; } var cell = Cells[number]; if (cell.Mark()) { Game.CallBingo(this); } }
public IEntity CellAt(MapCoordinate coordinate) { if (coordinate.Key != MapKey) { return(null); } if (Cells.ContainsKey(coordinate)) { return(Cells[coordinate]); } else { return(DefaultCell); } }
internal static string Move(string cur, int dx, int dy) { if (!InvLocation.ContainsKey(cur)) { return(null); } var h = InvLocation[cur]; var scp = h.Split(new[] { '/', '_' }); var ynew = Convert.ToInt32(scp[0], CultureInfo.InvariantCulture) + dy; var xnew = Convert.ToInt32(scp[1], CultureInfo.InvariantCulture) + dx; var hnew = MakePosition(xnew, ynew); if (!Location.ContainsKey(hnew)) { return(null); } var curnew = Location[hnew].RegNum; return(!Cells.ContainsKey(curnew) ? null : curnew); }
public int MovePrisoner(Player player, int cellNumber) { if (!Cells.ContainsKey(cellNumber) || Cells[cellNumber].Area.GetPositions() != 2) { return(-1); } Prisoner prisoner = null; foreach (var cell in Cells) { if (!cell.Value.HasPrisoner(player)) { continue; } prisoner = cell.Value.Prisoners[player.Id]; cell.Value.RemovePrisoner(player, null, false); break; } if (prisoner == null) { return(-2); } return(Cells[cellNumber].AddPrisoner(player, prisoner) == 1 ? 1 : 0); }
public bool CellExists(int x, int y) { return(Cells.ContainsKey(new MapCoordinate(MapKey, x, y))); }
public bool CellExists(MapCoordinate coordinate) { return(Cells.ContainsKey(coordinate)); }
private static void LoadAbcMap() { var pathCellsXml = Path.Combine(Application.StartupPath, "abcells.xml"); if (!File.Exists(pathCellsXml)) { return; } string map2; try { map2 = File.ReadAllText(pathCellsXml, Encoding.UTF8); } catch { return; } //var sb = new StringBuilder(); try { var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(map2); var cellsNodeList = xmlDocument.GetElementsByTagName(AppConsts.TagAbcMapCell); foreach (XmlNode cellNode in cellsNodeList) { if (cellNode.Attributes == null) { continue; } var abcCell = new AbcCell(); if (cellNode.Attributes[AppConsts.AttrAbcMapRegNum] == null) { continue; } abcCell.RegNum = cellNode.Attributes[AppConsts.AttrAbcMapRegNum].Value; if (cellNode.Attributes[AppConsts.AttrAbcMapLabel] != null) { abcCell.Label = cellNode.Attributes[AppConsts.AttrAbcMapLabel].Value; if (Cells.ContainsKey(abcCell.RegNum)) { if ( !abcCell.Label.Equals(Cells[abcCell.RegNum].Tooltip, StringComparison.CurrentCultureIgnoreCase)) { //sb.Append( // $"Клетка [{abcCell.RegNum}] помечена как [{Cells[abcCell.RegNum].Tooltip}], должно быть [{abcCell.Label}]"); //sb.AppendLine(); } } else { //sb.Append($"Клетка [{abcCell.RegNum}] отсутствует"); //sb.AppendLine(); } } var cost = 0; if (cellNode.Attributes[AppConsts.AttrAbcMapCost] != null) { if (!int.TryParse(cellNode.Attributes[AppConsts.AttrAbcMapCost].Value, out cost)) { cost = 0; } } abcCell.Cost = cost; if (abcCell.Cost == 0) { if (Cells.ContainsKey(abcCell.RegNum)) { var jcost = Cells[abcCell.RegNum].Cost; if (jcost == 21) { abcCell.Cost = 30; } else { if (jcost == 28) { abcCell.Cost = 40; } else { if (jcost == 43) { abcCell.Cost = 60; } } } } } var visited = DateTime.MinValue; if (cellNode.Attributes[AppConsts.AttrAbcMapVisited] != null) { if (!DateTime.TryParse(cellNode.Attributes[AppConsts.AttrAbcMapVisited].Value, AppVars.EnUsCulture, DateTimeStyles.None, out visited)) { visited = DateTime.MinValue; } } abcCell.Visited = visited; var verified = DateTime.MinValue; if (cellNode.Attributes[AppConsts.AttrAbcMapVerified] != null) { if (!DateTime.TryParse(cellNode.Attributes[AppConsts.AttrAbcMapVerified].Value, AppVars.EnUsCulture, DateTimeStyles.None, out verified)) { verified = DateTime.MinValue; } } abcCell.Verified = verified; AbcCells.Add(abcCell.RegNum, abcCell); } } catch { } //File.WriteAllText("maps-diff.txt", sb.ToString()); }
private static void LoadMap() { var pathCellsXml = Path.Combine(Application.StartupPath, "map.xml"); if (!File.Exists(pathCellsXml)) { return; } var xml = new XmlDocument(); xml.LoadXml(File.ReadAllText(pathCellsXml)); var ecells = xml.GetElementsByTagName(AppConsts.TagMapCell); foreach (XmlNode ecell in ecells) { if (ecell.Attributes == null) { continue; } var cell = new Cell(); cell.CellNumber = ecell.Attributes[AppConsts.AttrMapCellNumber].Value.Trim(); int cost; int.TryParse(ecell.Attributes[AppConsts.AttrMapCellCost].Value.Trim(), out cost); cell.Cost = cost; bool hasFish; bool.TryParse(ecell.Attributes[AppConsts.AttrMapCellHasFish].Value.Trim(), out hasFish); cell.HasFish = hasFish; bool hasWater; bool.TryParse(ecell.Attributes[AppConsts.AttrMapCellHasWater].Value.Trim(), out hasWater); cell.HasWater = hasWater; cell.HerbGroup = ecell.Attributes[AppConsts.AttrMapCellHerbGroup].Value.Trim(); cell.Name = ecell.Attributes[AppConsts.AttrMapCellName].Value.Trim(); cell.Tooltip = ecell.Attributes[AppConsts.AttrMapCellTooltip].Value.Trim(); cell.Updated = ecell.Attributes[AppConsts.AttrMapCellUpdated].Value.Trim(); cell.NameUpdated = ecell.Attributes[AppConsts.AttrMapCellNameUpdated].Value.Trim(); cell.CostUpdated = ecell.Attributes[AppConsts.AttrMapCellCostUpdated].Value.Trim(); Cells.Add(cell.CellNumber, cell); } var ebots = xml.GetElementsByTagName(AppConsts.TagMapBots); foreach (XmlNode ebot in ebots) { if (ebot.Attributes == null) { continue; } var name = ebot.Attributes[AppConsts.AttrMapBotsName].Value.Trim(); int minLevel; int.TryParse(ebot.Attributes[AppConsts.AttrMapBotsMinLevel].Value, out minLevel); int maxLevel; int.TryParse(ebot.Attributes[AppConsts.AttrMapBotsMaxLevel].Value, out maxLevel); var c = ebot.Attributes[AppConsts.AttrMapBotsC].Value; var d = ebot.Attributes[AppConsts.AttrMapBotsD].Value; var mapbot = new MapBot(name, minLevel, maxLevel, c, d); var ecell = ebot.ParentNode; if (ecell != null) { var cellNumber = Cell.NormalizeRegNum(ecell.Attributes[AppConsts.AttrMapCellNumber].Value.Trim()); if (Cells.ContainsKey(cellNumber)) { Cells[cellNumber].AddMapBot(mapbot); } else { throw new Exception(cellNumber); } } } }