Greetings readers.
I implemented the playing field and the toolbox. Both went fairly smooth, because they are simple adapters of the constrained mapping and the multiset.
However, while implementing these classes and especially the tests for them, I noticed a fair amount of duplication. Both the toolbox-tests and the playingfield tests contain a lot of tests which check “Is a small plus bomb combined with a small plus bomb really a big plus bomb? Is a small plus bomb with a small diagonal bomb really an O-bomb? …”. While I implemented tests for the actual gamestate, this duplication of a responsibility became glaringly obvious, because now I had that large clump of tests in the same file. Two times.
Thus, I sat bad and asked myself: Where does this come from? How can I remove this duplication?
The duplication results from the following facts:
- The toolbox has a method combine(bombtype, bombtype) which tries to remove a bomb of each type and puts a bomb of the combined type into the toolbox (or it raises an exception, because the bombs cannot be combined). I implemented this method, because while I played this game, I usually combined several bombs in the toolbox before actually placing them on the field.
- The playing field contains the functionality that placing a bomb on an existing bomb combines the bombs if possible (if it is impossible, it raises an exception, of course). This is necessary, because some problems require you to place a bomb on an existing bomb, combining them, in order to solve the problem.
Given this duplication, the question is: Can I remove it? And as you might suspect already, yes I can. Ask yourself: Do I need the combination in the toolbox? Do I need the combination in the playing field? The answers: Yes, I do need to combination functionality in the playing field, because, as I said, some puzzles require you to place a bomb on an existing bomb, combining them in order to solve the puzzle. Thus, we can assume: placing two bombs on the same field in the playing area combines them. However, if we can combine bombs by placing them on the same location on the playing field, we do not need to be able to combine them in the toolbox! It is actually quite clear, now that I pondered about it for a bit: put(l, combine(b1, b2)) == put(l, b1); put(l, b2). Thus, I can remove all combining functionality from the toolbox and keep it in the playing field.
This is nice, because it reduces the complexity in the solver. Before this thoughts, I figured I need to consider two types of moves: combining bombs in the toolbox and placing bombs on the playing field. This was simplified! Now I just have to consider the move of placing bombs on the playing field, because this includes combining bombs! This was a very successful evening.
Thanks for reading and see you next time,
Tetha.
I drew this diagram with dia, because I did not decide to use UML beforehand. I rather wanted to have some diagrams, searched around and ended up with UML-diagrams, because the other diagrams did not express what I wanted.


Consider having 2 small plus bombs in your inventory. Now you have a lot of plans that are all equal in this context:











