# The Rainbow Baseball Game

This activity is inspired from the orange game, from the "Computer Science Unplugged" activities repository. It was however heavily since then, first for the CSIRL (my repository of free unplugged activities to introduce computer science, available at http://www.loria.fr/~quinson/Mediation/SMN/) and now for PLM.

In the literature, the generalized form of this problem is known as the pebble motion problem (the bases can be connected by any kind of graph, and the affinity of pebbles with bases may be different). Another variant of this problem is the well known 15-puzzle, with one player per base, and a two dimensional square grid. Much more information about these problems can be found on wikipedia, as usual.

### How do you know that the naive algorithm won't loop on that initial situation?

Well, we simply tested all possible situations to see when this algorithm loops and when it finds the correct solution. We found that it works for all situations where no player is at home (there is 84 such situations for 4 bases, once you take the symmetries into account). It obviously works for some situations that do not respect this criteria (such as all situations it encounters from one of those 84 boards to the final state), but that's another story. Having such a criteria allows us to generate pseudo-random initial situations for the first exercise for which the algorithm we propose is guarenteed to work.

We also explored bigger instances of the problem, and unfortunately, we have no such criteria for them. With 5 bases, the algorithm wrongly loops for 24 of the 1824 possible boards where no player is home (that's 1.31%). With 6 bases, it fails on 1251 of the 58860 such boards (2.12%). With 7 bases, it fails for 84444 out of 2633940 (that's 3.2%). I am still looking for a criteria ensuring that the algorithm won't loop. If you discover one, please report it. Ideally, it would be simple to enforce manually so that we can use it during our unplugged activities.

### What can I do to improve this PLM universe?

As usual, there are several things that could be done in the code of this universe to improve it:

- Other graphical representations could be proposed, such as a linear one (for the existing exercises) or other ones (such as a grid or a tree, if an exercise on this kind of graph proves interesting).
- Other exercises on other algorithms on this variant, or on other variants such as the 15-puzzle.