public static PersonState MoveAlongTheEdge(PersonState state, Edge edge) { var resultItems = state.Items.Select(item => new ItemUnit(item)).ToList(); foreach (var item in edge.RequestedItems.Where(a => a.IsDisappearing && a.BasicItem.InUse)) { resultItems.Find(a => a.BasicItem == item.BasicItem).Count -= item.Count; } // TODO: be careful with IsProhibiting foreach (var item in edge.To.RequestedItems.Where(a => a.BasicItem.IsProhibiting)) { var itemUnit = resultItems.Find(a => a.BasicItem == item.BasicItem); if (itemUnit != null) { itemUnit.Count -= item.Count; } if (item.BasicItem.IsVital && (itemUnit == null || itemUnit.Count <= 0)) { return null; } } AddItems(resultItems, edge.RecievedItems); AddItems(resultItems, edge.To.RecievedItems); RemoveUnnecessaryItems(resultItems); return new PersonState(edge.To.Id, resultItems, state, edge); }
public static PersonState MoveAlongTheEdge(PersonState state, Edge edge) { var resultItems = state.Items.Select(item => new ItemUnit(item)).ToList(); foreach (var item in edge.RequestedItems.Where(a => a.IsDisappearing && a.BasicItem.InUse)) { resultItems.Find(a => a.BasicItem == item.BasicItem).Count -= item.Count; } // TODO: be careful with IsProhibiting foreach (var item in edge.To.RequestedItems.Where(a => a.BasicItem.IsProhibiting)) { var itemUnit = resultItems.Find(a => a.BasicItem == item.BasicItem); if (itemUnit != null) { itemUnit.Count -= item.Count; } if (item.BasicItem.IsVital && (itemUnit == null || itemUnit.Count <= 0)) { return(null); } } AddItems(resultItems, edge.RecievedItems); AddItems(resultItems, edge.To.RecievedItems); RemoveUnnecessaryItems(resultItems); return(new PersonState(edge.To.Id, resultItems, state, edge)); }
public bool Equals(PersonState other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(other.ParagraphNo == this.ParagraphNo && ItemsWorker.ItemsAreEqual(other.Items, this.Items)); }
public bool Equals(PersonState other) { if (ReferenceEquals(null, other)) { return false; } if (ReferenceEquals(this, other)) { return true; } return other.ParagraphNo == this.ParagraphNo && ItemsWorker.ItemsAreEqual(other.Items, this.Items); }
public PersonState(int paragraphNo, List <ItemUnit> items, PersonState previousState, Edge previousEdge) { this.Items = items; this.ParagraphNo = paragraphNo; this.PreviousState = previousState; this.PreviousEdge = previousEdge; unchecked { m_HashCode = (this.Items.Where(item => item.BasicItem.InUse).Aggregate(0, (current, itemUnit) => current ^ (itemUnit.Count * 100003 + itemUnit.GetHashCode()))) ^ (1000003 * this.ParagraphNo); } }
public PersonState(int paragraphNo, List<ItemUnit> items, PersonState previousState, Edge previousEdge) { this.Items = items; this.ParagraphNo = paragraphNo; this.PreviousState = previousState; this.PreviousEdge = previousEdge; unchecked { m_HashCode = (this.Items.Where(item => item.BasicItem.InUse).Aggregate(0, (current, itemUnit) => current ^ (itemUnit.Count * 100003 + itemUnit.GetHashCode()))) ^ (1000003 * this.ParagraphNo); } }
public static bool EdgeIsAvailable(PersonState state, Edge edge) { // TODO: be carefull with InUse and IsProhibiting if (edge.RequestedItems.Any(item => !item.BasicItem.InUse && item.BasicItem.IsProhibiting)) { return(false); } foreach (var item in edge.RequestedItems.Where(item => item.BasicItem.IsProhibiting)) { var current = state.Items.Find(a => a.BasicItem == item.BasicItem); if (current == null || current.Count < item.Count) { return(false); } } return(true); }
public static bool EdgeIsAvailable(PersonState state, Edge edge) { // TODO: be carefull with InUse and IsProhibiting if (edge.RequestedItems.Any(item => !item.BasicItem.InUse && item.BasicItem.IsProhibiting)) { return false; } foreach (var item in edge.RequestedItems.Where(item => item.BasicItem.IsProhibiting)) { var current = state.Items.Find(a => a.BasicItem == item.BasicItem); if (current == null || current.Count < item.Count) { return false; } } return true; }
public SearchResultState(PersonState state, int distance) { State = state; Distance = distance; }
public SearchParameters(PersonState startState, SearchAlgorithm algorithm) { StartState = startState; Algorithm = algorithm; }