Dominoes is a game played with rectangular domino 'tiles'. Today the tiles are often made of plastic or wood, but in the past, they were made of real stone or ivory. They have a rectangle shape and are divided in 2 square fields, each marked with zero to six pips. In a standard set, all 28 combinations of stones with 0 to 6 pips occur exactly once.

dominostenen
Domino tiles.

The genesis of the game is unclear. Possibly, dominoes originates from China and the stones were brought here by Marco Polo, but this is uncertain.

Assignment

Define a class Domino to represent domino tiles in Python. We choose a design where the tiles are immutable objects. This way, not a single method may change the internal state of an object after is was initialized. The objects of this class should have at least the following methods:

Example

>>> tile1 = Domino(3, 4)
>>> Domino(-1, 7)
Traceback (most recent call last):
AssertionError: invalid number of pips

>>> tile1
Domino(3, 4)
>>> print(tile1)
+---+---+
|o  |o o|
| o |   |
|  o|o o|
+---+---+
>>> print(tile1.rotate())
+---+---+
|o o|o  |
|   | o |
|o o|  o|
+---+---+
>>> print(tile1)
+---+---+
|o  |o o|
| o |   |
|  o|o o|
+---+---+

>>> tile2 = Domino(1, 3)
>>> tile1 + tile2
Traceback (most recent call last):
AssertionError: domino tiles do not match
>>> print(tile2 + tile1)
+---+---+
|   |o o|
| o |   |
|   |o o|
+---+---+
>>> tile3 = tile1.rotate() + tile2.rotate()
>>> tile3
Domino(4, 1)
>>> print(tile3)
+---+---+
|o o|   |
|   | o |
|o o|   |
+---+---+