public List <T> FindSameBoxState(BoxState state) { if (state == null) { return(new List <T>()); } return(list.FindAll(s => s.IsBoxStateEquals(state))); }
public override bool Equals(Object obj) { BoxState s = obj as BoxState; if (object.ReferenceEquals(s, null)) { return(false); } return(this.IsBoxStateEquals(s)); }
public bool HasPath(BoxState end) { if (!ValidEnd(end)) { return(false); } if (this.queue.FindSameBoxState(end).Count > 0) { return(true); } return(RunToStop(state => state.IsBoxStateEquals(end))); }
public BoxMovingStep(BoxState state, int movingBoxIndex, BoxMovingDirection boxMovingDirection) { if (state == null) { throw new ArgumentNullException("state"); } if (movingBoxIndex < 0 || movingBoxIndex >= state.BoxCount) { throw new ArgumentOutOfRangeException("movingBoxIndex"); } Orignal = state; MovingBoxIndex = movingBoxIndex; MovingDirection = boxMovingDirection; }
public bool IsBoxStateEquals(BoxState state) { if (state == null || state.boxs.Length != this.boxs.Length) { return(false); } var s = boxs.ToList(); var d = state.boxs.ToList(); for (int i = 0; i < boxs.Length; i++) { if (!d.Remove(s[i])) { return(false); } } return(true); }
public List <BoxState> FindPath(BoxState end) { List <BoxState> path = new List <BoxState>(); if (this.HasPath(end)) { BoxState find = this.queue.FindSameBoxState(end).First(); path.Add(find); while (find.Parent != null) { path.Add(find.Parent); find = find.Parent; } path.Reverse(); } return(path); }
private bool ValidEnd(BoxState end) { if (end == null) { throw new ArgumentNullException("end"); } if (end.IsOverlapping) { return(false); } if (start.BoxCount != end.BoxCount) { return(false); } if (!end.IsMeetMap(map)) { return(false); } return(true); }