//Function for Border Collision NOT IMPLIMENTED YET // void OnCollisionEnter2D(Collision2D Coll){ // float lastX; // float lastY; // if (Coll.gameObject.name == "Border1") { // moveL = false; // lastX = Input.mousePosition.x; // lastY = Input.mousePosition.y; // b1X = lastX + 10.0f; // transform.position = new Vector2 (b1X, lastY); // // } // //||Coll.gameObject.name == "Boarder2") // if (Coll.gameObject.name == "Boarder3"||Coll.gameObject.name == "Boarder4") { // //this.transform.position.y = this.transform.position.y - 0.3; // } // } //Check to see if tangram is finished if "this" and incoming peices have same positions public bool checkPos(Tans inTan) { //set the x and y boolian positions positions because we have a tolerance for each x/y position bool xCheck = false, yCheck = false; //These cut off any extra decimal points float xInTan = (float)((Mathf.Round(inTan.transform.position.x * 100)) / 100); float yInTan = (float)((Mathf.Round(inTan.transform.position.y * 100)) / 100); // if (this.type == inTan.type) { // Debug.Log (this.name + "x:" + this.myTanPosition.x + " " + inTan.name + "x:" + inTan.myTanPosition.x ); // Debug.Log (this.name + "y:" + this.myTanPosition.y + " " + inTan.name + "y:" + inTan.myTanPosition.y); // } //Check if x coordinate is in the tolerance range if (this.myTanPosition.x * 10 < (xInTan * 10 + 3) && this.myTanPosition.x * 10 > (xInTan * 10 - 3)) { //Check if y coordinate is in the tolerance range if (this.myTanPosition.y * 10 < (yInTan * 10 + 3) && this.myTanPosition.y * 10 > (yInTan * 10 - 3)) { //if they're the same type of Tan if (this.type == inTan.type) { //move the current tan to the position of the Puzzle Tan. this.transform.position = new Vector3(inTan.transform.position.x, inTan.transform.position.y, 1.0f); //set x & y to true xCheck = true; yCheck = true; } } } //return x & y check return(xCheck && yCheck); }
//checks to see if the direction of the tans are the same public bool checkRotation(Tans inTan) { switch (type) { case TangramType.Parallelogram: //For Paralellogram //Check what direction its facing if (flipped == inTan.flipped) { //if the direction is the same or 180 degrees different than return true return(direction == inTan.direction || direction + 4 == inTan.direction || direction - 4 == inTan.direction); } else { return(false); } case TangramType.Square: //For square // Debug.Log ("square Direction " + (this.direction % 2).ToString () + " VS " + (inTan.direction % 2).ToString ()); //Since a square rotated 90 degrees fits the same way it really only has 2 directions //we modulos to see if its one or the other and return true return(direction % 2 == inTan.direction % 2); default: return(direction == inTan.direction); } }
//分词,同时标注词性 public Tuple <string[], string[]> SplitToArray(string text) { string now = text; if (now.Length == 0) { return(null); } int ptr = 0; Tans[] ans = new Tans[10005]; int s = 0; while (ptr < now.Length) { if (now[ptr] == '\r' && now[ptr + 1] == '\n') { ptr += 2; continue; } ans[s] = new Tans(); int deep = 0; Tnode trie = root; for (int i = 0; i + ptr < now.Length; ++i) { char t = now[i + ptr]; if (!trie.mp.ContainsKey(t)) { break; } trie = trie.mp[t]; if (trie.ed) { deep = i + 1; ans[s].str = ""; for (int j = 0; j < deep; ++j) { ans[s].str += now[ptr + j]; } if (s == 0) { for (int j = 0; j <= K; ++j) { if (trie.sum > 0) { ans[s].each[j] = trie.each[j] * 1.0 / trie.sum; } else { ans[s].each[j] = 0; } ans[s].last[j] = -1; } } else { for (int j = 0; j < K; ++j) { int save = -1; double big = -1; for (int r = 0; r <= K; ++r) { if (ans[s - 1].each[r] * p[r, j] > big) { big = ans[s - 1].each[r] * p[r, j]; save = r; } } ans[s].each[j] = big * trie.each[j] * 1.0 / trie.sum; ans[s].last[j] = save; } ans[s].each[K] = 0; } } } if (deep == 0) { deep++; for (int j = 0; j < K; ++j) { ans[s].each[j] = 0; } ans[s].each[K] = 1; ans[s].str = ""; for (int j = 0; j < deep; ++j) { ans[s].str += now[ptr + j]; } if (s == 0) { ans[s].last[K] = -1; } else { int save = -1; double big = -1; for (int r = 0; r <= K; ++r) { if (ans[s - 1].each[r] > big) { big = ans[s - 1].each[r]; save = r; } } ans[s].last[K] = save; } } ptr += deep; s++; } int[] optlist = new int[10005]; double bb = -1; for (int i = 0; i <= K; ++i) { if (ans[s - 1].each[i] > bb) { optlist[s - 1] = i; bb = ans[s - 1].each[i]; } } for (int i = s - 1; i >= 1; --i) { int da, db; da = optlist[i]; db = ans[i].last[da]; optlist[i - 1] = db; } List <string> words = new List <string>(); List <string> semantics = new List <string>(); for (int i = 0; i < s; ++i) { words.Add(ans[i].str); semantics.Add(rtrans[optlist[i]]); } return(new Tuple <string[], string[]>(words.ToArray(), semantics.ToArray())); }