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