public void BlackNode_GetAndSet(PgnMoveInformation?Black)
        {
            var mp = new MovePair()
            {
                BlackNode = Black
            };

            Assert.AreEqual(Black, mp.BlackNode);
        }
        public void WhiteNode_GetAndSet(PgnMoveInformation?white)
        {
            var mp = new MovePair()
            {
                WhiteNode = white
            };

            Assert.AreEqual(white, mp.WhiteNode);
        }
示例#3
0
        public int CompareTo(object obj)
        {
            MovePair other = (MovePair)obj;

            if (distance > other.distance)
            {
                return(1);
            }
            if (distance < other.distance)
            {
                return(-1);
            }
            return(0);
        }
        public bool IsFull_Test(PgnMoveInformation?white, PgnMoveInformation?black)
        {
            var mp = new MovePair(white, black);

            return(mp.IsFull);
        }
示例#5
0
    public virtual bool TestRoomValidity(Board board)
    {
        int margin = Constants.ROOM_MARGIN;

        bool movedNorth = false;
        bool movedSouth = false;
        bool movedEast  = false;
        bool movedWest  = false;

        int cachedX = x;
        int cachedY = y;

        if (x < board.boardMargin)
        {
            x = board.boardMargin;
        }
        movedEast = true;
        if (y < board.boardMargin)
        {
            y = board.boardMargin;
        }
        movedNorth = true;
        if (x + width > board.columns - board.boardMargin)
        {
            x = board.columns - board.roomMargin - width;
        }
        movedWest = true;
        if (y + height > board.rows - board.boardMargin)
        {
            y = board.rows - board.boardMargin - height;
        }
        movedSouth = true;

        bool moved = false;

        int northFreedom = 0;
        int southFreedom = 0;
        int eastFreedom  = 0;
        int westFreedom  = 0;

        GetDoorwayFreedoms(ref northFreedom, ref southFreedom, ref eastFreedom, ref westFreedom);

        MovePair moveEast = new MovePair(0, delegate(Room target) {
            if (!movedWest)
            {
                int desiredX   = target.x + target.width + margin;
                int difference = desiredX - x;
                if (difference <= eastFreedom && desiredX + width <= board.columns - board.boardMargin)
                {
                    eastFreedom -= difference;
                    westFreedom += difference;
                    movedEast    = true;
                    moved        = true;
                    x            = desiredX;
                }
            }
        });
        MovePair moveWest = new MovePair(0, delegate(Room target) {
            if (!movedEast)
            {
                int desiredX   = target.x - width - margin;
                int difference = x - desiredX;
                if (difference <= eastFreedom && desiredX >= board.boardMargin)
                {
                    westFreedom -= difference;
                    eastFreedom += difference;
                    movedEast    = true;
                    moved        = true;
                    x            = desiredX;
                }
            }
        });
        MovePair moveNorth = new MovePair(0, delegate(Room target) {
            if (!movedSouth)
            {
                int desiredY   = target.y + target.height + margin;
                int difference = desiredY - y;
                if (difference <= northFreedom && desiredY + height <= board.rows - margin)
                {
                    eastFreedom -= difference;
                    westFreedom += difference;
                    movedNorth   = true;
                    moved        = true;
                    y            = desiredY;
                }
            }
        });
        MovePair moveSouth = new MovePair(0, delegate(Room target) {
            if (!movedNorth)
            {
                int desiredY   = target.y - height - margin;
                int difference = y - desiredY;
                if (difference <= southFreedom && desiredY <= board.boardMargin)
                {
                    westFreedom -= difference;
                    eastFreedom += difference;
                    movedSouth   = true;
                    moved        = true;
                    y            = desiredY;
                }
            }
        });
        List <MovePair> options = new List <MovePair>()
        {
            moveEast, moveWest, moveNorth, moveSouth
        };

        List <Room> collisionRooms = new List <Room>(board.stories[story].rooms);

        Rect rect = new Rect(x - margin, y - margin, width + margin, height + margin);

        for (int i = 0; i < collisionRooms.Count; i++)
        {
            Room room      = collisionRooms[i];
            Rect otherRect = new Rect(room.x - room.margin, room.y - room.margin, room.width + room.margin, room.height + room.margin);
            if (rect.Overlaps(otherRect))
            {
                moved = false;

                moveEast.distance  = x + width + margin - room.x;
                moveWest.distance  = room.x + room.width + margin - x;
                moveNorth.distance = y + height + margin - room.y;
                moveSouth.distance = room.y + room.height + margin - y;

                options.Sort();
                foreach (MovePair movePair in options)
                {
                    if (movePair.distance > 0)
                    {
                        movePair.action(room);
                        if (moved)
                        {
                            break;
                        }
                    }
                }

                if (!moved)
                {
                    return(false);
                }
                //It won't be able to collide anymore
                collisionRooms.Remove(room);
                i = 0;
            }
        }
        //If it all worked, make corrections to doorways and hallways
        foreach (Doorway doorway in doorways)
        {
            if (DirectionUtil.Orientation(doorway.roomOutDirection) == Orientation.Horizontal)
            {
                doorway.x += x - cachedX;
                doorway.corridor.length += x - cachedX;
            }
            else
            {
                doorway.y += y - cachedY;
                doorway.corridor.length += y - cachedY;
            }
        }
        return(true);
    }