Example #1
0
 public CommandMove Update(Character actor, Callback onFinish)
 {
     this.TargetActor = actor;
     this.MoveType    = EMoveType.SeekActor;
     this.OnFinish    = onFinish;
     return(this);
 }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Move"/> struct.
 /// Constructor for quiet promotion moves
 /// </summary>
 /// <param name="piece">The moving piece</param>
 /// <param name="from">The from square</param>
 /// <param name="to">The to square</param>
 /// <param name="type">The move type</param>
 /// <param name="promoted">The promotion piece</param>
 public Move(Piece piece, Square from, Square to, EMoveType type, Piece promoted)
     : this(from, to)
 {
     SetMovingPiece(piece);
     SetMoveType(type);
     SetPromotedPiece(promoted);
 }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Move"/> struct.
 /// Constructor for capture moves
 /// </summary>
 /// <param name="piece">The moving piece</param>
 /// <param name="captured">The captured piece</param>
 /// <param name="from">The from square</param>
 /// <param name="to">The to square</param>
 /// <param name="type">The move type</param>
 public Move(Piece piece, Piece captured, Square from, Square to, EMoveType type)
     : this(from, to)
 {
     SetMovingPiece(piece);
     SetCapturedPiece(captured);
     SetMoveType(type);
 }
Example #4
0
 public CommandMove Update(Vector3 destPosition, Callback onFinish)
 {
     this.TargetPos = destPosition;
     this.MoveType  = EMoveType.SeekPosition;
     this.OnFinish  = onFinish;
     return(this);
 }
    private void RecreateLevel()
    {
        _carrentBrushType  = EPipeType.None;
        _carrentBrushColor = -1;
        _carrentBrushParam = -1;
        _intBrush          = PIPE_TYPE_NONE_ID;
        _indexStart        = -1;
        _drawState         = EMoveType.None;

        _textures = new Texture[_w * _h];
        _neededStates.Clear();
        for (int i = 0; i < _w; ++i)
        {
            List <SSlotData> rowN = new List <SSlotData>();
            for (int j = 0; j < _h; ++j)
            {
                int id = GetSlotIndex(i, j);
                _textures[id] = _statesTexs[PIPE_TYPE_NONE_ID];

                SSlotData neededSlot = new SSlotData();
                neededSlot.x  = i;
                neededSlot.y  = j;
                neededSlot.c  = -1;
                neededSlot.p  = -1;
                neededSlot.pt = EPipeType.None;
                rowN.Add(neededSlot);
            }
            _neededStates.Add(rowN);
        }
    }
Example #6
0
 public CommandMove Update(Transform target, Callback onFinish)
 {
     this.Target   = target;
     this.MoveType = EMoveType.SeekTransform;
     this.OnFinish = onFinish;
     return(this);
 }
Example #7
0
 public Move(int x, int y, EMoveType type)
 {
     Debug.Assert(x >= 0 && x <= 7, "Wrong Move x Position!");
     Debug.Assert(y >= 0 && y <= 7, "Wrong Move y Position!");
     X    = x;
     Y    = y;
     Type = type;
 }
Example #8
0
        /// <summary>
        /// Determine if a move is legal or not, by performing the move and checking if the king is under attack afterwards.
        /// </summary>
        /// <param name="move">The move to check</param>
        /// <param name="piece">The moving piece</param>
        /// <param name="from">The from square</param>
        /// <param name="type">The move type</param>
        /// <returns>true if legal, otherwise false</returns>
        public bool IsLegal(Move move, Piece piece, Square from, EMoveType type)
        {
            if (!InCheck && piece.Type() != EPieceType.King && (Pinned & from).Empty() && !type.HasFlagFast(EMoveType.Epcapture))
            {
                return(true);
            }

            Position.IsProbing = true;
            Position.MakeMove(move);
            var opponentAttacking = Position.IsAttacked(Position.KingSquares[SideToMove.Side], ~SideToMove);

            Position.TakeMove(move);
            Position.IsProbing = false;
            return(!opponentAttacking);
        }
Example #9
0
    public void AddObjectToInventory(bool trade, GameObject prefab = null)
    {
        if (trade)
        {
            prefab = prefabToGive;
        }

        if (prefab)
        {
            moving = true;
            move   = EMoveType.RECEIVE;

            newObject = Instantiate(prefab, transform);
            if (trade)
            {
                previousObject = newObject;
            }

            colliders = newObject.GetComponents <Collider>();
            foreach (Collider collider in colliders)
            {
                collider.isTrigger = true;
            }

            rb            = newObject.GetComponent <Rigidbody>();
            rb.useGravity = false;
            rb.drag       = 0;

            newObject.transform.localPosition = spawnPos;
            targetPos   = receiveEndPos;
            rb.velocity = (targetPos - spawnPos);

            Interactible interactible = newObject.GetComponent <Interactible>();
            interactible.inspectionInterface = inspectionInterface;
            interactible.tutorialManager     = tutorialManager;
        }
        else
        {
            moving      = false;
            waiting     = false;
            currentTime = 0;
            EventManager.Instance.Raise(new BlockInputEvent()
            {
                block = false, navigation = false
            });
        }
    }
Example #10
0
    void Update()
    {
        if (waiting)
        {
            currentTime += Time.deltaTime;
            if (currentTime >= waitTime)
            {
                waiting     = false;
                currentTime = 0;
                EventManager.Instance.Raise(new BlockInputEvent()
                {
                    block = false, navigation = false
                });
            }
        }
        if (moving)
        {
            if (move == EMoveType.RECEIVE && newObject.transform.localPosition.z <= targetPos.z)
            {
                rb.velocity   = Vector3.zero;
                rb.useGravity = true;
                rb.drag       = drag;
                foreach (Collider collider in colliders)
                {
                    collider.isTrigger = false;
                }
                moving  = false;
                waiting = true;
            }
            else if (move == EMoveType.GIVE_FIRST_STEP && previousObject.transform.localPosition.y >= targetPos.y)
            {
                move = EMoveType.GIVE_SECOND_STEP;

                targetPos   = spawnPos;
                targetPos.x = previousObject.transform.localPosition.x;
                rb.velocity = (targetPos - previousObject.transform.localPosition);
            }
            else if (move == EMoveType.GIVE_SECOND_STEP && previousObject.transform.localPosition.z >= targetPos.z)
            {
                Destroy(previousObject);
                AddObjectToInventory(true);
            }
        }
    }
Example #11
0
    public void RemoveLastObjectFromInventory()
    {
        moving = true;
        move   = EMoveType.GIVE_FIRST_STEP;

        colliders = previousObject.GetComponents <Collider>();
        foreach (Collider collider in colliders)
        {
            collider.isTrigger = true;
        }

        rb            = previousObject.GetComponent <Rigidbody>();
        rb.useGravity = false;
        rb.drag       = 0;

        targetPos    = previousObject.transform.position;
        targetPos.y += 1;
        rb.velocity  = (targetPos - previousObject.transform.position);
    }
        public void SetDestination(List <Vector3> path, EMoveType moveType = EMoveType.Direct)
        {
            if (path.Count <= 1)
            {
                lhDebug.LogError((object)("Path count is: " + path.Count + "   " + path[0]));
                return;
            }
#if lhSyncGizmos
            foreach (Transform item in m_objParent.transform)
            {
                if (item == m_objParent.transform)
                {
                    continue;
                }
                UnityEngine.Object.Destroy(item.gameObject);
            }
            m_pathList.Clear();
            m_sourcePathList.Clear();
            for (int i = 0; i < path.Count; i++)
            {
                m_sourcePathList.Add(path[i]);
                var obj = new GameObject(i.ToString());
                obj.transform.position = path[i];
                obj.transform.parent   = m_objParent.transform;
            }
#endif
            m_path = path;
            //float totalDistance = CalculateTotalDistance(path.vectorPath);
            this.m_moveType        = moveType;
            this.m_speed           = Mathf.Lerp(m_speed, m_maxSpeed, Time.deltaTime * m_accerate);
            this.m_nextStep        = m_speed * Time.deltaTime;
            this.m_nextCornerIndex = 1;
            if (m_moveType == EMoveType.Direct)
            {
                m_nextDirection = GetSegementDirection().normalized;
            }
            else
            {
                m_nextDirection = GetSegementJump().normalized;
            }
            m_targetReached = false;
            m_canMove       = true;
        }
Example #13
0
        public void TestAllBasicMove()
        {
            Square           expectedFrom            = ESquare.a2;
            Square           expectedTo              = ESquare.h8;
            const EPieceType expectedMovingPieceType = EPieceType.Pawn;
            Piece            expectedMovingPiece     = EPieces.WhitePawn;
            Piece            expectedCapturedPiece   = EPieces.BlackKnight;
            Piece            expectedPromotionPiece  = EPieces.WhiteQueen;
            const EMoveType  expectedMoveType        = EMoveType.Promotion;

            // full move spectrum
            var move = new Move(expectedMovingPiece, expectedCapturedPiece, expectedFrom, expectedTo, expectedMoveType, expectedPromotionPiece);

            var actualFrom             = move.GetFromSquare();
            var actualTo               = move.GetToSquare();
            var actualMovingEPieceType = move.GetMovingPieceType();
            var actualMovingPiece      = move.GetMovingPiece();
            var actualCapturedPiece    = move.GetCapturedPiece();
            var actualPromotionPiece   = move.GetPromotedPiece();
            var actualEMoveType        = move.GetMoveType();

            // test promotion status
            Assert.True(move.IsPromotionMove());
            Assert.True(move.IsQueenPromotion());

            // test squares
            Assert.Equal(expectedFrom, actualFrom);
            Assert.Equal(expectedTo, actualTo);

            // test pieces
            Assert.Equal(expectedMovingPieceType, actualMovingEPieceType);
            Assert.Equal(expectedMovingPiece, actualMovingPiece);
            Assert.Equal(expectedCapturedPiece, actualCapturedPiece);
            Assert.Equal(expectedPromotionPiece, actualPromotionPiece);

            // move type
            Assert.Equal(expectedMoveType, actualEMoveType);
            Assert.False(move.IsCastlelingMove());
            Assert.False(move.IsDoublePush());
            Assert.False(move.IsEnPassantMove());
        }
Example #14
0
    void Move(EMoveType type)
    {
        float result = 0.0f;

        switch (type)
        {
        case EMoveType.eMT_Forward: {
            result = p_fMoveSpeed;
            break;
        }

        case EMoveType.eMT_BackWard: {
            result = -1 * p_fMoveSpeed;
            break;
        }

        case EMoveType.eMT_Idle: {
            result = 0;
            break;
        }
        }
        SetCurSpeed(result);
        UpdatePosition();
    }
Example #15
0
        private static void AddPawnMoves(this IPosition pos, MoveList moves, BitBoard targetSquares, Direction direction, EMoveType type, Emgf flags)
        {
            if (targetSquares.Empty())
            {
                return;
            }

            var stm   = pos.State.SideToMove;
            var piece = EPieceType.Pawn.MakePiece(stm);

            var promotionRank       = stm.PromotionRank();
            var promotionSquares    = targetSquares & promotionRank;
            var nonPromotionSquares = targetSquares & ~promotionRank;

            while (nonPromotionSquares)
            {
                var to   = nonPromotionSquares.Lsb();
                var from = to - direction;
                pos.AddMove(moves, piece, from, to, PieceExtensions.EmptyPiece, flags, type);
                BitBoards.ResetLsb(ref nonPromotionSquares);
            }

            type |= EMoveType.Promotion;

            if (flags.HasFlagFast(Emgf.Queenpromotion))
            {
                var sqTo   = promotionSquares.Lsb();
                var sqFrom = sqTo - direction;
                pos.AddMove(moves, piece, sqFrom, sqTo, EPieceType.Queen.MakePiece(stm), flags, type);
                BitBoards.ResetLsb(ref promotionSquares);
            }
            else
            {
                while (promotionSquares)
                {
                    var sqTo   = promotionSquares.Lsb();
                    var sqFrom = sqTo - direction;
                    for (var promotedPiece = EPieceType.Queen; promotedPiece >= EPieceType.Knight; promotedPiece--)
                    {
                        pos.AddMove(moves, piece, sqFrom, sqTo, promotedPiece.MakePiece(stm), flags, type);
                    }

                    BitBoards.ResetLsb(ref promotionSquares);
                }
            }
        }
Example #16
0
 /// <summary>
 /// Applies the move to the current matrix and gets the resulting one.
 /// </summary>
 /// <param name="moveType">Move type.</param>
 /// <returns></returns>
 public int[,] ApplyMove(EMoveType moveType)
 {
     throw new NotImplementedException();
 }
Example #17
0
 public static bool HasFlagFast(this EMoveType value, EMoveType flag) => (value & flag) != 0;
Example #18
0
        private void AddMove(ICollection <Move> moves, Piece piece, Square from, Square to, Piece promoted, EMoveType type = EMoveType.Quiet)
        {
            Move move;

            if (type.HasFlagFast(EMoveType.Capture))
            {
                move = new Move(piece, Position.GetPiece(to), from, to, type, promoted);
            }
            else if (type.HasFlagFast(EMoveType.Epcapture))
            {
                move = new Move(piece, EPieceType.Pawn.MakePiece(~SideToMove), from, to, type, promoted);
            }
            else
            {
                move = new Move(piece, from, to, type, promoted);
            }

            // check if move is actual a legal move if the flag is enabled
            if (Flags.HasFlagFast(Emgf.Legalmoves) && !IsLegal(move, piece, from, type))
            {
                return;
            }

            moves.Add(move);
        }
Example #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Move"/> struct.
 /// Constructor for capture+promotion moves
 /// </summary>
 /// <param name="piece">The moving piece</param>
 /// <param name="captured">The captured piece</param>
 /// <param name="from">The from square</param>
 /// <param name="to">The to square</param>
 /// <param name="type">The move type</param>
 /// <param name="promotedEPiece">The promotion piece</param>
 public Move(Piece piece, Piece captured, Square from, Square to, EMoveType type, Piece promotedEPiece)
     : this(piece, captured, from, to, type) => SetPromotedPiece(promotedEPiece);
Example #20
0
 public ChartMovedEventArgs(EMoveType move_type)
 {
     MoveType = move_type;
 }
Example #21
0
 /// <summary>
 /// Applies the move to the current matrix and gets the resulting one.
 /// </summary>
 /// <param name="moveType">Move type.</param>
 /// <returns></returns>
 public int[,] ApplyMove(EMoveType moveType)
 {
     throw new NotImplementedException();
 }
Example #22
0
        private void AddPawnMoves(MoveList moves, BitBoard targetSquares, Direction direction, EMoveType type)
        {
            if (targetSquares.Empty())
            {
                return;
            }

            var piece = EPieceType.Pawn.MakePiece(_position.State.SideToMove);

            foreach (var squareTo in targetSquares)
            {
                var squareFrom = squareTo - direction;
                if (!squareTo.IsPromotionRank())
                {
                    AddMove(moves, piece, squareFrom, squareTo, PieceExtensions.EmptyPiece, type);
                }
                else
                {
                    if (Flags.HasFlagFast(Emgf.Queenpromotion))
                    {
                        AddMove(moves, piece, squareFrom, squareTo,
                                EPieceType.Queen.MakePiece(_position.State.SideToMove),
                                type | EMoveType.Promotion);
                    }
                    else
                    {
                        for (var promotedPiece = EPieceType.Queen; promotedPiece >= EPieceType.Knight; promotedPiece--)
                        {
                            AddMove(moves, piece, squareFrom, squareTo,
                                    promotedPiece.MakePiece(_position.State.SideToMove),
                                    type | EMoveType.Promotion);
                        }
                    }
                }
            }
        }
Example #23
0
 public CommandMove Update(Vector3 motion)
 {
     this.Motion   = motion;
     this.MoveType = EMoveType.MoveForce;
     return(this);
 }
Example #24
0
        private static void AddMove(this IPosition pos, MoveList moves, Piece piece, Square from, Square to, Piece promoted, Emgf flags, EMoveType type = EMoveType.Quiet)
        {
            Move move;

            if (type.HasFlagFast(EMoveType.Capture))
            {
                move = new Move(piece, pos.GetPiece(to), from, to, type, promoted);
            }
            else if (type.HasFlagFast(EMoveType.Epcapture))
            {
                move = new Move(piece, EPieceType.Pawn.MakePiece(~pos.State.SideToMove), from, to, type, promoted);
            }
            else
            {
                move = new Move(piece, from, to, type, promoted);
            }

            // check if move is actual a legal move if the flag is enabled
            if (flags.HasFlagFast(Emgf.Legalmoves) && !pos.IsLegal(move, piece, from, type))
            {
                return;
            }

            moves.Add(move);
        }