public Snake(Snake parent, int newHeadPosition, bool incDim) { this.head = newHeadPosition; this.world = parent.world; if (incDim) { if (parent.visitedDim == world.Dimentions) { this.visitedDim = world.Dimentions; } else { this.visitedDim = parent.visitedDim + 1; } } else { this.visitedDim = parent.visitedDim; } if (!world.ValidPosition(head)) { throw new ArgumentException("Snake position is invalid"); } this.tail = new int[parent.tail.Length + 1]; for (int i = 0; i < parent.tail.Length; i++) { this.tail[i] = parent.tail[i]; } this.tail[tail.Length - 1] = head; // this.Parent = parent; this.heuristicFunction = parent.heuristicFunction; this.hValue = heuristicFunction.calc_h(this); }
// private LinkedList<INode> children; public Snake(World world, int head, ISnakeHeuristic heuristicFunction, bool useDim = true) { this.head = head; this.world = world; this.visitedDim = (useDim ? 0 : world.Dimentions); if (!world.ValidPosition(head)) { throw new ArgumentException("Snake position is invalid"); } this.tail = new int[1]; this.tail[this.tail.Length - 1] = head; // this.Parent = null; this.heuristicFunction = heuristicFunction; this.hValue = heuristicFunction.calc_h(this); }