Mercurial > hg > Database > jungle-sharp
comparison Main/jungle-network/operations/NetworkNodePath.cs @ 20:1f99e150f336
fix folder and add Object Mapper.
author | Kazuma Takeda |
---|---|
date | Thu, 15 Dec 2016 22:52:48 +0900 |
parents | |
children | f2ea780b3e80 |
comparison
equal
deleted
inserted
replaced
19:0865819106cf | 20:1f99e150f336 |
---|---|
1 using UnityEngine; | |
2 using System.Collections; | |
3 using System.Collections.Generic; | |
4 | |
5 public class NetworkNodePath : NodePath { | |
6 LinkedList<int> Path; | |
7 | |
8 public NetworkNodePath () { | |
9 Path = new LinkedList<int>(); | |
10 Path.AddFirst(-1); | |
11 } | |
12 | |
13 public NetworkNodePath (NodePath path){ | |
14 Path = new LinkedList<int>(); | |
15 foreach(int p in path) { | |
16 Path.AddLast(p); | |
17 } | |
18 } | |
19 | |
20 // msg pack ni pointer wo watasenai point youso wo narabikaeru. | |
21 private NetworkNodePath (LinkedList<int> path) { | |
22 this.Path = path; | |
23 } | |
24 | |
25 IEnumerator IEnumerable.GetEnumerator() | |
26 { | |
27 return this.GetEnumerator(); | |
28 } | |
29 | |
30 public IEnumerator<int> GetEnumerator() | |
31 { | |
32 foreach(var l in Path) { | |
33 yield return l; | |
34 } | |
35 } | |
36 | |
37 public NodePath add (int pos) { | |
38 LinkedList<int> newPath = copyPath(); | |
39 newPath.AddLast(pos); | |
40 return new NetworkNodePath(newPath); | |
41 } | |
42 | |
43 public NodePath addHead(int pos) { // still java code. | |
44 LinkedList<int> newPath = copyPath(); | |
45 newPath.AddFirst(pos); | |
46 return new NetworkNodePath(newPath); | |
47 } | |
48 | |
49 public Pair<int, NodePath> pop () { | |
50 LinkedList<int> cPath = copyPath(); | |
51 int e = cPath.First.Value; | |
52 cPath.RemoveFirst(); | |
53 return new Pair<int, NodePath>(e, new NetworkNodePath(cPath)); | |
54 } | |
55 | |
56 public int size () { | |
57 return this.Path.Count; | |
58 } | |
59 | |
60 | |
61 public LinkedList<int> copyPath(){ | |
62 LinkedList<int> newPath = new LinkedList<int>(); | |
63 foreach(int i in this.Path) { | |
64 newPath.AddLast(i); | |
65 } | |
66 return newPath; | |
67 } | |
68 | |
69 public override string ToString () { | |
70 return Path.ToString(); | |
71 } | |
72 | |
73 public NodePath tail() { | |
74 this.Path.RemoveLast(); | |
75 return new NetworkNodePath(this.Path); | |
76 } | |
77 | |
78 public Pair<int, NodePath> last () { | |
79 int lastValue = this.Path.Last.Value; | |
80 this.Path.RemoveLast(); | |
81 return new Pair<int, NodePath>(lastValue, new NetworkNodePath(this.Path)); | |
82 } | |
83 | |
84 | |
85 | |
86 } |