private Book(string name, BaseGraph baseGraph) { Name = name; this.CreateDate = DateTime.Now; this.m_Paragraphs = new Dictionary<int, Paragraph>(); this.m_Edges = new Dictionary<int, List<Edge>>(); foreach (var vertex in baseGraph.Vertices) { var paragraph = new Paragraph(vertex); if (baseGraph.Descriptions.ContainsKey(vertex)) { paragraph.Description = baseGraph.Descriptions[vertex]; } m_Paragraphs.Add(vertex, paragraph); m_Edges.Add(vertex, new List<Edge>()); } foreach (var simpleEdge in baseGraph.Edges) { var edge = new Edge(GetParagraph(simpleEdge.From), GetParagraph(simpleEdge.To), true); m_Edges[simpleEdge.From].Add(edge); } AvailableItems = new List<ItemType>(); }
public Edge(Paragraph @from, Paragraph to, bool isDefault) { From = @from; To = to; IsDefault = isDefault; IsChanged = !isDefault; IsAcite = true; RecievedItems = new List<ItemUnit>(); RequestedItems = new List<RequestedItemUnit>(); }
public ParagraphModel(Paragraph paragraph) { m_Paragraph = paragraph; m_RecievedItems = new ObservableCollection<ItemUnitModel>(); foreach (var recievedItem in m_Paragraph.RecievedItems) { m_RecievedItems.Add(new ItemUnitModel(recievedItem)); } m_RequestedItems = new ObservableCollection<RequestedItemUnitModel>( paragraph.RequestedItems.Select(item => new RequestedItemUnitModel(item))); }
private List<int> FindCycleDfs(Paragraph p, Paragraph prev, Dictionary<Paragraph, int> dict, Dictionary<Paragraph, Paragraph> way) { way[p] = prev; dict[p] = 1; foreach (var edge in m_Edges[p.Id]) { if (dict.ContainsKey(edge.To)) { if (dict[edge.To] == 1) { bool haveGold = false; List<int> result = new List<int> {p.Id}; Paragraph current = p; while (current != edge.To) { current = way[current]; result.Add(current.Id); } foreach (var id in result) { var paragraph = this.GetParagraph(id); if (paragraph.RecievedItems.Count > 0) { if (paragraph.RecievedItems.Any(item => item.BasicItem.Name == "Gold")) { haveGold = true; } } } if (haveGold) { result.Reverse(); return result; } } } else { var res = FindCycleDfs(edge.To, p, dict, way); if (res != null) { return res; } } } dict[p] = 2; return null; }
public void Update(BaseGraph baseGraph) { this.LastUpdateDate = DateTime.Now; foreach (var vertex in baseGraph.Vertices) { Paragraph paragraph; if (m_Paragraphs.ContainsKey(vertex)) { paragraph = m_Paragraphs[vertex]; } else { paragraph = new Paragraph(vertex); m_Paragraphs.Add(vertex, paragraph); m_Edges.Add(vertex, new List<Edge>()); } if (baseGraph.Descriptions.ContainsKey(vertex)) { paragraph.Description = baseGraph.Descriptions[vertex]; } } foreach (var simpleEdge in baseGraph.Edges) { var edges = this.GetEdges(simpleEdge.From, simpleEdge.To); // TODO: Check condition when to add/not add new edge if (!edges.Any(e => e.IsDefault)) { var edge = new Edge(m_Paragraphs[simpleEdge.From], m_Paragraphs[simpleEdge.To], true); m_Edges[simpleEdge.From].Add(edge); } } }