Пример #1
0
        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);
        }
Пример #2
0
        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));
        }
Пример #3
0
        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));
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
        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);
            }
        }
Пример #7
0
        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);
        }
Пример #8
0
        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;
        }
Пример #9
0
 public SearchResultState(PersonState state, int distance)
 {
     State = state;
     Distance = distance;
 }
Пример #10
0
 public SearchResultState(PersonState state, int distance)
 {
     State    = state;
     Distance = distance;
 }
Пример #11
0
 public SearchParameters(PersonState startState, SearchAlgorithm algorithm)
 {
     StartState = startState;
     Algorithm = algorithm;
 }
Пример #12
0
 public SearchParameters(PersonState startState, SearchAlgorithm algorithm)
 {
     StartState = startState;
     Algorithm  = algorithm;
 }