Universal Reconfiguration of Facet-Connected Modular Robots by Pivots: The O(1) Musketeers

We present the first universal reconfiguration algorithm for transforming a modular robot between any two facet-connected square-grid configurations using pivot moves. More precisely, we show that five extra “helper” modules (“musketeers”) suffice to reconfigure the remaining n modules between any two given configurations. Our algorithm uses O(n2)\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$O(n^2)$$\end{document} pivot moves, which is worst-case optimal. Previous reconfiguration algorithms either require less restrictive “sliding” moves, do not preserve facet-connectivity, or for the setting we consider, could only handle a small subset of configurations defined by a local forbidden pattern. Configurations with the forbidden pattern do have disconnected reconfiguration graphs (discrete configuration spaces), and indeed we show that they can have an exponential number of connected components. But forbidding the local pattern throughout the configuration is far from necessary, as we show that just a constant number of added modules (placed to be freely reconfigurable) suffice for universal reconfigurability. We also classify three different models of natural pivot moves that preserve facet-connectivity, and show separations between these models.


Introduction
Shape shifting is a powerful idea in science fiction: T-1000 robots (from Terminator 2: Judgement Day), Changelings (from Star Trek: Deep Space 9), Symbiotes (from Venom), Mystique (from X-Men), and Metamorphagi (from Harry Potter) all have the ability to transform their shape nearly arbitrarily.How can we make shape shifting into science?
Modular robots [5,20,23] are perhaps the best answer to this question.The idea is to build a single "robot" out of many small units called modules, each of which can attach and detach from each other, move relative to each other, communicate with each other, and compute.Modular robots offer extreme adaptability to changing environment or user needs, in particular by reconfiguring the modules into exponentially many effective shapes of the overall robot.Modularity also offers a practical future for manufacturing (identical modules can be mass-produced, making them relatively cheap), makes robots easy to repair by just replacing the broken modules, and makes it possible to re-use components from one robot/task to another.
For computational geometry, modular robots offer exciting challenges: what shapes can a modular robot self-reconfigure into, and what are good algorithms for reconfiguration?According to [20], the main difficulties in self-reconfiguration are the physical motion constraints of the modules themselves, connectivity requirements for the robot to hold together, collisions between moving and/or static modules, and "deadlocks" where no module can move or some module gets "trapped" within the configuration.
The wide diversity of mechatronic solutions to modular robots can be characterized from a geometric viewpoint by three key properties: (1) the lattice, (2) connectivity requirement, and (3) allowed moves.
Lattice Most modular robots follow a space-filling lattice structure (for example, squares or hexagons in 2D, or cubes in 3D), to simplify both reconfiguration and the characterization of possible shapes.Pure lattice modular robots [2,6,11,14,18,21] have one robot per lattice element and always remain on the lattice, while hybrid modular robots [15,17,19,24] also allow units move out of the lattice.We focus here on the well-studied square lattice, though we suspect our results can be generalized to cube lattices.
Connectivity requirement A modular robot generally needs to be connected at all times while reconfiguring, so that the modules do not fall apart.The most common and practical constraint is that the modules are always facet-connected, meaning a connected facet-adjacency graph where vertices represent modules and edges represent adjacencies by shared facets (edges in 2D).The exception is that the moving module is excluded from this graph during each move, meaning that other modules must be facet-connected while the moving module may briefly disconnect during the move.A weaker connectivity constraint, considered in some theoretical research [4,Ch. 4], is that the robot is connected via shared vertices.In such case, reconfiguration is always possible.We focus here on the more challenging facet-connectivity constraint.
Allowed moves One of the most popular models is sliding squares/cubes [1,[7][8][9], illustrated in Fig. 1 (left).In this case, modules live in a square or cube lattice, move by sliding relative to each other, and require facet-connectivity.For this model, universal reconfiguration is possible between any two facet-connected configurations, in any dimension [1,7].
We focus here on a more challenging model, pivoting squares/cubes [4,21,22], illustrated in Fig. 1 (right).In this case, modules live in a square or cube lattice, move by rotating relative to each other, and require facet-connectivity.The key difference is that a module needs two additional squares/cubes of empty space in order to pivot to a facet-adjacent position, whereas a slide just needs the destination square/cube to be empty.Unfortunately, some configurations are rigid in this model, meaning that no module can move without disconnecting the robot.
Rigid configurations appear also in the sliding square model when the sliding capability is restricted to turning corners [13].However, in this model the existence of free space around the modules does not guarantee reconfigurability, while in the pivoting squares model it does, as we will discuss later.
As a consequence, all known reconfiguration algorithms for pivoting squares/ cubes are somehow partial.One algorithm follows some heuristics without a termination guarantee [3] (see also [12] for heuristics for hexagons).A recent algorithm guarantees reconfiguration by forbidding one or more local patterns in both the start and goal configurations [21], essentially preventing narrow holes in the shape.(A similar result was obtained for hexagons [16].)These assumptions severely restrict the possible shapes that can be reconfigured, to a o(1) fraction.The absence of such local patterns though is far from being necessary for reconfigurability.In 3D, some further strong conditions are added, such as that every hole must be orthogonally convex [21].
Our results Our main result is that universal reconfiguration is possible if we allow the addition of a constant number of (five) extra "helper" modules, which a s s a s Fig. 1 Contrast between the sliding model (left) and the pivoting model (right).Top: The two ways a module a starting above module s can move to the adjacent lattice position, above module s ′ .Bottom: The two ways a module a starting above module s can move to the square to the right of s.Pivoting requires more free squares (marked with a grey cross) to execute Algorithmica (2021) 83:1316-1351 we call musketeer modules. 1 A similar idea was recently applied to a slightly different model of programmable matter in [13], where helpers are called seeds.The key is that these helper modules are not considered part of the initial or target shape, and thus we are free to place them where we like (in particular, along the external boundary of the robot).Surprisingly, this small amount of additional freedom is enough to achieve universal reconfiguration.In fact, we prove in Sect. 4 that five musketeer modules are both sufficient and sometimes necessary to solve any reconfiguration under our strategy.Our algorithm is centralized and based on the old idea of following the right-hand rule to escape a maze [10].The number of pivoting moves it makes is O(n 2 ) , which is optimal in the worst case by an earth-moving lower bound: each module may need to move a distance of (n).This result can be seen as proving connectivity of the reconfiguration graph G n,k , where vertices represent facet-connected configurations of n modules and edges represent valid pivot moves, with the addition of k ≥ 5 musketeer modules.With k = 0 musketeers, G n,k is known to be disconnected.Surprisingly, there have been no (successful) attempts to understand the structure of this reconfiguration graph.In Sect.3, we analyze the structure of this reconfiguration graph.Specifically, we prove that G n,0 can have an exponential number of connected compo- nents of exponential size, and in some models, can have an exponential number of singleton connected components (rigid configurations); while in other models, the reconfiguration graph cannot have any singleton connected components.
One other main contribution of this paper is to precisely define a variety of natural models for pivot moves.Pivoting is naturally defined as the rotation of one module about one of its vertices that is shared with a (static) module.But there are some subtleties in this definition depending on exactly which modules must be facet-connected at what times.(Obviously, the moving module is not facet-connected to the others during the move.)In Sect.2, we define three nested models, each at least as powerful as the previous, and in Sect.3.1, we prove strict separations between these models.Our analysis of connected components in the configuration space (in Sect.3) also considers the effects of these different models.We conclude with open problems in Sect. 5.

Pivot Moves
In a square grid, the fact that two squares may share a vertex without actually sharing an edge opens a wider range of possibilities for the pivoting move.Refer to Fig. 2. The most restrictive set of moves (Set 1 in Fig. 2) requires module a to be facet-adjacent to module s and to rotate about one of the two vertices of the edge they share.Such move can be a 90 • or a 180 • rotation, depending on whether or not s has a neighboring module s ′ adjacent to it through the other edge of s incident to the rotation center, and of course, requires the goal grid position to be empty and some intermediate positions to be (at least partially) clear.These cells are depicted in white in Fig. 2.
The authors of [21] propose an expanded set of moves (Set 2 in Fig. 2) that allows module a to rotate 90 • about module s even when s ′ is not present, as long as module a is again facet-adjacent to another module t at the end of the move.Since their reconfiguration algorithm relies on reversible moves, this implies allowing also the reverse move: module a can rotate 90 • about a vertex of another module s incident to a, without requiring s to be facet-adjacent to a, as long as a is facet-adjacent to some module before performing the move and after performing the move.We call this enlarged set the leapfrog set of moves.If the previous move is allowed (i.e., if it is feasible for a given modular robot prototype), it seems natural to allow concatenating more than one of such moves, i.e., to allow concatenating consecutive rotations about vertices incident to the pivoting module.It is easy to prove that such concatenation cannot involve more than two pivots before the moving module becomes facet-adjacent to another module.Indeed, if a module a is facet-adjacent to a module s 1 , after at most two such moves it neces- sarily becomes adjacent to a module s 2 (Set 3 in Fig. 2).We call this complete set the monkey set of moves.
It is worth noticing that diagonal monkey jumps may be unnecessary for most purposes, since a diagonal monkey jump can be simulated by ignoring the presence of module s 2 and keep rotating about s 1 and its neighboring modules.Naturally, this would imply performing a higher number of pivoting moves.We further discuss this issue in Sect.4.1.

Reconfiguration Problem
Consider a configuration C of n robot modules in a given grid.The facet-adjacency graph of C has a node for each module, and an edge between a pair of nodes if the corresponding modules are facet-adjacent.Throughout this paper we will often refer to the facet-adjacency graph simply as the adjacency graph.We will say that a configuration C is facet-connected if the adjacency graph of C is connected.
Applying a pivot move from one of the three sets of moves described in the previous section to a facet-connected configuration C, means applying one of the moves to a module in C, in such a way that the configuration (without the pivoting module) stays facet-connected before, after, and during the move, and the pivoting module does not collide with any other module.Note that this implies that even after deleting the moving module the configuration remains facet-connected.Reconfiguring C consists of applying a concatenation of such moves.
The (universal) reconfiguration problem asks whether it is possible to reconfigure any facet-connected configuration of n modules in a given grid into any other configuration with the same number of modules.For simplicity in the description, we assume that modules are indistinguishable (unlabeled) and that translations are allowed.However, if any two configurations of n indistinguishable modules can be transformed into each other then any two configurations can also be transformed into each other preserving a labeling.To see that, we use that any two configurations of n indistinguishable modules can be transformed into each other if and only if any configuration can be transformed to a straight strip of modules of width one.Many algorithms for reconfiguring modular robots, including ours, make use of this fact.(The straight strip is also denoted straight-chain configuration in the literature.)If the modules are labeled, we can first reconfigure into a straight strip and then sort them in the desired order, as in [9].Similarly, the straight strip can be used for universal reconfiguration if translations are not allowed.In particular, our reconfiguration algorithm can be easily modified to handle labeled modules and if translations are not allowed.
For any positive integer n, the reconfiguration graph G n has a node for each facet- connected configuration with n modules, and an edge between two nodes if the corresponding configurations can be reconfigured into each other through a single pivoting move.We call rigid any configuration in which no module can move, i.e., any configuration that is an isolated node of G n , forming a connected component that is a singleton.We call locked any configuration that cannot be reconfigured into a straight strip of modules, i.e., any configuration belonging to a connected component of G n that does not contain a strip.

Reconfiguration Graph
Figure 3 (left) shows an example of a configuration that is rigid under the largest possible set of pivoting moves (Set 3 in Fig. 2).In [21] it is proved that reconfiguration for Set 2 of pivoting moves (leapfrog moves) is possible between two facetconnected configurations of the same number of squares, provided that they are both admissible shapes.Admissibility is defined in terms of forbidden patterns: a facetconnected configuration of squares is admissible if it does not contain any of the three patterns-, I , and Z -depicted in Fig. 4.However, this local separation condition is certainly not necessary, as proved by the example in Fig. 3 (right).
These results raise several natural questions for facet-connected pivoting squares: Are the three sets of moves equivalent?In particular, is reconfigurability between admissible shapes also guaranteed when using the most restrictive set of pivoting moves?This latter question has been answered positively by the results from [21].Although not explicitly stated, the reconfiguration algorithm from [21] uses only restrictive moves.
Several other interesting questions are open.Can the admissible condition be relaxed when using the largest set of pivoting moves?Do there exist rigid configurations that contain only one type of pattern?If so, are they rigid with respect to all three sets of pivoting moves?What can we say about the reconfiguration graph G n for the different sets of pivoting moves?We try to answer these questions in the remaining of this section.

Separation Between the Different Sets of Moves
We start by showing that the three sets of moves for pivoting squares are not equivalent, as they produce three different reconfiguration graphs.

Proposition 1
The monkey set of moves for pivoting squares (Set 3) is stronger than the leapfrog set (Set 2), and the leapfrog set is stronger than the restrictive set (Set 1).That is, the resulting reconfiguration graph G n has strictly fewer connected components for Set 3 than for Set 2, and fewer connected components for Set 2 than for Set 1.
Proof To show the above inequalities, we first recall that the leapfrog set (Set 2) also allows the moves allowed by the restrictive set (Set 1), and that the monkey moves (Set 3) include the moves allowed by the leapfrog set (Set 2).Hence, in order to prove this proposition, it suffices to show that there exist two configurations that can be reconfigured to each other using the leapfrog set (Set 2), but not using the restrictive set (Set 1), and that there exist two configurations that can be reconfigured to each other using the monkey moves (Set 3), but not using the leapfrog set (Set 2).
To show the first inequality consider the two configurations from Fig. 5, which include a single module that can pivot without disconnecting the configuration (shaded pink).This module can pivot along some piece of the boundary that is Fig. 5 Two shapes that can be reconfigured into each other using the leapfrog set of moves, but cannot be reconfigured into each other using the restrictive set of moves (the only module that can move is the highlighted one inside the rectangular hole, but it can neither leave the hole, nor reach the target position, nor allow other modules to move) different depending on the pivoting moves allowed.If the leapfrog pivoting moves (Set 2) are used, the two configurations belong to the same connected component of G n , but not if only the restrictive pivoting moves (Set 1) are allowed.For the sec- ond inequality consider the configuration in Fig. 6.It is rigid for the leapfrog set of moves (Set 2), but it can easily be reconfigured into a strip using the monkey moves (Set 3).□ Let us now discuss the differences between the three forbidden patterns (depicted in Fig. 4).From a purely geometric viewpoint, pattern produces a (corner) bottleneck along the boundary of a configuration that is narrower than the one produced by pattern I (corridor bottleneck).This one is in turn narrower than the one produced by pattern Z (wide bottleneck).The next propositions show how the presence or the absence of each of such patterns influences reconfiguration under each of the three sets of pivoting moves.

Pattern : Corner Bottleneck
We start by showing that pattern alone suffices to make a configuration rigid, regardless of the set of pivoting moves used (restrictive, leapfrog, or monkey).
Proposition 2 Let G n be the reconfiguration graph of facet-connected pivoting squares.If only pattern is allowed, while patterns I and Z are forbidden, the number of connected components of G n that are singletons and the number of connected components of G n of exponential size are both exponential in n for sufficiently large n, regardless of the set of pivoting moves used.Proof Figure 7 (top) shows a rigid configuration.Notice that the dark gray set of blocks forming an x-monotone path in the adjacency graph can be configured in (2 n ) ways, since there are n − 80 dark-gray modules and each pair of consecutive dark gray modules can be connected at least in two different ways while still maintaining monotonicity in the x-direction and avoiding the creation of a new cycle.
We can modify this construction to obtain the locked configuration from Fig. 7, where each of the pink modules can pivot inside a hole.First, no matter where the pink modules sit, none of the gray modules can move.Therefore, if the number of such inner holes of the configuration is k, the size of the corresponding connected component of G n is 8 k .Moreover, each of the light pieces creating an inner hole has at most 72 modules.Second, if the path of dark modules has length p, the number of different connected components that are obtained is (2 p ) , since again each pair of consecutive dark modules can be connected at least in two different ways.The construction is completed by making k = ⌊ n∕73⌋ and p = n − 73k for any 0 <  < 1 , we have that asymptotically there are 2 (n) components of 2 (n) size.□

Pattern I : Corridor Bottleneck
The forbidden pattern I is weaker than pattern in the sense that it suffices to make a configuration rigid for the sets of moves 1 and 2 (restrictive and leapfrog).However, if the entire Set 3 of moves is allowed, pattern I alone cannot make a configuration rigid, as shown by Proposition 4 below.
Proposition 3 Let G n be the reconfiguration graph of facet-connected pivoting squares under sets 1 and 2 of pivoting moves (restrictive and leapfrog).If only pattern I is allowed, and patterns and Z are forbidden, the number of connected components of G n that are singletons and the number of connected components of G n of exponential size are both exponential in n for sufficiently large n.Proof Figure 8 shows a configuration containing only pattern I that is rigid under sets 1 and 2 of pivoting rules.The path of dark modules can have different shapes, as each pair of consecutive dark modules can be facet-adjacent in at least two ways while maintaining the path monotonic in the x-direction.Let p be the length of such path.Thus, a rigid construction without the part containing the pink modules can be configured in (2 p ) ways which is 2 (n) if p is (n) .If we included the gadgets con- taining the pink modules, we obtain a locked configuration, where each of the pink modules can pivot to three different positions independently.Each gadget contains 13 modules and an example is shown in the yellow box in Fig. 8. Therefore, if the number of such gadgets is k, the size of the corresponding connected component of The right and the left ends of the configuration shown in Fig. 8 consist of 22 modules each.Additionally, there is one extra module placed between the dark path and the right end to ensure that there is only one adjacency between the two.
Assuming n > 45 , and making k = ⌊ (n − 45)∕13⌋ and p = n − (45 + 13k) for any 0 <  < 1 we have that asymptotically there are 2 (n) components of 2 (n) size.□ In contrast, if the entire set of monkey-pivoting moves is allowed, then no configuration can be rigid if it only contains instances of pattern I (and no instance of patterns and Z ).
Proposition 4 Let G n be the reconfiguration graph of facet-connected pivoting squares under the entire Set 3 of monkey-pivoting moves.If only pattern I is allowed, and patterns and Z are forbidden, then G n contains no singleton components.
In order to prove this result, we make use of two definitions and a lemma.Definition 1 A corner of a facet-connected configuration of squares is a module that is adjacent to at least two empty grid positions through two consecutive edges: North and East, South and East, North and West, or South and West.
Definition 2 Let G be the facet-adjacency graph of a given facet-connected configuration of squares.The cactus graph T(G) of G is defined as follows.For each simple cycle C in G, consider the set Region(C) of grid positions that lie in C or are enclosed by C. A simple cycle C is said to be maximal if Region(C) is maximal with respect to inclusion.We define T(G) as the graph obtained after the deletion of modules enclosed by a cycle.The cactus graph has a "tree structure".It is composed by maximal cycles, degree-1 vertices that are not enclosed by cycles, and paths connecting them.A connector of a maximal cycle is a vertex adjacent to a vertex in T(G) not in the maximal cycle.A leaf of the cactus graph is either a degree-1 vertex or a maximal cycle with a single connector.Figure 9 illustrates this definition.Although without a specific name or designation, this same graph has been previously used in [7] to help prove the connectedness of the reconfiguration graph of modular robots that follow the sliding cube model.

Lemma 1 Let C be any configuration of facet-connected squares. Let G be the facetadjacency graph of C. There always exists a corner in C that is not a cut vertex of G.
Proof Let T(G) be the cactus graph of G.If T(G) has a node m of degree one, then m corresponds to a corner in C that is not a cut vertex of G, so the lemma holds.Otherwise, we view T(G) as a tree of cycles, and arbitrarily pick a leaf cycle in T(G) (note that at least one such leaf cycle exists).The leaf cycle must have a corner different from its connector.Such a node cannot be a cut vertex.□ We can now proceed to prove Proposition 4.

Proof of Proposition 4
Let C be a configuration of facet-connected pivoting squares that does not contain patterns and Z .By Lemma 1 there exists a module c in C such that i) c is a corner and ii) removal of c does not disconnect C. We will prove that c can pivot.Assume, without loss of generality, that c is a North-East corner, and that it is connected to the rest of C through its South; refer to Fig. 10.Since c is a North-East corner, the grid positions to its East and North are empty.Since patterns and Z do not appear in C, the grid positions (1, 1) and (2, 1) relative to c are also empty.There are two possibilities for the grid position South-East from c.If it is occupied by a module, then c can pivot 90 • ; see Fig. 10a.If it is empty, then again there are two possibilities for the grid position (2, 0) relative to c.If it is occupied, then c can pivot 90 • ; see Fig. 10b.If it is empty, consider the grid position (2, −1) with respect to c.If this is empty too, then c can pivot 180 • ; see Fig. 10c.If it is occupied, then c can make a straight monkey jump; see Fig. 10d.

Pattern Z : Wide Bottleneck
The forbidden pattern Z is weaker than the forbidden patterns and I in the sense that no configuration can be rigid if it contains only instances of pattern Z .
Proposition 5 Let G n be the reconfiguration graph of facet-adjacent pivoting squares.If only pattern Z is allowed, and patterns and I are forbidden, then G n contains no singleton components, regardless of the set of pivoting moves allowed.
Proof Let C be a configuration of facet-connected pivoting squares that does not contain patterns I and Z .By Lemma 1 there exists a module c in C such that i) c is a corner and ii) removal of c does not disconnect C. We will prove that c can pivot.Assume, without loss of generality, that c is a North-East corner, and that it is connected to the rest of C through its South.Since c is a North-East corner, the grid positions to its East and North are empty.Since pattern does not appear in C, the grid position to the North-East of c is also empty.Finally, there are two possibilities for the grid position South-East from c.If it is occupied by a module, then c can pivot 90 • , as illustrated in Fig. 11 (top).If it is empty, then the positions (2, 0) and (2, −1) relative to c need to be empty as well, since pattern I is forbidden; see Fig. 11 (bottom).Therefore, c can pivot 180 • .□ However, there can be locked configurations containing only instances of pattern Z .Figure 12 shows such a configuration, whose adjacency graph is a path.We partition the configuration into left and right sides by splitting the path in half.The subset configuration space shown in Fig. 12 has 19 configurations, and assumes that no module in the right side moves.The whole configuration space will then have 19 2 configurations and can be obtained from Fig. 12 by combining all possible pairs of left and right sides.It is clear that the movable modules of opposite sides cannot coordinate and thus the straight strip is not in this component of the configuration space.Hence, the configuration is locked.
Proposition 6 Let G n be the reconfiguration graph of facet-connected pivoting squares under pivoting set of moves 1.If only pattern Z is allowed, and patterns and I are forbidden, the number of connected components of G n of exponential size is exponential in n for sufficiently large n.Proof Figure 13 shows a configuration containing only pattern Z that is locked under Set 1 of pivoting rules.Each of the pink modules can pivot to four different positions inside the gadget (highlighted in Fig. 13) containing it, which consists of 53 modules.Therefore, if the number of such gadgets is k, the size of the corresponding connected component of G n is (4 k ) .Moreover, if the path of dark modules has length p, the number of different connected components that are obtained is (2 p ) , as in the proof of Proposition 3. The right and the left ends of the configuration shown in Fig. 13 consist of 36 modules each, and each gadget contains 54 modules.

Universal Reconfiguration Algorithm with O(1) Musketeers
In this section, we aim for the important practical goal of universal reconfiguration, that is, connectivity of the reconfiguration graph.We have seen that the local separation condition (while sufficient) is too strong: Robot configurations can contain many instances of the forbidden patterns and still be reconfigurable.On the other hand, we proved that as soon as the local separation condition is relaxed, the reconfiguration graph breaks into at least an exponential number of connected components of exponential size.
In what follows, we propose and analyze a new approach for reconfiguring arbitrary facet-connected configurations (which may contain an arbitrary number of instances of the forbidden patterns) using the monkey moves (Set 3).Our strategy is based on the addition of O(1) musketeer modules, i.e., modules that can freely move around the boundary of our robot configuration and will be used as helpers in certain situations.These modules are not necessarily part of the specified initial or target configuration.

Preliminaries: Outer Shell
Let C be an arbitrary facet-connected configuration of pivoting squares.We start by introducing a few definitions.
Let G be the facet-adjacency graph of C, and G the facet-adjacency graph of the lattice cells that are not occupied by a module of C. Each bounded connected component of G is a hole of the robot configuration C. The only unbounded connected component of G is the exterior of C. The boundary of C is the set of lattice cells that are empty and are facet-adjacent to (at least) one module of C. If the configuration has holes, we define its external boundary as the subset of the boundary contained in the unbounded connected component of G. Proof We start by proving that such a sequence of moves from Set 3 is always possible.In order to do that, we prove that an invariant holds before and after each possible move, which allows m to pivot clockwise following the right-hand rule.
Let the cell positions be denoted by their relative coordinates with respect to m.The invariant is that position (0, 1) is empty and that if at least one of a 0 = (−1, 0) or a 1 = (−1, 1) is occupied, then both b 0 = (1, 0) and b 1 = (1, 1) must be empty; see Fig. 14.Naturally, the invariant will be rotated as m moves along the boundary of C, so that it is always facing outward.The invariant is trivially satisfied initially by our choice of starting position.
We want to show that, when the invariant is satisfied, m can pivot according to the right-hand rule and that the position it moves to satisfies the invariant.First consider the case where b 0 is occupied and thus a 0 and a 1 are empty.If b 1 or c 2 = (0, 2) are occupied, m can pivot to (0, 1) and the invariant holds in a rotated version; see Fig. 15.
On the other hand, when b 1 and c 2 are empty, consider b 2 = (1, 2) ; refer to Fig. 16.If b 2 is empty, m can move to b 1 and maintain the invariant.If b 2 is occupied, consider a 2 = (−1, 2) .If this cell is empty, m can move there and after pivoting the invariant is satisfied (in a rotated version).Finally, if b 2 and a 2 are both occupied, m can move to a 1 and a rotated version of the invariant holds.Now, consider the case where b 0 is empty, illustrated in Fig. 17.If b 1 is occupied, the invariant guarantees that a 1 and a 2 are empty, and m can move to b 1 .After the  Since the static configuration C has a finite number of modules and is facet-connected, this concludes the proof that, using the monkey set of moves (Set 3) m can pivot along the external boundary of C following the right-hand rule and return to its initial position.In addition, since the starting position of m belongs to the external boundary of C, and no move can get m into a hole, the positions occupied by m along its traversal are all located in the external boundary.
If the robot is only allowed the operations of the leapfrog model, then it is not always possible for the additional module m to pivot along the boundary and return to its initial position.Indeed, any configuration containing one of the two situations depicted in Fig. 16, where the moving module performs a monkey jump, cannot be traversed in the leapfrog model.In the leapfrog model, the additional module m would get stuck and could not advance following the right-hand rule.□ It is worth noticing that the proof of Lemma 2 does not require the use of diagonal monkey jumps, but only of straight monkey jumps.This is relevant form a practical viewpoint, since it allows our results to be applied to a larger class of modular robots.For example, the hardware systems modeled in [3,21] can perform straight monkey jumps, but not diagonal ones.

Algorithm Overview
Our reconfiguration algorithm transforms any initial facet-connected configuration C of pivoting squares into any goal configuration with the same number of modules.
In order to simplify the algorithm's description, we use the common approach of transforming the initial shape into an intermediate canonical configuration, namely, a straight strip of width one.The reconfiguration from the strip to the final shape is obtained by reversing the steps of the algorithm applied to the final shape.The canonical strip can be built from any lexicographically best positioned module of the configuration.For example, we will grow a horizontal strip to the left of the bottommost of the leftmost modules of the configuration.
The strategy behind the algorithm is simple.It consists of sequentially choosing a module from the configuration that is not a cut vertex of its facet-adjacency graph, and make it pivot, following the right-hand rule, along the outer shell, until it reaches the tip of the strip and stops.The problem of this strategy, as we saw in Sect.3, is that the reconfiguration graph is not connected, even under the extended set of monkey moves.In order to overcome this problem, the algorithm uses musketeer modules.Any module from the canonical strip can serve as a musketeer module.We will prove that five musketeer modules are sufficient and sometimes necessary to solve any reconfiguration based on our strategy.Because the canonical strip is initially empty, it may be necessary to add musketeer modules to the strip, if fewer than needed are available (this may happen at most once).

Algorithm Details
The description of the algorithm and the proof of its correctness make use of a potential function.If m is a module located in the lattice position with coordinates (x, y), the potential function at m is defined as (m) = (x + y, x) .The potential being a two-dimensional function, we sort its values lexicographically.The maximum potential max (minimum potential min ) of a configuration is the lexicographically largest (smallest) potential of all its modules.Note that, whenever we use the term configuration, we refer to the facet-connected component that includes all modules other than the ones in the canonical strip.
Given any configuration, we define North-East and South-West as being the modules with highest and lowest potential, respectively.Notice that in any configuration C, both North-East and South-West are facet-adjacent to the outer shell of C.

Musketeer Modules Definition 3
We say that a module m is outer-free in a configuration C if it is facetadjacent to the outer shell and it can pivot clockwise, without disconnecting the robot.
The first step of the algorithm is to look for an outer-free module, and pivot it to the tip of the strip.This step is repeated until no further outer-free modules exist in the initial configuration.If at that point the configuration is a strip, the algorithm ends.
Otherwise, all the modules in the strip may be used as musketeer modules, one at at time, starting from the tip of the strip, pivoting them to the positions where they are needed, as described in next Sect.4.3.2.Since our algorithm may require five such modules, it may be necessary to add extra modules to the strip (or anywhere in the configuration where they are outer-free) in order to complete the necessary set of musketeer modules.This can be done at this stage or on the fly, as needed.This second option may be preferable in some cases, as not all configurations require as many as five musketeer modules.

Bridging Procedure
In this section we describe an operation necessary in some situations when there are no outer-free modules in the configuration.Let m be the North-East module, i.e., the maximum potential module of a given configuration C. Trivially, there can be no modules of C located North, North-East, or East of m.In a slight abuse of notation we identify a module in a configuration with the position it occupies.Using this notation, positions m + (0, 1) , m + (1, 1) , and m + (1, 0) are empty.Therefore, the degree of m in the facet-adjacency graph can only be 1 or 2. Since m is not outerfree, it must be a cut vertex and have degree 2. Let b 1 and g 1 respectively be its coun- terclockwise and clockwise facet-adjacent modules; see Fig. 19.We color the two connected components of C connected by m blue and green, so that b 1 is blue and g 1 is green.One important procedure of our algorithm, which we call bridging, is the act of using musketeer modules to connect the green and blue components so that m becomes outer-free.

Observation 1
The outer shell has two green-blue changes of color, one happening at m. 1 3 Algorithmica (2021) 83:1316-1351 Consider a grid-aligned 3 × 3 square S centered at the lattice cell of coordinates s 0 = m + (2, 1) ; see Fig. 19 (right).Translate S orthogonally clockwise one unit at a time along the boundary of the configuration until it reaches s 0 again.Ignoring the positions where S is not adjacent to a boundary edge (i.e., the positions of S where one of its corners coincides with a convex corner of C), let s i be the i-th position of the center of S along its boundary traversal, and let s = s 0 .Refer to Fig. 19.Since m is the maximum potential module of the configuration, S is empty of modules at position s 0 and all subsequent positions, and it does not share edges with the blue component when centered at s 0 , while at s −2 it is facet-adjacent to the blue module b 1 .Let s k be the first position of S along its boundary traversal where S becomes facet-adjacent to a blue module.Since S travels along the boundary of the configuration, the rectangular union R of S centered at s k and at s k−1 should also be facet- adjacent to a green module; see Fig. 19 (bottom).
The algorithm pivots the musketeer modules clockwise, following the right-hand rule along the outer shell of the configuration.By Lemma 2, the modules can reach every grid position eventually contained by S that shares an edge with a green or blue module.In particular, the musketeer modules will reach the vicinity of s k .We use them to connect the blue and green components, thus forming a cycle containing m.
Let g and b be the closest pair of respectively green and blue modules facet-adjacent to rectangle R, and let d be the L 1 distance between them.The bridging pro- cedure depends on the value of d.We note that d > 1 or else both modules would belong to the same component.Cased = 2 Up to rotations and reflections, g and b must occur in one of the two configurations shown in Fig. 20 (left).In the first case, the position North of g (respectively, East of b) must be occupied or else g (resp., b) would be outer-free, contradicting the precondition of the bridging operation that the configuration contains no outer-free modules.Therefore, placing one musketeer module a 1 East of g connects the components without changing the maximum and minimum potential of the configuration, as shown in the first row of Fig. 20.
In the second case, the position between g and b must be empty, or else they would belong to the same connected component.The positions to the West and North (resp., South) of g (resp., b) must contain a module, or else g (resp., b) would be outer-free, contradicting the precondition of the bridging operation.
The positions shown as blue dots in the figure must contain at least one module or else the module South of b would be outer-free.As for the existence of modules on the top and bottom sides of S, there are three options.2, 1) contains a module, the sequence of four musketeer modules a 1 -a 4 shown in Fig. 20 can be sent to connect the green and blue components.Otherwise, the five musketeer modules a 1 -a 5 do the bridging.In this case, a sequence of moves can bridge the components using the five musketeer modules a 1 -a 5 as depicted in Fig. 20.
In all cases, the diagonal dotted lines are used to indicate the existence of modules with greater and smaller potential than that of the musketeer modules.Note that this bridging operation does not change the maximum and minimum potential of the configuration.
Case d = 3 Up to rotations and reflections, g and b must occur in one of the two configurations shown in Fig. 21 (left).In the first the lattice positions West and North of g must be occupied.Therefore, position g + (0, 2) must also be occupied.Otherwise the configuration would have a (green) outer-free module.Then a sequence of moves can place the two musketeer modules a 1 and a 2 as shown in the first row of Fig. 21, connecting the green and blue components without changing the maximum and minimum potential of the configuration.
In the second case the lattice positions West and North of g must contain a module or g would be outer-free.Symmetrically, the positions West and South of b must also contain a module.Furthermore, either b + (1, −1) or b + (0, −2) must also be occupied, or else the module below b would be outer-free.Therefore a sequence of moves can place four musketeer modules a 1 -a 4 as shown in the second row of Fig. 21.These musketeer modules connect the green and blue components without changing the maximum and minimum potential of the configuration.22.In the first case, the lattice positions g + (−1, 0) , g + (0, 1) and g + (0, 2) must contain a module, or else there would exist an outer-free module.Analogously, b + (0, −1) , b + (1, 0) , and b + (2, 0) must be occupied for the same reason.Then, a sequence of moves can place three musketeer modules a 1 -a 3 as shown in the first row of Fig. 22, connecting the green and blue components without changing the maximum and minimum potential of the configuration.In the second case, b + (0, −1) , b + (1, 0) , and either b + (2, 0) or b + (1, 1) must be occupied, since the configuration does not have outer-free modules.Therefore, a sequence of moves can place three musketeer modules a 1 -a 3 as shown in the second row of Fig. 22, connecting the green and blue components without changing the maximum and minimum potential of the configuration.Finally, in the third case, either b + (0, −1) or b + (0, 1) must be occupied.In each case, a sequence of moves places four musketeer modules a 1 -a 4 as shown in the third row of Fig. 22.These musketeer modules connect the green and blue components without changing the maximum and minimum potential of the configuration.
Case d = 5 Up to rotations and reflections, g and b must occur in one of the two configurations shown in Fig. 23.In the first case, g + (−1, 0) , g + (0, 1) , g + (0, 2) , 1) b + (0, −1) , and b + (1, 0) must be occupied, because the configuration has no outer-free modules.Then a sequence of moves can place four musketeer modules a 1 -a 4 as shown in Fig. 23 (left), connecting the green and blue components with- out changing the maximum and minimum potential of the configuration.In the second case, b + (0, −1) , b + (1, 0) , and either b + (1, 1) or b + (2, 0) must be occu- pied by modules, since the configuration cannot have outer-free modules.Then a sequence of moves can place four musketeer modules a 1 -a 4 as shown in Fig. 23 (right).These musketeer modules connect the green and blue components without changing the maximum and minimum potential of the configuration.
Case d = 6 Up to rotations and reflections, g and b must occur in the configu- ration shown in Fig. 24.Since the configuration has no outer-free modules, the lattice positions West and North of g must contain modules, so do the positions East and South of b.Then a sequence of moves can place five musketeer modules a 1 -a 5 as shown in Fig. 24.These musketeer modules connect the green and blue components without changing the maximum and minimum potential of the configuration.
Bridging result As a result, we obtain the following lemma.Their subindexes indicate the order of their appearance.Note that a 3 needs to be moved to the empty space to its left for a 4 to be moved to its position (Color figure online) minimum potential of the configuration.After the procedure ends, m is still the North-East module of the modified configuration, but no longer a cut vertex of its facet-adjacency graph.
Proof It is easy to see that d can only be 2, 3, 4, 5, or 6.For each of the possible values of d, we have proven that the configuration can be bridged, i.e., that a connection can be made between the two connected components of C ⧵ {m} , using at most five musketeer modules whose new locations do not increase the potential function of the configuration.Each musketeer module performs O(n) pivoting operations along the boundary of C, for a total of O(n) pivoting operations.Since the bridging procedure adds a new connection between the two connected components of C ⧵ {m} , module m is no longer a cut vertex.Since the bridging procedure does not increase the potential of the configuration, m is still its maximum potential module.□ Notice also that the bound of five musketeer modules for bridging is tight: Fig. 25 shows an example requiring five musketeer modules for bridging.

Reconfiguration Step
We now need to guarantee that module m is able to move and thus, it can pivot along the outer shell of C and join the canonical strip.This is clear when m is disjoint from the neighborhood of m.We also want to show that we can liberate and send to the canonical strip either the musketeers used or at least as many modules as musketeers used.We will extend the analysis of the neighborhood of m, and for each of the possible cases we will show that either invoking the bridging procedure or explicitly placing musketeer modules can guarantee that.
Progress is measured in terms of the potential gap = max − min of the con- figuration and the size of C (recall that C includes all modules that are not part of the canonical strip).We will show that each reconfiguration step decreases the potential gap and/or the size of C.
Recall the setting of the configuration before performing a reconfiguration step (Fig. 19).Module m is the North-East module (i.e., the highest module of maximum potential in a given configuration C), it has degree 2 and connects two connected components of C, one blue (extending counterclockwise) and one green (extending clockwise).Let b 1 and g 1 be the blue and green modules adja- cent to m, respectively.Position m + (−1, −1) must be empty, since otherwise the green and blue modules would belong to the same component.

Lemma 4
The neighborhood around m is in one of the three configurations shown in Fig. 26b.1-b.3: its South neighbor g 1 has degree 2 and a South neighbor g 2 , and its West neighbor b 1 has maximum degree 2.
Proof By the definition of m, the positions m + (1, 0) , m + (0, 1) , and m + (1, −1) must be empty, otherwise C would contain a module with potential higher than that of m, a contradiction.Since the positions West and East of g 1 are empty, g 1 has maximum degree 2. Assume first that g 1 has degree 1.In this case the position g 1 + (1, −1) must be occu- pied by a module b ′ , otherwise g 1 would be an outer-free module.Refer to Fig. 26a.Note that the positions West, North, and East of b ′ are empty (the last two due to the definition of m), which means that b ′ has degree 1 and can pivot clockwise without disconnecting C, contradicting the fact that C has no outer-free modules.It follows that g 1 is of degree 2 and has a South neighbor.
Since the position below b 1 is empty, b 1 has maximum degree 3. Assume first that b 1 has degree 3, as shown in Fig. 26a.Note, however, that the positions above and to the right of its North neighbor b ′′ are all empty (because these positions have poten- tial higher than that of m, which is maximum) and therefore b ′′ can pivot clockwise without disconnecting C, contradicting the fact that C has no outer-free modules.Thus b 1 has degree at most 2.
We now argue that the neighborhood around m is in one of the three configurations shown in Fig. 26b.1-b.3.If b 1 has degree 1, then the position b 1 + (−1, 1) must be occupied, otherwise b 1 would be outer-free; see Fig. 26b.1.Note that this posi- tion must be occupied by a green module, otherwise the blue component would be disconnected.If b 1 has a North neighbor, then the position b 1 + (−1, 1) must also be occupied, otherwise the North neighbor would be outer-free; see Fig. 26b.2.Note that this position must be occupied by a blue module, otherwise the green and blue Let g 2 be the South neighbor of g 1 guaranteed by Lemma 4, and let b 2 be the North or West neighbor of b 1 (if one exists).Our reconfiguration procedure depends on the degrees of g 2 , b 1 and b 2 (if it exists).
Reconfiguring when b 1 has degree 1 This case is depicted in Figs.26b.1 and 27.In this case we simply place a musketeer module above b 1 ; it is labelled a 1 in Fig. 27.This musketeer module connects the blue and green components, leaving m free to pivot along the outer shell of C and join the canonical strip; see Fig. 27b.Module g 1 then becomes outer-free and can pivot clockwise to join the canonical strip; see Fig. 27c.

Lemma 5 This reconfiguration step uses O(n) pivoting operations to transform C into a facet-connected configuration of smaller size and smaller potential gap
.
Proof In addition to the O(n) pivoting operations used by m to join the canonical strip, this reconfiguration uses only a constant number of pivoting operations, as indicated by Fig. 27.The output of this reconfiguration step, shown in Fig. 27d, is facet-connected, because each of the blue and green components are facet-connected, and a 1 facet-connects to each of them.Because the musketeer module a 1 joins C and the configuration modules m and g 1 leave C, both the size and the maxi- mum potential of C decrease as a result.Note that the minimum potential of C stays the same, therefore the potential gap decreases.(a) From this point on we assume that b 1 has degree 2 and therefore b 2 exists.Reconfiguring when g 2 or b 2 has degree 1 First observe that, if g 2 has degree one, then the green component consists of g 1 and g 2 only (otherwise the green component would be disconnected).Also note that position g 2 + (1, −1) must be occupied by a blue module, otherwise g 2 would be outer-free.We handle this situation similarly to the one above: place a musketeer module (labelled a 1 in Fig. 28) to the right of g 2 , to connect the blue and green components.This leaves m free to pivot along the outer shell of C and join the canonical strip; see Fig. 28b.It is then followed by g 1 ; see Fig. 28c.The argument is similar for the case when b 2 exists and has degree 1.The result for b 2 ( g 2 , resp.) is depicted on the top (bottom, resp.) of Fig. 29.
Notice that b 2 cannot have a North neighbor since it would have a higher poten- tial than m.In this case we invoke the bridging procedure to connect the green and blue components with a set of musketeer modules, so that m becomes outer-free and can pivot clockwise to join the canonical strip.For each combination of (top, Reconfiguring when g 2 has degree greater than 2 If g 2 does not have a West neighbor, then g 2 has East and South neighbors and is of degree 3; see Fig. 30a.Note however that in this case the East neighbor of g 2 is outer-free (because the positions above and to its right have potential higher than that of m and are therefore empty), contradicting the fact that C has no outerfree modules.This implies that g 2 has a West neighbor.In this case we invoke the bridging procedure to connect the green and blue components joined by the cut vertex m with a set of musketeer modules, so that m becomes outer-free and can pivot clockwise to join the canonical strip.Recall that we are in the context where b 1 has degree 2 before reconfiguration (Lemma 4 guarantees that the degree of b 2 Assume first that b 2 lies North of b 1 .Refer to Fig. 30b.We discuss two situ- ations, depending on whether the position b � = b 1 + (−1, −1) is empty or not.If position b ′ is empty, then a sequence of pivoting operations reconnects the green and blue components in the vicinity of b 1 as follows.First, b 1 pivots counterclock- wise to attach to g 1 ; see Fig. 30c.1.Second, b 2 pivots clockwise to attach on top of b 1 ; see Fig. 30c.2.Finally, g 1 pivots counterclockwise twice to attach North of b 2 ; see Fig. 30c.3.The result is shown in Fig. 30c. 4.  If the position b ′ is occupied, then b 1 is blocked; see Fig. 30d.1.In this case g 1 piv- ots clockwise to free the space South-East of b 1 .Figure 30d.2shows the case when g 1 attaches to the East neighbor of g 2 , but the argument holds for the case when g 2 does not have an East neighbor (in this case g 1 would attach East of g 2 ).With g 1 out of the way, b 1 can now pivot clockwise and attach East of b ′ , followed by b 2 which pivots clockwise to attach North of b 1 ; see Fig. 30d.3.Finally, g 1 reverses its pivoting step back to its original position, then pivots counterclockwise once more to attach North of b 2 ; see Fig. 30d.4.The result is shown in Fig. 30d. 5.  Assume now that b 2 lies West of b 1 ; see Fig. 31a.1.In this case, after m rolls away to join the canonical strip, a sequence of pivoting operations reconnects the green and blue components in the vicinity of b 1 as follows.First, g 1 pivots clockwise; see Fig. 31a.2.Second, b 1 pivots clockwise; see Fig. 31a.3.Finally, g 1 reverses its piv- oting step back to its original position, then pivots counterclockwise once more to attach North of b 1 ; see Fig. 31a.4.The result is shown in Fig. 31a. 5.In all these cases, the green and blue components remain connected after the musketeer modules retrace their steps to join the canonical strip.

Lemma 8 This reconfiguration step uses O(n) pivoting operations to transform C into a facet-connected configuration of smaller size and smaller potential gap .
Proof By Lemma 3, the bridging procedure (and its reverse) takes O(n) pivoting operations.In addition to the O(n) pivoting operations used by m to join the canonical strip, this reconfiguration step uses only a constant number of pivoting operations.The resulting configuration is facet-connected, because each of the blue and green components are connected, and this reconfiguration step connects the blue and green components together, as shown in the right columns of Figs. 30 and 31.are empty (since their potential is higher than that of m), which implies that b 2 has degree 2. So the only situation left to discuss here is when b 2 lies West of b 1 .
Assume first that b 2 has a South neighbor; see Fig. 32.This case is very simi- lar to the one where g 2 has a West neighbor (discussed in the previous section and depicted in Fig. 31), and the same sequence of operations applies here as well: after bridging, m pivots clockwise along the outer shell to join the canonical line; g 1 and b 1 pivot clockwise, in this order; then g 1 pivots counterclockwise (the only differ- ence is that g 1 stops after the first pivoting step).This sequence of pivoting steps is depicted in Fig. 32.
Assume now that b 2 does not have a South neighbor.Since the degree of b 2 is at least 3, b 2 must have West and North neighbors.Refer to Fig. 33a.Let b ′ be the North neighbor of b 2 and note that the position m ′ North of b ′ must be occupied, oth- erwise b ′ would be outer-free.Also note that the position West of m ′ must be occu- pied and the position West of b ′ must be empty, otherwise m ′ would be outer-free.We reassign the role of m to m ′ and recolor the graph so that its blue and green com- ponents are joined by m ′ ; see Fig. 33b.Let b ′ 1 and g ′ 1 be the blue and green neighbors of m ′ .If b ′ 1 does not have a North neighbor, we are in a situation similar to the one depicted in Fig. 31 and handle it the same way: bridge the (new) blue and green components; pivot m ′ clockwise along the outer shell to join the canonical line; pivot g ′ 1 and b ′ 1 clockwise, in this order; then pivot g ′ 1 counterclockwise twice.The result is shown in Fig. 33c.
We use a similar sequence of pivoting steps for the case when b ′ 1 has a North neighbor b ′′ ; see Fig. 33d.1.First note that the position North of b ′′ is empty, since it has potential higher than the one of m.Also note that the position West of b ′′ is occupied and the position West of b ′ 1 is empty, otherwise b ′′ would be outer-free.This enables the following sequence of operations.First, we bridge the (new) blue and green components.Second, we pivot m ′ clockwise along the outer shell to join the canonical line.Exactly as in Fig. 30, we branch on whether b ′ (the grid position to the southwest of b 1 ) is empty.We pivot g ′ In all these cases, the green and blue components remain connected after the musketeer modules retrace their steps to join the canonical line.= O(n) .Each step of the innermost loop uses O(n) pivoting operations to take an outer-free module to the end of the strip, thus decreasing the size of C by one.Each reconfiguration step uses O(n) pivoting steps to decrease either the potential gap or the size of C, leaving it facet-connected (and never increasing the potential gap).Because the size of C never increases, the length of the canonical strip never decreases.This means that the strip can have fewer than five modules only once and the conditional does not affect the complexity of the algorithm.We conclude that the algorithm terminates after O(n) iterations in total.Because each iteration takes O(n) pivoting steps, the total number of pivoting steps is O(n 2 ) .Optimality comes from the (n 2 ) pivoting steps required to reconfigure a vertical strip into a horizon- tal one.□

Conclusion and Open Problems
This paper addresses the problem of reconfiguring a facet-connected grid configuration of n modules into any other configuration of n modules under three increasingly more flexible sets of pivoting moves, namely restrictive, leapfrog and monkey.Previous results solve this problem under the leapfrog set of moves, as long as the initial and final configurations satisfy a strong local separating condition imposed by 1 3 Algorithmica (2021) 83:1316-1351 three forbidden patterns.We show that there exist robot configurations with many instances of the three forbidden patterns that are still reconfigurable, so the local separation condition is not necessary.On the other hand, we show that as soon as the local separation condition is relaxed, the reconfiguration graph breaks into an exponential number of connected components of exponential size.To overcome this obstacle we introduce a new pivoting move, called monkey, and a natural reconfiguration approach that does not depend on local features, but uses up to five extra modules that can freely move around the boundary of the robot configuration.These extra modules are used to unlock intermediate locked configurations so that progress can be made towards the target configuration.We show that our approach uses O(n 2 ) monkey-pivoting moves to reconfigure any source configuration with n pivoting modules into any given target configuration.
We leave open the question of whether universal reconfiguration can be accomplished under the more restrictive set of leapfrog pivoting moves using a constant number of extra modules.
Another question is whether our approach generalizes to three or higher dimensions.For example, when the slice graphs (where the vertices are the slices of the configuration cut along an axis and the edges connect slices with facet-adjacent modules) of the source and target configurations are both paths, we should be able to reconfigure each to a strip of modules, one slice at a time, similar to our 2-dimensional approach does.We conjecture that a similar approach will also work for general 3-dimensional configurations, potentially after increasing the number of musketeer modules to bridge larger gaps introduced by the higher dimensionality.

Fig. 3 Fig. 4 3
Fig.3Left: a rigid configuration of edge-connected pivoting squares.Right: A configuration that can be reconfigured into a strip using any set of pivoting moves, in spite of containing instances of the three forbidden patterns (as the pairs highlighted)

Fig. 6 (
Fig.6(left) A shape that can be reconfigured using the monkey set of moves, but not using the leapfrog set of moves.Reconfiguration in the monkey model would start by moving modules a and b to the left (as shown in the right figure).After both have moved, module c can rotate clockwise allowing all other modules to move one by one

Fig. 7 Fig. 8 A
Fig. 7 Configurations showing only the forbidden pattern .Top: Rigid configuration for any set of pivoting moves.Bottom: Locked configuration for any set of pivoting moves

Fig. 9
Fig.9 The adjacency graph G of a facet-connected configuration (left) and the corresponding cactus graph T(G) (right); leaves and maximal cycles are dark-shaded

Fig. 11 3 Fig. 12 Fig. 13 A
Fig. 11 If only pattern Z is allowed, any corner can pivot regardless of the set of pivoting moves used

Lemma 2 3
Let C be an arbitrary and static facet-connected configuration of pivoting squares.Let m be an additional module attached to C, North of the topmost rightmost module of C. Using the monkey set of moves (Set 3), m can pivot along the external boundary of C following the right-hand rule and return to its initial 1 Algorithmica (2021) 83:1316-1351 position.If only the leapfrog set of moves (Set 2) is allowed, this is not always possible.

Fig. 14
Fig. 14 Illustration of the invariant.The additional module m (in pink) is facet-adjacent to a module of C (in gray).The opposite cell (with a cross) is empty.If a 1 or a 2 are occupied, then both b 1 and b 2 are empty (Color figure online)

Fig. 15
Fig. 15 When b 0 is occupied, a 0 and a 1 are empty.The move, when b 1 or c 2 are occupied.Striped cells are empty, filled cells are occupied

Fig. 16 Fig. 17 3
Fig. 16 When b 0 is occupied, a 0 and a 1 are empty.The move, when b 1 or c 2 are both empty.Striped cells are empty, filled cells are occupied

Fig. 18 A
Fig. 18 A robot configuration (in gray) and its associated outer shell (striped in pink) (Color figure online)

1 RFig. 19
Fig. 19 Top: 3 × 3 square S in its initial position s 0 .The outer thick line indicates the path traversed by the center of S. Dots correspond to the center positions where S is adjacent to a boundary edge.Bottom: the rectangular union R of S centered at s k and at s k−1

Option 1 :
Both positions g + (1, 1) and g + (2, 1) are empty.Then we can bridge the two components by sending three musketeer modules in the order shown in Fig. 20.Notice that if the positions b + (1, −1) and b + (2, −1) are empty, an x-symmetric solution applies.Option 2: At least one of positions g + (2, 1) or g + (3, 1) contains a module.Such module(s) necessarily belong to the green component, by definition of s k .If g + (

Fig. 20 1 3
Fig. 20 Bridging when d = 2 .Striped cells are empty, filled cells are occupied.Green and blue indicate different connected components of C⧵{m} .Dotted pairs of cells of the same color mean that a module must exist in at least one of the two cells.The orange cells labelled a i correspond to the positions of the bridging musketeer modules.Their subindices indicate the order of their appearance (Color figure online)

Fig. 21
Fig. 21 Bridging when d = 3 .Striped cells are empty, filled cells are occupied.Green and blue indicate different connected components of C⧵{m} .The dotted pair of cells indicates that a module must exist in at least one of the two cells.The orange cells labelled a i correspond to the positions of the bridging musketeer modules.Their subindexes indicate the order of their appearance (Color figure online)

Fig. 22
Fig. 22 Bridging when d = 4 .Striped cells are empty, filled cells are occupied.Green and blue indicate different connected components of C⧵{m} .The dotted pair of cells indicates that a module must exist in at least one of the two cells.The orange cells labelled a i correspond to the positions of the bridging musketeer modules.Their subindexes indicate the order of their appearance (Color figure online)

Lemma 3 Fig. 23 4 a 3 a 5 Fig. 24
Fig. 23 Bridging when d = 5 .Striped cells are empty, filled cells are occupied.Green and blue indicate different connected components of C⧵{m} .The dotted pairs of cells indicate that a module must exist in at least one of the two cells.The orange cells labelled a i correspond to the positions of the bridging musketeer modules.Their subindexes indicate the order of their appearance (Color figure online)

Fig. 25
Fig. 25 A rigid configuration that requires the addition of five musketeer modules for bridging

2 Fig. 26 a
Fig. 26 a If g ′ exists, it is outer-free; if b 1 is of degree 3, b ′′ is outer-free, b.1 b 1 has degree 1, b.2 b 1 has a North neighbor, b.3 b 1 has a West neighbor

Lemma 6
This reconfiguration step uses O(n) pivoting operations to transform C into a facet-connected configuration of smaller size and smaller potential gap .Proof In addition to the O(n) pivoting operations used by m to join the canonical strip, this reconfiguration step uses only a constant number of pivoting operations, as indicated by Fig. 28.The output of this reconfiguration step is facet-connected, because each of the blue and green components are facet-connected, and a 1 facet- connects to each of them; see Fig. 28d.Because the musketeer module a 1 joins C and the configuration modules m and g 1 leave C, both the size and the maximum potential of C decrease as a result.Note that the minimum potential of C remains unchanged, therefore the potential gap decreases.□ Reconfiguring when g 2 and b 2 have degree 2 We start with the configurations guaranteed by Lemma 4 and depicted in Fig. 26b.2-b.3, and place the second neighbor of b 2 and g 2 in all possible positions.

Fig. 30 3
Fig. 30 Reconfiguring when g 2 has degree greater than 2 a g 2 does not have a West neighbor, b g 2 has a West neighbor and b 2 lies North of b 1

Fig. 31
Fig. 31 Reconfiguring when g 2 has degree greater than 2, g 2 has a West neighbor and b 2 lies West of b 1

Lemma 9
This reconfiguration step uses O(n) pivoting operations to transform C into a facet-connected configuration of smaller size and smaller or equal potential gap.Proof By Lemma 3, the bridging procedure (and its reverse) takes O(n) pivoting operations.In addition to the O(n) pivoting operations used by m or m ′ to join the canonical strip, this reconfiguration step uses only a constant number of pivoting operations.The resulting configuration is facet-connected, because each of the blue and green components are connected, and this reconfiguration step connects the blue and green components together, as shown in the right columns of Figs.32 and 33.Note that the size of C decreases, because the musketeer modules rejoin the canonical strip.In both cases the potential gap does not increase.□

Fig. 33 Theorem 1
Fig. 33 Reconfiguring when b 2 has degree greater than 2 but no South neighbor