public void ItCanBeCompared() { PieceId def = PieceId.Default; PieceId some = new PieceId( PieceType.Bishop, PieceColor.Black, PieceEdition.ManRay ); PieceId nul = null; Assert.IsTrue(PieceId.Default == def); Assert.IsTrue(def == PieceId.Default); Assert.IsFalse(def == some); Assert.IsTrue(def != some); Assert.IsFalse(def != PieceId.Default); Assert.IsTrue(nul == null); Assert.IsTrue(null == nul); Assert.IsFalse(nul == def); Assert.IsFalse(def == nul); Assert.IsFalse(nul != null); Assert.IsFalse(null != nul); Assert.IsTrue(nul != def); Assert.IsTrue(def != nul); }
/// <summary> /// Creates a piece of given id at a given position /// </summary> private void CreatePiece(int x, int y, PieceId pieceId) { var go = InstantiatePrefabAt(piecePrefab, new Vector2Int(x, y)); var piece = go.GetComponent <Piece>(); piece.pieceId = pieceId; piece.SetPosition(x, y); pieces.Add(piece); }
/// <summary> /// Returns true if there's a friendly piece at the position /// </summary> private static bool IsFriend(Vector2Int position) { PieceId pieceIdAtPos = board.GetPieceIdAt(position); if (pieceIdAtPos == null) { return(false); } return(pieceIdAtPos.color == subjectId.color); }
/// <summary> /// Returns true if there's any kind of piece piece at the position /// </summary> private static bool IsOccupied(Vector2Int position) { PieceId pieceIdAtPos = board.GetPieceIdAt(position); if (pieceIdAtPos == null) { return(false); } return(true); }
public static List <ChessMove> GetPossibleMoves( Vector2Int subjectPosition, PieceId subjectId, Board board ) { PieceMovement.subjectPosition = subjectPosition; PieceMovement.subjectId = subjectId; PieceMovement.board = board; moves = new List <ChessMove>(); switch (subjectId.type) { case PieceType.Pawn: PawnMovement(); break; case PieceType.Rook: RookMovement(); break; case PieceType.Bishop: BishopMovement(); break; case PieceType.Knight: KnightMovement(); break; case PieceType.Queen: QueenMovement(); break; case PieceType.King: KingMovement(); break; default: FakeMovement(); break; } PieceMovement.subjectPosition = default(Vector2Int); PieceMovement.subjectId = null; PieceMovement.board = null; var ret = moves; moves = null; return(ret); }
public static string getResourceName(PieceId pieceId) { switch (pieceId) { case PieceId.Pawn: return "Pawn"; case PieceId.Rook: return "Rook"; case PieceId.Knight: return "Knight"; case PieceId.Bishop: return "Bishop"; case PieceId.Queen: return "Queen"; case PieceId.King: return "King"; default: return ""; } }
public override int GetHashCode() { int hash = 1; if (Id != 0) { hash ^= Id.GetHashCode(); } if (Letter.Length != 0) { hash ^= Letter.GetHashCode(); } if (Type != 0) { hash ^= Type.GetHashCode(); } if (UnlockLetterId != 0) { hash ^= UnlockLetterId.GetHashCode(); } if (HorizentalLinkId != 0) { hash ^= HorizentalLinkId.GetHashCode(); } if (VerticalLinkId != 0) { hash ^= VerticalLinkId.GetHashCode(); } if (PieceId != 0) { hash ^= PieceId.GetHashCode(); } if (PieceIndex != 0) { hash ^= PieceIndex.GetHashCode(); } return(hash); }
public async void OurMoveWasFinished(ChessMove ourMove) { clock.StartMe(); foreach (Vector2Int pos in Board.IteratePositions()) { PieceId pieceId = board.GetPieceIdAt(pos); if (pieceId == null) { continue; } if (pieceId.color != color) { continue; } await Task.Delay(Random.Range(500, 5_000)); float duration = clock.StopMe(); if (clock.IsTimeOverForMe()) { OnOutOfTime?.Invoke(); return; } OnMoveFinish?.Invoke(new ChessMove { origin = pos, target = FindFreeSpot(), duration = duration }); return; } throw new Exception(); }
public PieceMeta(PlayerId playerId, PieceId pieceId) { this.playerId = playerId; this.pieceId = pieceId; }
public override int GetHashCode() { return PieceId.GetHashCode() ^ HashIndex.GetHashCode(); }