Mercurial > hg > Database > jungle-sharp
comparison src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle/store/impl/DefaultNodePath.cs @ 0:dec15de2c6ff
first commit
author | Kazuma |
---|---|
date | Tue, 21 Jun 2016 17:11:12 +0900 |
parents | |
children | 02b2ab7bffe6 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:dec15de2c6ff |
---|---|
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 int[] _array; | |
9 int Count; | |
10 | |
11 IEnumerator IEnumerable.GetEnumerator() | |
12 { | |
13 // call the generic version of the method | |
14 return this.GetEnumerator(); | |
15 } | |
16 | |
17 public IEnumerator<int> GetEnumerator() | |
18 { | |
19 for (int i = 0; i < Count; i++) | |
20 yield return _array[i]; | |
21 } | |
22 | |
23 | |
24 | |
25 public void Start() { | |
26 NodePath p = new DefaultNodePath(); | |
27 p = p.add(1).add(2).add(3).add(4); | |
28 Debug.Log (p.ToString ()); | |
29 } | |
30 | |
31 public DefaultNodePath() { | |
32 path = new List<int> ().addLast (-1); | |
33 } | |
34 | |
35 private DefaultNodePath(List<int> path) { | |
36 this.path = path; | |
37 } | |
38 | |
39 | |
40 // public IEnumerator<int> iterator() { | |
41 // return path.iterator(); | |
42 // } | |
43 | |
44 public NodePath add(int pos) { | |
45 List<int> newPath = path.addLast(pos); | |
46 return new DefaultNodePath(newPath); | |
47 } | |
48 | |
49 public Pair<int, NodePath> pop() { | |
50 int head = path.headList(); | |
51 List<int> tail = path.deleteHead(); | |
52 return new Pair<int, NodePath>(head, new DefaultNodePath(tail)); | |
53 } | |
54 | |
55 public Pair<int, NodePath> last() { | |
56 int last = path.headList(); | |
57 List<int> list = path.deleteHead(); | |
58 return new Pair<int, NodePath>(last, new DefaultNodePath(list)); | |
59 } | |
60 | |
61 public string toString() { | |
62 return path.toString(); | |
63 } | |
64 | |
65 public int size() { | |
66 return path.length(); | |
67 } | |
68 | |
69 public NodePath tail() { | |
70 List<int> tail = path.deleteLast (); | |
71 return new DefaultNodePath (tail); | |
72 } | |
73 | |
74 public List<DefaultNodePath> inits() { | |
75 List<DefaultNodePath> paths = new List<DefaultNodePath> (); | |
76 List<int> coursePath = new List<int> (); | |
77 foreach (int tmpPath in path) { | |
78 List<int> tmp = coursePath.addLast (tmpPath); | |
79 paths = paths.addLast (new DefaultNodePath (tmp)); | |
80 coursePath = tmp; | |
81 } | |
82 return paths; | |
83 } | |
84 | |
85 | |
86 } |