0
|
1 using UnityEngine;
|
|
2 using System.Collections.Generic;
|
|
3 using System.Collections;
|
|
4
|
|
5 public class DefaultNodePath : NodePath {
|
|
6 private List<int> path = new List<int>();
|
|
7
|
|
8 IEnumerator IEnumerable.GetEnumerator()
|
|
9 {
|
|
10 // call the generic version of the method
|
|
11 return this.GetEnumerator();
|
|
12 }
|
|
13
|
|
14 public IEnumerator<int> GetEnumerator()
|
|
15 {
|
7
|
16 return path.iterator ();
|
0
|
17 }
|
|
18
|
|
19 public DefaultNodePath() {
|
|
20 path = new List<int> ().addLast (-1);
|
|
21 }
|
|
22
|
|
23 private DefaultNodePath(List<int> path) {
|
|
24 this.path = path;
|
|
25 }
|
|
26
|
7
|
27 /// <summary>
|
|
28 /// Listに追加します。
|
|
29 /// path = path.add(0)を2回する
|
|
30 /// path = path.add(0).add(0)する
|
|
31 /// これは同じ
|
|
32 /// </summary>
|
|
33 /// <param name="pos">Position.</param>
|
0
|
34
|
|
35 public NodePath add(int pos) {
|
|
36 List<int> newPath = path.addLast(pos);
|
|
37 return new DefaultNodePath(newPath);
|
|
38 }
|
|
39
|
|
40 public Pair<int, NodePath> pop() {
|
|
41 int head = path.headList();
|
|
42 List<int> tail = path.deleteHead();
|
|
43 return new Pair<int, NodePath>(head, new DefaultNodePath(tail));
|
|
44 }
|
|
45
|
|
46 public Pair<int, NodePath> last() {
|
|
47 int last = path.headList();
|
|
48 List<int> list = path.deleteHead();
|
|
49 return new Pair<int, NodePath>(last, new DefaultNodePath(list));
|
|
50 }
|
|
51
|
7
|
52 public override string ToString() {
|
0
|
53 return path.toString();
|
|
54 }
|
|
55
|
|
56 public int size() {
|
|
57 return path.length();
|
|
58 }
|
|
59
|
|
60 public NodePath tail() {
|
|
61 List<int> tail = path.deleteLast ();
|
|
62 return new DefaultNodePath (tail);
|
|
63 }
|
|
64
|
|
65 public List<DefaultNodePath> inits() {
|
|
66 List<DefaultNodePath> paths = new List<DefaultNodePath> ();
|
|
67 List<int> coursePath = new List<int> ();
|
|
68 foreach (int tmpPath in path) {
|
|
69 List<int> tmp = coursePath.addLast (tmpPath);
|
|
70 paths = paths.addLast (new DefaultNodePath (tmp));
|
|
71 coursePath = tmp;
|
|
72 }
|
|
73 return paths;
|
|
74 }
|
|
75
|
|
76
|
|
77 }
|