private void botDrag() { Board bästaDrag = Rekursiv.BästaDrag(currentBoard, 1, Variabler.svårighetsGrad, 15000); ändraBoard(currentBoard, bästaDrag); GameObject.Find("ValdBit").GetComponentInChildren <TextMesh>().text = "Bot move: " + beräknaPosition(startPosition) + "-" + beräknaPosition(flyttPosition); }
private void selectPjäs(int x, int y) { if (flyttaPjäs) { return; } if (currentBoard.Pjäser[y, x] == null || currentBoard.Pjäser[y, x].färg == "Svart") //ska flytta egen pjäs { if (markeradPjäs != null) { Board testBoard = new Board(); testBoard.copyBoard(currentBoard); testBoard.Pjäser[y, x] = testBoard.Pjäser[markeradIndexY, markeradIndexX]; testBoard.Pjäser[markeradIndexY, markeradIndexX] = null; markeradPjäs = null; markeradIndexY = 0; markeradIndexX = 0; selectRam.transform.position = new Vector3(20, 20); if (Rekursiv.godkäntDrag(currentBoard, testBoard, 2, 0)) { ändraBoard(currentBoard, testBoard); } } } else //markerar egen pjäs { if (markeradPjäs == currentBoard.Pjäser[y, x]) //klickar på markerad pjäs { markeradPjäs = null; markeradIndexY = 0; markeradIndexX = 0; selectRam.transform.position = new Vector3(20, 20); return; } markeradPjäs = currentBoard.Pjäser[y, x]; markeradIndexY = y; markeradIndexX = x; selectRam.transform.position = currentBoard.Pjäser[y, x].objekt.transform.position - new Vector3(0.5f, 0); } }
void Update() { botDragCount++; if (botDragCount == 5) { botDrag(); } if (flyttaPjäs) { GameObject.Find("chessIndicator").transform.position = new Vector2(25f, 25f); flyttObjekt.objekt.transform.position += ((Vector3)(flyttPosition - startPosition)).normalized / 25; if ((flyttPosition - (Vector2)flyttObjekt.objekt.transform.position).magnitude < 0.05f) { flyttObjekt.objekt.transform.position = flyttPosition; if (tagenPjäs != null) { tagenPjäs.objekt.transform.position = new Vector2(20, 20); if (tagenPjäs.färg == "Vit") { tagenPjäs.objekt.transform.position = new Vector2((antalTagnaVita % 3) - 7.1f, 3 - antalTagnaVita / 3); antalTagnaVita++; } else { tagenPjäs.objekt.transform.position = new Vector2((antalTagnaSvarta % 3) - 7.1f, antalTagnaSvarta / 3 - 4); antalTagnaSvarta++; } tagenPjäs = null; } flyttObjekt.objekt.GetComponent <SpriteRenderer>().sortingOrder = 0; if (flyttObjekt.färg == "Vit") { botDragCount = 0; } if (Rekursiv.checkSchackmatt(currentBoard, 1, 0) || Rekursiv.checkSchackmatt(currentBoard, 1, 1)) { botDragCount = 10; GameObject.Find("Schackmatt").transform.position = new Vector2(5.6f, 0); GameObject.Find("Playagain").transform.position = new Vector2(5.6f, -2.05f); Destroy(turnIndicator); Destroy(GameObject.Find("Bakknapp")); Destroy(GameObject.Find("Reverseknapp")); Destroy(GameObject.Find("ValdBit")); Destroy(GameObject.Find("chessIndicator")); if (flyttObjekt.färg != "Vit") { GetComponent <AudioSource>().Play(); } } //if (flyttObjekt.färg == "Vit") //{ // botDragCount = 0; // if (Rekursiv.checkSchackmatt(currentBoard, 1, 0)) // { // Debug.Log("Schackmatt"); // botDragCount = 10; // } //} //else //{ // if (Rekursiv.checkSchackmatt(currentBoard, 1, 1)) // Debug.Log("Schackmatt"); //} turnFärg++; turnIndicator.GetComponent <SpriteRenderer>().color = new Color(turnFärg % 2, (turnFärg + 1) % 2, 0); flyttaPjäs = false; GameObject.Find("Scoreboard").GetComponentInChildren <TextMesh>().text = "Score: " + -currentBoard.boardVärde(true) / 100; if (Rekursiv.checkSchackmatt(currentBoard, 2, 0) || Rekursiv.checkSchackmatt(currentBoard, 2, 1)) { GameObject.Find("chessIndicator").transform.position = new Vector2(5.63f, -3.47f); } } } if (Input.GetButton("Fire1")) { klick = true; } else if (klick) { klick = false; Vector2 musPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (musPosition.x > -4.5f && musPosition.x < 3.5f && musPosition.y > -4.5f && musPosition.y < 3.5f) { selectPjäs((int)(musPosition.x + 4.5), (int)(3.5f - musPosition.y)); } } }
void Update() { delay++; if (delay == 4) { Board bästaDrag = Rekursiv.bästaDrag(currentBoard, 1, Variabler.svårighetsGrad, 0); ändraBoard(currentBoard, bästaDrag, Color.red); GameObject.Find("text").GetComponent <TextMesh>().text = "Column: " + (nyPjäs.transform.position.x + 6) / 1.5; } if (movePjäs) { if (hastighet < 0.12f) { hastighet += 0.01f; } nyPjäs.transform.position += new Vector3(0, -hastighet); if (nyPjäs.transform.position.y - yPosition < 0.06f) { hastighet = 0.05f; movePjäs = false; nyPjäs.transform.position = new Vector2(nyPjäs.transform.position.x, yPosition); if (nyPjäs.GetComponent <SpriteRenderer>().color.Equals(Color.green)) { delay = 0; GameObject.Find("turnIndicator").GetComponent <SpriteRenderer>().color = Color.red; } else { GameObject.Find("turnIndicator").GetComponent <SpriteRenderer>().color = Color.white; } if (currentBoard.getBoardVärde() > 50000 || currentBoard.getBoardVärde() < -50000) { GameObject slutKnapp = GameObject.Find("slutKnapp"); slutKnapp.transform.position = new Vector2(7.4f, -3.5f); blink script = slutKnapp.AddComponent <blink>(); delay = 10; förlorat = true; if (currentBoard.getBoardVärde() > 50000) { slutKnapp.GetComponentInChildren <TextMesh>().text = "You lost!"; script.färgRöd = true; } else { slutKnapp.GetComponentInChildren <TextMesh>().text = "You won!"; script.färgRöd = false; } } } } if (Input.GetButton("Fire1")) { klick = true; } else if (klick) { klick = false; Vector2 musPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (musPosition.x > -5.25f && musPosition.x < 5.25f && musPosition.y > -4.5) { if (musPosition.x < 0) { musPosition.x -= 1.5f; } valdRad((int)((musPosition.x / 1.5f) + 0.5) + 3); } } }