diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Main/jungle-network/operations/NetworkNodePath.cs	Thu Dec 15 22:52:48 2016 +0900
@@ -0,0 +1,86 @@
+using UnityEngine;
+using System.Collections;
+using System.Collections.Generic;
+
+public class NetworkNodePath : NodePath {
+	LinkedList<int> Path;
+
+	public NetworkNodePath () {
+		Path = new LinkedList<int>();
+		Path.AddFirst(-1);
+	}
+
+	public NetworkNodePath (NodePath path){
+		Path = new LinkedList<int>();
+		foreach(int p in path) {
+			Path.AddLast(p);
+		}
+	}
+
+	// msg pack ni pointer wo watasenai point youso wo narabikaeru.
+	private NetworkNodePath (LinkedList<int> path) {
+		this.Path = path;
+	}
+
+	IEnumerator IEnumerable.GetEnumerator()
+	{
+		return this.GetEnumerator();
+	}
+
+	public IEnumerator<int> GetEnumerator()
+	{
+		foreach(var l in Path) {
+			yield return l;
+		}
+	}
+
+	public NodePath add (int pos) {
+		LinkedList<int> newPath = copyPath();
+		newPath.AddLast(pos);
+		return new NetworkNodePath(newPath);
+	}
+
+	public NodePath addHead(int pos) { // still java code.
+		LinkedList<int> newPath = copyPath();
+		newPath.AddFirst(pos);
+		return new NetworkNodePath(newPath);
+	}
+
+	public Pair<int, NodePath> pop () {
+		LinkedList<int> cPath = copyPath();
+		int e = cPath.First.Value;
+		cPath.RemoveFirst();
+		return new Pair<int, NodePath>(e, new NetworkNodePath(cPath));
+	}
+
+	public int size () {
+		return this.Path.Count;
+	}
+
+
+	public LinkedList<int> copyPath(){
+		LinkedList<int> newPath = new LinkedList<int>();
+		foreach(int i in this.Path) {
+			newPath.AddLast(i);
+		}
+		return newPath;
+	}
+
+	public override string ToString () {
+		return Path.ToString();
+	}
+
+	public NodePath tail() {
+		this.Path.RemoveLast();
+		return new NetworkNodePath(this.Path);
+	}
+
+	public Pair<int, NodePath> last () {
+		int lastValue = this.Path.Last.Value;
+		this.Path.RemoveLast();
+		return new Pair<int, NodePath>(lastValue, new NetworkNodePath(this.Path));
+	}
+
+
+
+}