int Max(GameObject[][] tab, int alpha, int beta, int poda) { if (poda == MAX_ITE) { return(dificuldade == 1 ? UtilityFacil(tab) : UtilityDificil(tab)); } int v = int.MinValue; for (int i = 0; i < tab.Length; i++) { for (int j = 0; j < tab[i].Length; j++) { if (tab[i][j] && tab[i][j].name.StartsWith(this.cor)) { List <Vector2> jogadasPossiveis = br.MovimentosPossiveis(tab, tab[i][j], new Vector2(i, j), true); foreach (Vector2 jogada in jogadasPossiveis) { GameObject[][] tabCopy = br.copiar(tab); tabCopy = br.AtualizaPosicoes(tabCopy, new Vector2(i, j), jogada, false); // br.AtualizaPosicoesRelativas(tabCopy, tab[i][j], jogada); int vLinha = Min(tabCopy, alpha, beta, poda + 1); if (poda == 0 && vLinha == v) { this.jogadas.Add(jogada); this.quem.Add(tab[i][j]); } if (vLinha > v) { v = vLinha; if (poda == 0) { this.jogadas.Clear(); this.quem.Clear(); this.jogadas.Add(jogada); this.quem.Add(tab[i][j]); } } // if(vLinha >= beta){ // return v; // } // if(vLinha>alpha){ // alpha = vLinha; // } } } } } return(v); }
//movimenta a peça para a posição do tile desejado public void movePiece(GameObject p, GameObject t) { gm.disableColliders(); if (p != null) { piece = p; } if (t != null) { tile = t; } string[] resp = null; Vector2 vec = new Vector2(); if (piece != null && tile != null) { pieceToMove = piece; posToGo = tile.transform.position; bm.clearTiles(); string respStr = tile.name; resp = respStr.Split(new char[] { ',' }); float[] respf = new float[2]; for (int i = 0; i < 2; i++) { respf[i] = float.Parse(resp[i]); } vec = new Vector2(respf[0], respf[1]); br.AtualizaPosicoes(piece, vec); ctrlMove = true; toc.Play(); if (piece.name.Contains("Pawn") && (vec.x == 0 || vec.x == 7)) { podeMudarTurno = false; gm.setPromoteToChange(piece); //podeMudarTurno = true; } if (pieceToMove.name.Contains("King") && br.getRoque()) { if (respf[1] == (float)1) { // roque curto if (piece.name.StartsWith("White")) { // roque curto do rei branco GameObject torre = brancas.transform.Find("White Rook 2").gameObject; GameObject tileDaTorre = GameObject.Find("0,2"); rookToMove = torre; rookPosToGo = tileDaTorre.transform.position; } else { // roque curto do rei preto GameObject torre = pretas.transform.Find("Black Rook 2").gameObject; GameObject tileDaTorre = GameObject.Find("7,2"); rookToMove = torre; rookPosToGo = tileDaTorre.transform.position; } roque = true; } else if (respf[1] == (float)5) { // roque longo if (piece.name.StartsWith("White")) { // roque longo do rei branco GameObject torre = brancas.transform.Find("White Rook 1").gameObject; GameObject tileDaTorre = GameObject.Find("0,4"); rookToMove = torre; rookPosToGo = tileDaTorre.transform.position; } else { // roque longo do rei preto GameObject torre = pretas.transform.Find("Black Rook 1").gameObject; GameObject tileDaTorre = GameObject.Find("7,4"); rookToMove = torre; rookPosToGo = tileDaTorre.transform.position; } roque = true; } } } }