mirror of
https://github.com/Earth-Genesis-Games/Ajedrez_Purgatorio.git
synced 2026-09-11 09:47:35 +00:00
- Duel flow: mating piece vs boss while board collapses (PurgatoryDuelManager/Rules/UI/MuerteQuotes) - GameState.PurgatoryDuel + CampaignManager rescue/restart hooks + SquareClick routing - Dice-based rescue of most valuable dead identity; final defeat restarts Chapter 1 - 6 SFX clips wired in Ch1/2/3 via AudioClipAssigner - OptionsMenuController runtime audio/graphics panel, wired to MainMenu - Tests migrated to Assets/Tests/EditMode subfolders + PurgatoryDuelRulesTests (200 total) - Editor tools: DiagAssign, SpeakerDatabaseSetup, PurgatoryCanvasMaintenance
205 lines
5.7 KiB
C#
205 lines
5.7 KiB
C#
using NUnit.Framework;
|
|
using UnityEngine;
|
|
using UnityEngine.TestTools;
|
|
|
|
namespace AjedrezPurgatorio.Tests.Unit.Chess
|
|
{
|
|
[TestFixture]
|
|
[Category("Unit")]
|
|
[Category("Chess")]
|
|
[Category("CheckDetector")]
|
|
[Category("FastTests")]
|
|
public class CheckDetectorTests
|
|
{
|
|
private CheckDetector _detector;
|
|
private Piece[,] _board;
|
|
private GameObject _root;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
_detector = new CheckDetector();
|
|
_board = new Piece[8, 8];
|
|
_root = new GameObject("TestRoot");
|
|
}
|
|
|
|
[TearDown]
|
|
public void Teardown()
|
|
{
|
|
Object.DestroyImmediate(_root);
|
|
}
|
|
|
|
private T CreatePiece<T>(int x, int y, bool isWhite) where T : Piece
|
|
{
|
|
var go = new GameObject($"Piece_{typeof(T).Name}_{x}_{y}");
|
|
go.transform.SetParent(_root.transform);
|
|
var piece = go.AddComponent<T>();
|
|
piece.currentPos = new Vector2Int(x, y);
|
|
piece.isWhite = isWhite;
|
|
piece.hasMoved = true; // avoid castling logic
|
|
_board[x, y] = piece;
|
|
return piece;
|
|
}
|
|
|
|
#region IsInCheck Tests
|
|
|
|
[Test]
|
|
public void IsInCheck_NullBoard_ReturnsFalse()
|
|
{
|
|
LogAssert.Expect(LogType.Error, "[CheckDetector] Board es null.");
|
|
Assert.IsFalse(_detector.IsInCheck(null, true));
|
|
}
|
|
|
|
[Test]
|
|
public void IsInCheck_NoKingOnBoard_ReturnsFalse()
|
|
{
|
|
Assert.IsFalse(_detector.IsInCheck(_board, true));
|
|
}
|
|
|
|
[Test]
|
|
public void IsInCheck_WhiteKingNotAttacked_ReturnsFalse()
|
|
{
|
|
CreatePiece<King>(4, 0, true);
|
|
CreatePiece<Rook>(0, 0, true);
|
|
|
|
Assert.IsFalse(_detector.IsInCheck(_board, true));
|
|
}
|
|
|
|
[Test]
|
|
public void IsInCheck_WhiteKingAttackedByBlackRook_ReturnsTrue()
|
|
{
|
|
CreatePiece<King>(4, 0, true);
|
|
CreatePiece<Rook>(4, 5, false);
|
|
|
|
Assert.IsTrue(_detector.IsInCheck(_board, true));
|
|
}
|
|
|
|
[Test]
|
|
public void IsInCheck_WhiteKingAttackedByBlackBishop_ReturnsTrue()
|
|
{
|
|
CreatePiece<King>(4, 0, true);
|
|
CreatePiece<Bishop>(7, 3, false);
|
|
|
|
Assert.IsTrue(_detector.IsInCheck(_board, true));
|
|
}
|
|
|
|
[Test]
|
|
public void IsInCheck_WhiteKingAttackedByBlackKnight_ReturnsTrue()
|
|
{
|
|
CreatePiece<King>(4, 0, true);
|
|
CreatePiece<Knight>(2, 1, false);
|
|
|
|
Assert.IsTrue(_detector.IsInCheck(_board, true));
|
|
}
|
|
|
|
[Test]
|
|
public void IsInCheck_WhiteKingAttackedByBlackPawn_ReturnsTrue()
|
|
{
|
|
CreatePiece<King>(4, 4, true);
|
|
CreatePiece<Pawn>(3, 5, false);
|
|
|
|
Assert.IsTrue(_detector.IsInCheck(_board, true));
|
|
}
|
|
|
|
[Test]
|
|
public void IsInCheck_BlackKingAttackedByWhiteRook_ReturnsTrue()
|
|
{
|
|
CreatePiece<King>(4, 7, false);
|
|
CreatePiece<Rook>(4, 3, true);
|
|
|
|
Assert.IsTrue(_detector.IsInCheck(_board, false));
|
|
}
|
|
|
|
[Test]
|
|
public void IsInCheck_BlackKingNotAttacked_ReturnsFalse()
|
|
{
|
|
CreatePiece<King>(4, 7, false);
|
|
CreatePiece<Rook>(0, 7, false);
|
|
|
|
Assert.IsFalse(_detector.IsInCheck(_board, false));
|
|
}
|
|
|
|
[Test]
|
|
public void IsInCheck_PieceBlocksAttack_ReturnsFalse()
|
|
{
|
|
CreatePiece<King>(4, 0, true);
|
|
CreatePiece<Rook>(4, 7, false);
|
|
CreatePiece<Pawn>(4, 3, true);
|
|
|
|
Assert.IsFalse(_detector.IsInCheck(_board, true));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IsCheckmate Tests
|
|
|
|
[Test]
|
|
public void IsCheckmate_NotInCheck_ReturnsFalse()
|
|
{
|
|
CreatePiece<King>(4, 0, true);
|
|
CreatePiece<Rook>(0, 0, true);
|
|
|
|
Assert.IsFalse(_detector.IsCheckmate(_board, true));
|
|
}
|
|
|
|
[Test]
|
|
public void IsCheckmate_KingCanEscape_ReturnsFalse()
|
|
{
|
|
CreatePiece<King>(0, 0, true);
|
|
CreatePiece<Rook>(7, 7, false);
|
|
|
|
Assert.IsFalse(_detector.IsCheckmate(_board, true));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region WouldLeaveKingInCheck Tests
|
|
|
|
[Test]
|
|
public void WouldLeaveKingInCheck_NullBoard_ReturnsTrue()
|
|
{
|
|
var king = CreatePiece<King>(4, 0, true);
|
|
LogAssert.Expect(LogType.Error, "[CheckDetector] Board o piece es null.");
|
|
Assert.IsTrue(_detector.WouldLeaveKingInCheck(null, king, new Vector2Int(4, 1)));
|
|
}
|
|
|
|
[Test]
|
|
public void WouldLeaveKingInCheck_SafeMove_ReturnsFalse()
|
|
{
|
|
var king = CreatePiece<King>(4, 0, true);
|
|
CreatePiece<Rook>(4, 7, false);
|
|
|
|
Assert.IsFalse(_detector.WouldLeaveKingInCheck(_board, king, new Vector2Int(3, 0)));
|
|
}
|
|
|
|
[Test]
|
|
public void WouldLeaveKingInCheck_ExposesKingToCheck_ReturnsTrue()
|
|
{
|
|
var king = CreatePiece<King>(4, 3, true);
|
|
var blocker = CreatePiece<Pawn>(4, 5, true);
|
|
CreatePiece<Rook>(4, 7, false);
|
|
|
|
Assert.IsTrue(_detector.WouldLeaveKingInCheck(_board, blocker, new Vector2Int(3, 5)));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region HasAnyLegalMove Tests
|
|
|
|
[Test]
|
|
public void HasAnyLegalMove_EmptyBoard_ReturnsFalse()
|
|
{
|
|
Assert.IsFalse(_detector.HasAnyLegalMove(_board, true));
|
|
}
|
|
|
|
[Test]
|
|
public void HasAnyLegalMove_KingCanMove_ReturnsTrue()
|
|
{
|
|
CreatePiece<King>(4, 0, true);
|
|
Assert.IsTrue(_detector.HasAnyLegalMove(_board, true));
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|