/// <summary> /// Permet à une pièce de se déplacer. /// </summary> /// <param name="coordFrom">Coordonnée de départ du mouvement.</param> /// <param name="coordTo">Coordonnée de fin du mouvement.</param> public void move(int[] coordFrom, int[] coordTo) { m_board.movePiece(coordFrom, coordTo); String playerName = getCurrentPlayerName(); m_gameGUI.writeEvent(playerName + ": Déplacement valide vers X(" + (coordTo[0] + 1) + "), Y(" + (coordTo[1] + 1) + ")."); }
/// <summary> /// Demande au plateau de vérifiré la possibilité d'un échec et mat. /// </summary> /// <returns>Vrai si un des rois est en échec et mat.</returns> public bool askBoardCheckMat() { //trying move on temp board Board tempBoard = new Board(m_board.ToString()); for (int tileX = 0; tileX < tempBoard.Width; tileX++) { for (int tileY = 0; tileY < tempBoard.Width; tileY++) { if (tempBoard[tileX, tileY].isOccupied() && tempBoard[tileX, tileY].getPieceColor() == m_turn) { for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { if (x != 0 || y != 0) { int[] direction = new int[] { x, y }; int[] start = new int[] { tempBoard[tileX, tileY].X, tempBoard[tileX, tileY].Y }; int[] end = new int[] { start[0], start[1] }; Move tempMove = new Move(tempBoard[start[0], start[1]]); bool isOutOfIndex = true; bool isPossible = false; do { isOutOfIndex = !((end[0] + direction[0] > 0 && end[0] + direction[0] < 8) && (end[1] + direction[1] > 0 && end[1] + direction[1] < 8)); if (!isOutOfIndex) { end[0] += direction[0]; end[1] += direction[1]; tempMove.End = tempBoard[end[0], end[1]]; isPossible = (tempMove.isValidMovement() && !tempBoard.isCollisionning(tempMove.getCoordFrom(), tempMove.getCoordTo()) && tempBoard[tempMove.getCoordTo()[0], tempMove.getCoordTo()[1]].getPieceColor() != m_turn); if (isPossible) { tempBoard.movePiece(start, end); //Does the move puts us in check position on the temp board if (!tempBoard.detectCheck(m_turn)) { return(false); } tempBoard.movePiece(end, start); } } } while (!isOutOfIndex && isPossible); } } } } } } return(true); }
/// <summary> /// Demande au plateau de vérifiré la possibilité d'un échec et pat. /// </summary> /// <returns>Vrai si un des rois est en échec et pat.</returns> public bool askBoardCheckPat() { //trying move on temp board Board tempBoard = new Board(m_board.ToString()); for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { if (x != 0 || y != 0) { int[] direction = new int[] { x, y }; int[] start = m_board.getKingCoord(m_turn); int[] end = new int[] { start[0], start[1] }; if ((end[0] + direction[0] > 0 && end[0] + direction[0] < 8) && (end[1] + direction[1] > 0 && end[1] + direction[1] < 8)) { end[0] += direction[0]; end[1] += direction[1]; if (!m_board[end[0], end[1]].isOccupied()) { tempBoard.movePiece(start, end); //Does the move puts us in check position on the temp board if (!tempBoard.detectCheck(m_turn)) { return(false); } tempBoard.movePiece(end, start); } } } } } return(true); }
/// <summary> /// Demande au plateau de vérifiré la possibilité d'un échec. /// </summary> /// <returns>Vrai si un des rois est en échec.</returns> public bool askBoardCheck() { //trying move on temp board Board tempBoard = new Board(m_board.ToString()); tempBoard.movePiece(m_move.getCoordFrom(), m_move.getCoordTo()); if (m_turn == 'W') { return(tempBoard.detectCheck(m_turn)); } else { return(tempBoard.detectCheck(m_turn)); } //Does the move puts us in check position on the temp board }