public String[] showCastleMovementSuggestion(string current_position) { string[] arr = new string[58]; int counter = 0; int now_x = Int32.Parse(current_position.Split('_')[0]); int now_y = Int32.Parse(current_position.Split('_')[1]); /*diametery down to up */ int plus = 1, temp_i = now_x; bool first6 = false; int j = now_y; if (j < 6) { j++; } else { first6 = true; } for (int i = now_x; ; j += plus) { if (j == 6) { if (Board.condition_matrix[i, j] == DieClass.NO_DIE && !first6) { arr[counter++] = i + "_" + j; } // check this else if (DieClass.colorCheck(i, now_y) == color && !first6) //home has die but same color { break; } else { arr[counter++] = i + "_" + now_y; break; } //home has die but different color /**/ if (i != 12) { temp_i = (now_x + 12) % 24; } else { temp_i = 24; } /**/ if (Board.condition_matrix[temp_i, j] == DieClass.NO_DIE) { arr[counter++] = temp_i + "_" + j; } else if (DieClass.colorCheck(temp_i, now_y) == color) //home has die but same color { break; } else { arr[counter++] = temp_i + "_" + now_y; break; } //home has die but different color plus = -1; } else if (Board.condition_matrix[temp_i, j] == DieClass.NO_DIE) { arr[counter++] = temp_i + "_" + j; } else if (DieClass.colorCheck(temp_i, now_y) == color) //home has die but same color { break; } else { arr[counter++] = temp_i + "_" + now_y; break; } //home has die but different color if (i >= 25 || j >= 7 || i <= 0 || j <= 0) { break; } } /*diametery up to down */ plus = -1; temp_i = now_x; j = now_y; if (j > 1 && j <= 6) { j--; for (int i = now_x; j != 0; j += plus) { if (Board.condition_matrix[now_x, j] == DieClass.NO_DIE) { arr[counter++] = now_x + "_" + j; } else if (DieClass.colorCheck(now_x, now_y) == color) //home has die but same color { break; } else { arr[counter++] = now_x + "_" + now_y; break; } //home has die but different color if (i >= 25 || j >= 7 || i <= 0 || j <= 0) { break; } } } /*clockwise*/ int adder = now_x; if (adder == 24) { adder = 1; } else { adder = now_x + 1; } for (; ; adder++) { if (adder == 24 && adder != now_x) { if (Board.condition_matrix[adder, now_y] == DieClass.NO_DIE) { arr[counter++] = adder + "_" + now_y; } else if (DieClass.colorCheck(adder, now_y) == color) //home has die but same color { break; } else { arr[counter++] = adder + "_" + now_y; break; } //home has die but different color adder = 1; if (Board.condition_matrix[adder, now_y] == DieClass.NO_DIE && adder != now_x) { arr[counter++] = adder + "_" + now_y; } else if (DieClass.colorCheck(adder, now_y) == color) //home has die but same color { break; } else { arr[counter++] = adder + "_" + now_y; break; } //home has die but different color } else if (Board.condition_matrix[adder, now_y] == DieClass.NO_DIE && adder != now_x) { arr[counter++] = adder + "_" + now_y; } else if (DieClass.colorCheck(adder, now_y) == color) //home has die but same color { break; } else { arr[counter++] = adder + "_" + now_y; break; } //home has die but different color if (adder >= 25 || adder <= 0 || adder == now_x) { break; } } /*anti-clockwise*/ int subber = now_x; if (subber == 1) { subber = 24; } else { subber = now_x - 1; } for (; ; subber--) { if (subber == 1 && subber != now_x) { if (Board.condition_matrix[subber, now_y] == DieClass.NO_DIE) { arr[counter++] = subber + "_" + now_y; } else if (DieClass.colorCheck(subber, now_y) == color) //home has die but same color { break; } else { arr[counter++] = subber + "_" + now_y; break; } //home has die but different color subber = 24; if (Board.condition_matrix[subber, now_y] == DieClass.NO_DIE && subber != now_x) { arr[counter++] = subber + "_" + now_y; } else if (DieClass.colorCheck(subber, now_y) == color) //home has die but same color { break; } else { arr[counter++] = subber + "_" + now_y; break; } //home has die but different color } else if (Board.condition_matrix[subber, now_y] == DieClass.NO_DIE && subber != now_x) { arr[counter++] = subber + "_" + now_y; } else if (DieClass.colorCheck(subber, now_y) == color) //home has die but same color { break; } else { arr[counter++] = subber + "_" + now_y; break; } //home has die but different color if (subber >= 25 || subber <= 0 || subber == now_x) { break; } } return(arr); }
private string[] downLeft(int now_x, int now_y) { int counter = 0, i = now_x, j = now_y; string[] arr = new String[10]; int plus = 1; int minus = -1; bool flag2 = false, firstcome = true; if (j == 1) { if (i == 24) { i = 1; } else { i++; } j++; plus = 1; } else { if (i == 24) { i = 1; j--; plus = -1; } else /*if (j != 6)*/ { i++; j--; plus = -1; } //else { plus = -1; flag2 = true; } } minus = 1; for (; i != now_x || j != now_y; i += minus, j += plus) { if (i == now_x && j == now_y) { break; } if (j == 1 && i != now_x) { if (i == now_x && j == now_y) { break; } if (counter < 47 && Board.condition_matrix[i, j] == DieClass.NO_DIE) { arr[counter++] = i + "_" + j; } else if (DieClass.colorCheck(i, j) == color) /* do nothing */; { //home has die but same color } else { arr[counter++] = i + "_" + j; break; } //home has die but different color minus = 1; plus = 1; if (i == 24) { j++; plus = 1; i = 1; minus = 1; } else { i++; j++; minus = 1; plus = 1; } } if (j == 6) { if (i == now_x && j == now_y) { break; } if (Board.condition_matrix[i, j] == DieClass.NO_DIE) { arr[counter++] = i + "_" + j; } else if (DieClass.colorCheck(i, j) == color) //home has die but same color { break; } else { arr[counter++] = i + "_" + j; break; } //home has die but different color i = nextNumberTopToLeft(i); Debug.Log(i); if (Board.condition_matrix[i, j] == DieClass.NO_DIE) { arr[counter++] = i + "_" + j; } else if (DieClass.colorCheck(i, j) == color) //home has die but same color { break; } else { arr[counter++] = i + "_" + j; break; } //home has die but different color if (i == now_x && j == now_y) { break; } plus = -1; minus = 1; } else if (i == 24 && j != 6) { if (Board.condition_matrix[i, j] == DieClass.NO_DIE) { arr[counter++] = i + "_" + j; } else if (DieClass.colorCheck(i, j) == color) //home has die but same color { break; } else { arr[counter++] = i + "_" + j; break; } //home has die but different color i = 1; minus = 1; j += plus; if (j == 1) { plus = 1; } if (i == now_x && j == now_y) { break; } if (Board.condition_matrix[i, j] == DieClass.NO_DIE) { arr[counter++] = i + "_" + j; } else if (DieClass.colorCheck(i, j) == color) //home has die but same color { break; } else { arr[counter++] = i + "_" + j; break; } //home has die but different color } else if (j != 6 && counter < 47 && Board.condition_matrix[i, j] == DieClass.NO_DIE) { arr[counter++] = i + "_" + j; } else if (DieClass.colorCheck(i, j) == color) //home has die but same color { break; } else { arr[counter++] = i + "_" + j; break; } //home has die but different color }
public void printGameobject(Transform x) { turn %= 3; checkTurn(); if (x.transform.childCount == 1) { if (previous_obj) { previous_obj.color = previous_color; } Image im = x.gameObject.GetComponent <Image>(); previous_color = im.GetComponent <Image>().color; print(previous_color); previous_obj = im; im.color = selectedColor; whoIs = x.transform.GetChild(0).name; nowObject = x.transform.GetChild(0); pastX = x; string nameX = pastX.transform.name; s = nameX.Split('_'); current_position = nameX; int cx = Int32.Parse(current_position.Split('_')[0]); int cy = Int32.Parse(current_position.Split('_')[1]); current_die_color_id = Board.condition_matrix[cx, cy]; int clr = Int32.Parse(current_die_color_id.Split('_')[0]); current_die_color = DieClass.declareDieColor(clr); myKnight = new KnightClass(current_die_color); myCastle = new CastleClass(current_die_color); mySoldire = new SoldireClass(current_die_color); myBishop = new BishopClass(current_die_color); myQueen = new QueenClass(current_die_color); myKing = new KingClass(current_die_color); if (turn == 0 && current_die_color == DieClass.YELLOW_DIE || turn == 1 && current_die_color == DieClass.GREEN_DIE || turn == 2 && current_die_color == DieClass.RED_DIE) { if (whoIs == DieClass.KNIGHT_NAME) { String[] a = myKnight.showKnightMovementSuggestion(current_position); doColorHomes(a); int i = 0; foreach (string c in a) { print(i + ": " + c); i++; // Color the Homes for knight } } else if (whoIs == DieClass.CASTLE_NAME) { String[] arr = myCastle.showCastleMovementSuggestion(current_position); doColorHomes(arr); foreach (string c in arr) { print(c); // Color the Homes for castle } } else if (whoIs == DieClass.SOLDIRE_NAME) { String[] a = mySoldire.showSoldireMovementSuggestion(current_position); doColorHomes(a); int i = 0; foreach (string c in a) { print(i + ": " + c); i++; // Color the Homes for knight } } else if (whoIs == DieClass.BISHOP_NAME) { String[] arr = myBishop.showBishopMovementSuggestion(current_position); int i = 0; doColorHomes(arr); foreach (string c in arr) { print(i + ": " + c); i++; // Color the Homes for bishop } } else if (whoIs == DieClass.QUEEN_NAME) { String[] arr = myQueen.showQueenMovementSuggestion(current_position); int i = 0; doColorHomes(arr); foreach (string c in arr) { print(i + ": " + c); i++; // Color the Homes for queen } } } } else if ((x.transform.childCount == 0) && (turn == 0 && current_die_color == DieClass.YELLOW_DIE || turn == 1 && current_die_color == DieClass.GREEN_DIE || turn == 2 && current_die_color == DieClass.RED_DIE)) { audioData = GetComponent <AudioSource>(); goal_position = x.transform.name; int gx = Int32.Parse(goal_position.Split('_')[0]); int gy = Int32.Parse(goal_position.Split('_')[1]); goal_die_color_id = Board.condition_matrix[gx, gy]; int clr = Int32.Parse(goal_die_color_id.Split('_')[0]); if (clr >= 1 && clr <= 8) { goal_die_color = DieClass.GREEN_DIE; } else if (clr >= 9 && clr <= 16) { goal_die_color = DieClass.RED_DIE; } else { goal_die_color = DieClass.YELLOW_DIE; } /**/ isSecondClick = true; if (isSecondClick == true) { for (int i = 0; i < nowplaces.Length; i++) { if (nowplaces[i] != null && nowplaces[i] != "") { Image im = GameObject.Find(nowplaces[i]).gameObject.GetComponent <Image>(); im.color = previous_places_color[i]; } } print("isSecondClick"); isSecondClick = false; } turn_count++; if (whoIs == DieClass.SOLDIRE_NAME) { if (mySoldire.checkSoldiertMovementValidity(goal_position, current_position, current_die_color)) { conditionText.text = ("SOLDIRE MOVED").ToString(); string temp_current_position = current_position; try { if (doMove(x)) { Board.condition_matrix[Int32.Parse(goal_position.Split('_')[0]), Int32.Parse(goal_position.Split('_')[1])] = current_die_color_id; print(goal_position.Split('_')[0] + "_" + goal_position.Split('_')[1] + " Set Die"); Board.condition_matrix[Int32.Parse(temp_current_position.Split('_')[0]), Int32.Parse(temp_current_position.Split('_')[1])] = DieClass.NO_DIE; print(temp_current_position.Split('_')[0] + "_" + temp_current_position.Split('_')[1] + " Reset Die"); turn++; checkTurn(); } else { print("(200) Trouble ..."); } } catch (Exception) { print("(201) Trouble ..."); } conditionText.text = ("SOLDIRE MOVED").ToString(); } else { conditionText.text = ("WRONG").ToString(); conditionText.color = Color.red; } } else if (whoIs == DieClass.CASTLE_NAME) { if (myCastle.checkCastleMovementValidity(goal_position, current_position)) { string temp_current_position = current_position; conditionText.text = ("CASTLE MOVED").ToString(); try { if (doMove(x)) { Board.condition_matrix[Int32.Parse(goal_position.Split('_')[0]), Int32.Parse(goal_position.Split('_')[1])] = current_die_color_id; print(goal_position.Split('_')[0] + "_" + goal_position.Split('_')[1] + "Set Die"); Board.condition_matrix[Int32.Parse(temp_current_position.Split('_')[0]), Int32.Parse(temp_current_position.Split('_')[1])] = DieClass.NO_DIE; print(temp_current_position.Split('_')[0] + "_" + temp_current_position.Split('_')[1] + "No Die"); turn++; checkTurn(); } else { print("(100) Trouble ..."); } } catch (Exception) { print("(101) Trouble ..."); } } else { conditionText.text = ("WRONG").ToString(); conditionText.color = Color.red; } } else if (whoIs == DieClass.KNIGHT_NAME) { if (myKnight.checkKnightMovementValidity(goal_position, current_position)) { string temp_current_position; temp_current_position = current_position; conditionText.text = ("KNIGHT MOVED").ToString(); if (doMove(x)) { Board.condition_matrix[Int32.Parse(goal_position.Split('_')[0]), Int32.Parse(goal_position.Split('_')[1])] = current_die_color_id; print(goal_position.Split('_')[0] + "_" + goal_position.Split('_')[1] + "Set Die"); Board.condition_matrix[Int32.Parse(temp_current_position.Split('_')[0]), Int32.Parse(temp_current_position.Split('_')[1])] = DieClass.NO_DIE; print(temp_current_position.Split('_')[0] + "_" + temp_current_position.Split('_')[1] + "No Die"); turn++; checkTurn(); } } else { conditionText.text = ("WRONG").ToString(); conditionText.color = Color.red; } } else if (whoIs == DieClass.KING_NAME) { } else if (whoIs == DieClass.BISHOP_NAME) { if (myBishop.checkBishopMovementValidity(goal_position, current_position)) { string temp_current_position = current_position; conditionText.text = ("BISHOP MOVED").ToString(); try { if (doMove(x)) { Board.condition_matrix[Int32.Parse(goal_position.Split('_')[0]), Int32.Parse(goal_position.Split('_')[1])] = current_die_color_id; print(goal_position.Split('_')[0] + "_" + goal_position.Split('_')[1] + " Set Die"); Board.condition_matrix[Int32.Parse(temp_current_position.Split('_')[0]), Int32.Parse(temp_current_position.Split('_')[1])] = DieClass.NO_DIE; print(temp_current_position.Split('_')[0] + "_" + temp_current_position.Split('_')[1] + " No Die"); turn++; checkTurn(); } else { print("(300) Trouble ..."); } } catch (Exception) { print("(301) Trouble ..."); } } else { conditionText.text = ("WRONG").ToString(); conditionText.color = Color.red; } } else if (whoIs == DieClass.QUEEN_NAME) { if (myQueen.checkQueenMovementValidity(goal_position, current_position)) { string temp_current_position = current_position; conditionText.text = ("QUEEN MOVED").ToString(); try { if (doMove(x)) { Board.condition_matrix[Int32.Parse(goal_position.Split('_')[0]), Int32.Parse(goal_position.Split('_')[1])] = current_die_color_id; print(goal_position.Split('_')[0] + "_" + goal_position.Split('_')[1] + " Set Die"); Board.condition_matrix[Int32.Parse(temp_current_position.Split('_')[0]), Int32.Parse(temp_current_position.Split('_')[1])] = DieClass.NO_DIE; print(temp_current_position.Split('_')[0] + "_" + temp_current_position.Split('_')[1] + " No Die"); checkTurn(); } else { print("(400) Trouble ..."); } } catch (Exception) { print("(401) Trouble ..."); } } else { conditionText.text = ("WRONG").ToString(); conditionText.color = Color.red; } } } } private void checkTurn() { switch (turn % 3) { case 0: leftTurn.SetActive(true); rightTurn.SetActive(false); bottomTurn.SetActive(false); break; case 1: leftTurn.SetActive(false); rightTurn.SetActive(true); bottomTurn.SetActive(false); break; case 2: leftTurn.SetActive(false); rightTurn.SetActive(false); bottomTurn.SetActive(true); break; } } Boolean doMove(Transform x) { try { conditionText.color = Color.white; pastX = x; string nameX = pastX.transform.name; s = nameX.Split('_'); current_position = pastX.transform.name; nowObject.SetParent(x); nowObject.transform.localPosition = Vector3.zero; nowObject.transform.localRotation = Quaternion.Euler(0, 0, 0); nowObject.transform.Rotate(0f, 0f, -7f, Space.World); return(true); } catch (Exception) { print("Trouble ..."); return(false); } } public void doColorHomes(string[] arr) { for (int i = 0; i < nowplaces.Length; i++) { if (nowplaces[i] != null && nowplaces[i] != "") { // print("for yellow color :" + nowplaces[i]); nowplaces[i] = null; } } int counter = -1; /********* normalize to optimal array ******////// for (int i = 0; i < arr.Length; i++) { if (arr[i] != null && arr[i] != "") { counter++; // print("in arr :" + arr[i]); nowplaces[counter] = arr[i]; } } //print("Length :" + nowplaces.Length.ToString()); /********* get colors like a array ******////// int counter1 = -1; for (int i = 0; i < arr.Length; i++) { if (arr[i] != null && arr[i] != "") { counter1++; previous_places_color[counter1] = GameObject.Find(arr[i]).gameObject.GetComponent <Image>().color; } } /********* set color to suggestion homes ******////// for (int i = 0; i < nowplaces.Length; i++) { if (nowplaces[i] != null && nowplaces[i] != "") { // print("for yellow color :" + nowplaces[i]); Image im = GameObject.Find(nowplaces[i]).gameObject.GetComponent <Image>(); im.color = new Color32(255, 170, 7, 255); } } }