private void DrawTestBlack() { if (!isWhiteTurn) { draw = true; checkListChessman = new List <GameObject>(activeChessman); foreach (GameObject go in checkListChessman) { Chessman c = go.GetComponent <Chessman>(); if (!c.isWhite) { BlackStalemate = c.PossibleMove(); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (BlackStalemate[i, j]) { draw = false; return; } } } } } } if (draw) { Draw(); } }
private void BlackCheckMateTest() { blackCheckMate = true; checkListChessman = new List <GameObject>(activeChessman); foreach (GameObject go in checkListChessman) { Chessman c = go.GetComponent <Chessman>(); if (!c.isWhite) { BlackInCheckMate = c.PossibleMove(); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (BlackInCheckMate[i, j]) { blackCheckMate = false; return; } } } } } if (blackCheckMate) { WhiteTeamWin(); } }
private void MoveChessman(int x, int y) { if (selectedChessman.PossibleMove(x, y)) { Chessmans[selectedChessman.CurrentX, selectedChessman.CurrentY] = null; selectedChessman.transform.position = GetTileCenter(x, y); selectedChessman.SetPosition(x, y); Chessmans[x, y] = selectedChessman; if (!throwAgain) { isWhiteTurn = !isWhiteTurn; } } move = 0; selectedChessman = null; }
private bool[,] checkKingFreeMove(bool white) { bool[, ] free = new bool[8, 8]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { free[i, j] = true; } } if (white) { foreach (GameObject go in activeChessmans) { Chessman c = go.GetComponent <Chessman>(); if (!c.isWhite) { bool[,] r = c.PossibleMove(); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (r[i, j]) { free[i, j] = false; } } } } } } else { foreach (GameObject go in activeChessmans) { Chessman c = go.GetComponent <Chessman>(); if (c.isWhite) { bool[,] r = c.PossibleMove(); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (r[i, j]) { free[i, j] = false; } } } } } } return(free); }
private void MoveChessman(int x, int y) { if (selectedChessman.PossibleMove(x, y)) { Chessmans[selectedChessman.CurrentX, selectedChessman.CurrentY] = null; selectedChessman.transform.position = GetTileCenter(x, y); Chessmans[x, y] = selectedChessman; isWhiteTurn = !isWhiteTurn; //Black piece turn if white piece has been moved(swap turn) } selectedChessman = null; //Select next Chessman }
private bool CheckCanMove() { bool canMove = false; foreach (GameObject go in activeChessman) { Chessman chessmanPiece = go.GetComponent <Chessman>(); if (isWhiteTurn && chessmanPiece.isWhite) { allowedMoves = chessmanPiece.PossibleMove(); checkIllegalMoves(chessmanPiece.CurrentX, chessmanPiece.CurrentY); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (allowedMoves[i, j]) { canMove = true; } } } } else if (!isWhiteTurn && !chessmanPiece.isWhite) { allowedMoves = chessmanPiece.PossibleMove(); checkIllegalMoves(chessmanPiece.CurrentX, chessmanPiece.CurrentY); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (allowedMoves[i, j]) { canMove = true; } } } } } return(canMove); }
public void moves() { X = 0; piece[X].max = m = -999; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { c2 = BoardManager.Instance.Chessmans[i, j]; if (c2 != null && c2.isWhite) { rw = c2.PossibleMove(); } } } for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { c2 = BoardManager.Instance.Chessmans[i, j]; if (c2 != null && !c2.isWhite) { piece[X].c = BoardManager.Instance.Chessmans[i, j]; piece[X].pm = piece[X].c.PossibleMove(); if (piece[X].pm != null) { eval(); } X++; } } } for (int i = 0; i < 16; i++) { if (piece[i].max >= m) { X = i; m = piece[i].max; BoardManager.Instance.selectedChessman = piece[i].c; } } BoardManager.Instance.MoveChessman(piece[X].mx, piece[X].my); }
private bool IsStalemate() { bool isStalemate = true; if (isWhiteTurn) { King whiteKing = GameObject.FindGameObjectWithTag("WhiteKing").GetComponent <King>(); int whiteKingX = whiteKing.CurrentX; int whiteKingY = whiteKing.CurrentY; foreach (GameObject go in activeChessman) { Chessman chessPiece = go.GetComponent <Chessman>(); if (!chessPiece.isWhite) { allowedMoves = chessPiece.PossibleMove(); checkIllegalMoves(chessPiece.CurrentX, chessPiece.CurrentY); if (allowedMoves[whiteKingX, whiteKingY]) { isStalemate = false; } } } } else { King blackKing = GameObject.FindGameObjectWithTag("BlackKing").GetComponent <King>(); int blackKingX = blackKing.CurrentX; int blackKingY = blackKing.CurrentY; foreach (GameObject go in activeChessman) { Chessman chessPiece = go.GetComponent <Chessman>(); if (chessPiece.isWhite) { allowedMoves = chessPiece.PossibleMove(); checkIllegalMoves(chessPiece.CurrentX, chessPiece.CurrentY); if (allowedMoves[blackKingX, blackKingY]) { isStalemate = false; } } } } return(isStalemate); }
public bool ThreatenedSpace(int x, int y) { bool threatened = false; bool[,] possibleMovesList = new bool[8, 8]; foreach (GameObject chessman in activeChessman) { Chessman ch = chessman.GetComponent <Chessman>(); if (ch.GetType() != typeof(King)) { if (ch.isWhite != isWhiteTurn) { possibleMovesList = ch.PossibleMove(); if (possibleMovesList[x, y]) { threatened = true; } } } } return(threatened); }
private void SelectChessman(float xf, float yf, int x, int y) { //Debug.Log(yf); if ((yf < -0.3 && yf > -1.1)) //自分の駒台クリック { if (!isWhiteTurn) { return; } int rounded_x = Mathf.RoundToInt(xf); if (rounded_x >= 1 && rounded_x <= 8) { koma_id = 8 - rounded_x; } if (maisuuInt[koma_id] >= 1) { selectedChessman = whiteKomadai[koma_id]; allowedMoves = selectedChessman.PossibleMove(); BoardHighlights.Instance.HighlightAllowedMoves(allowedMoves); } return; } if ((yf < 10.1 && yf > 9.3)) //相手の駒台クリック { if (isWhiteTurn) { return; } int rounded_x = Mathf.RoundToInt(xf); if (rounded_x >= 1 && rounded_x <= 8) { koma_id = 7 + rounded_x; } if (maisuuInt[koma_id] >= 1) { selectedChessman = blackKomadai[koma_id]; allowedMoves = selectedChessman.PossibleMove(); BoardHighlights.Instance.HighlightAllowedMoves(allowedMoves); } return; } //Chessmansは駒のGameObjectが格納された9x9の二次元配列 //クリックされた座標に駒がないとき //クリックをなかったことにする if (Chessmans[x, y] == null) { return; } //手番じゃない方の駒がクリックされた時 //クリックをなかったことにする if (Chessmans[x, y].isWhite != isWhiteTurn) { return; } //ここよくわからん bool hasAtleastOneMove = false; // allowedMoves = Chessmans[x, y].PossibleMove(); //ここも //その駒が動けないなら選択した状態にしない //クリックをなかったことにする for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { if (allowedMoves[i, j]) { hasAtleastOneMove = true; } } } if (!hasAtleastOneMove) { return; } // //選択中の駒にその位置の駒を代入 selectedChessman = Chessmans[x, y]; //動ける升をハイライトする BoardHighlights.Instance.HighlightAllowedMoves(allowedMoves); }
private void checkIllegalMoves(int x, int y) { //create a temp variable for selected chessman Chessman tempSelectedChessman = Chessmans[x, y]; //temporarily remove selected piece from chessmans Chessmans[x, y] = null; //white king's position King whiteKing = GameObject.FindGameObjectWithTag("WhiteKing").GetComponent <King>(); King blackKing = GameObject.FindGameObjectWithTag("BlackKing").GetComponent <King>(); int whiteKingX = whiteKing.CurrentX; int whiteKingY = whiteKing.CurrentY; int blackKingX = blackKing.CurrentX; int blackKingY = blackKing.CurrentY; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (allowedMoves[i, j]) { //reset x and y of king in case piece is not king (see next comment) whiteKingX = whiteKing.CurrentX; whiteKingY = whiteKing.CurrentY; blackKingX = blackKing.CurrentX; blackKingY = blackKing.CurrentY; //if the piece is a king, reset their x and y to the square they are moving to if (tempSelectedChessman.GetType() == typeof(King)) { if (isWhiteTurn) { whiteKingX = i; whiteKingY = j; } else { blackKingX = i; blackKingY = j; } } //Debug.Log("allowed move at: " + i + ", " + j); Chessman originalStateChessman = Chessmans[i, j]; Chessmans[i, j] = tempSelectedChessman; //if where the piece is going to move has an enemy piece, temporarily remove that piece for the check foreach (GameObject c in activeChessman) { Chessman ch = c.GetComponent <Chessman>(); //if the piece is not about to be taken if (ch.CurrentX == i && ch.CurrentY == j) { //the piece has been taken, so don't check if it can eat the king } else { //white turn if (isWhiteTurn) { if (!ch.isWhite) { bool[,] enemyPossibleMoves = ch.PossibleMove(); if (enemyPossibleMoves[whiteKingX, whiteKingY]) { allowedMoves[i, j] = false; } } } //black turn else { if (ch.isWhite) { bool[,] enemyPossibleMoves = ch.PossibleMove(); if (enemyPossibleMoves[blackKingX, blackKingY]) { allowedMoves[i, j] = false; } } } } } Chessmans[i, j] = originalStateChessman; } } } //return removed chessman to it's rightful spot Chessmans[x, y] = tempSelectedChessman; }