/// <summary> /// Reset/Restart from the Start Position /// </summary> public void ResetState() { Check = false; GameEnded = false; foreach (GameObject restorePiece in MoveHistory.Instance.EliminatedObjects) { if (restorePiece == null) { continue; } piecesOnBoard.Add(restorePiece); pieceAction.FadeIn(restorePiece); } foreach (GameObject piece in piecesOnBoard) { PieceInformation pieceInfo = piece.GetComponent <PieceInformation>(); if (pieceInfo.BeenPromoted) { pieceInfo.BeenPromoted = false; UndoPromotion(piece); } // Update board UpdateBoard(pieceInfo.CurrentXPosition, pieceInfo.CurrentZPosition, pieceInfo.GetOriginalX(), pieceInfo.GetOriginalZ(), piece); // Reset to piece's default values pieceInfo.CurrentXPosition = pieceInfo.GetOriginalX(); pieceInfo.CurrentZPosition = pieceInfo.GetOriginalZ(); pieceInfo.PieceMoves = 0; // Reset location Vector3 endPosition = new Vector3(pieceInfo.GetOriginalX(), 0, pieceInfo.GetOriginalZ()); pieceAction.ChangePosition(piece, endPosition, (int)pieceInfo.colour); } MoveHistory.Instance.Clear(); // Reset turn - White Start ResetTurn(); }
/// <summary> /// Checks if pawn can eliminate the opponent's pawn as per En Passant rule. /// </summary> /// <param name="position"> Position of the pawn </param> /// <param name="colour"> Colour of the pawn </param> /// <returns> True if pawn can be eliminated </returns> public bool EnPassant(Vector3 position, Vector3 direction, int colour) { LayerMask layer = whiteMask; if (colour == 1) { layer = blackMask; } RaycastHit hit; if (Physics.Raycast(position, direction, out hit, 0.055f, layer)) { GameObject pieceCollided = hit.collider.gameObject; PieceInformation piece = pieceCollided.GetComponent <PieceInformation>(); // Check if opponent's pawn in the direction provided. if ((int)piece.type == 5 && (int)piece.colour != colour) { // Check if the pawn is displaced two positions from its original position if (Math.Abs(piece.CurrentZPosition - piece.GetOriginalZ()) != 2) { return(false); } // Check if the pawn has only moved once. if (piece.PieceMoves != 1) { return(false); } return(true); } } return(false); }