Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
        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 "";
     }
 }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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;
 }
Ejemplo n.º 10
0
 public override int GetHashCode()
 {
     return PieceId.GetHashCode() ^ HashIndex.GetHashCode();
 }