Esempio n. 1
0
        public static bool piecesConnect(int a, int b, int ax, int ay, int bx, int by)
        {
            // Returns true if the given pieces, with the given coordinates (in any arbitrary grid)
            // have connected paths.  In that case, it is permissible to move a person to that square.
            // First, are the pieces adjacent?
            if (Math.Abs(ax - bx) > 1)
            {
                return(false);
            }
            if (Math.Abs(ay - by) > 1)
            {
                return(false);
            }
            // Are they on the same square?
            if (ax == bx && ay == by)
            {
                return(false);
            }
            // With diagonals, this whole thing is more error-prone to code manually.  Use an integer array as described
            // above, under connectPlaceTile, to find the intersections.
            int dx = bx - ax; int dy = by - ay;   // dx/dy are change from a to get to b.  a will be seen as the "center."

            int[,] arr = new int[7, 7];
            Pieces.zeroArray(arr);
            Pieces.connectPlaceTile(a, 0, 0, arr);   // put tile A in the center
            Pieces.connectPlaceTile(b, dx, dy, arr); // put tile B at its relative position
            if (Pieces.countTwos(arr) > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }