There are some situations in which you cannot place the tile you drew from the bag, these should be found and managed correctly.
To find this situation multiple solutions may be implemented.
I want to write down a quite efficient solution: Storing the available spaces in a Trie<Array, TilePosition> will allow us to index the empty slots in a way that will support O(1) insertions and deletions.
The idea is simple: each empty tile near a card should be indexed in the trie with the expected sides (or null if all sides are possible). When a card is drawn, the program can match the card sides against the trie (this isn't a primitive query but it can be implemmented quite easily).
There are some situations in which you cannot place the tile you drew from the bag, these should be found and managed correctly.
To find this situation multiple solutions may be implemented.
I want to write down a quite efficient solution: Storing the available spaces in a Trie<Array, TilePosition> will allow us to index the empty slots in a way that will support O(1) insertions and deletions.
The idea is simple: each empty tile near a card should be indexed in the trie with the expected sides (or null if all sides are possible). When a card is drawn, the program can match the card sides against the trie (this isn't a primitive query but it can be implemmented quite easily).