Tantrix is a two player game played with 56 hexagonal tiles. Each tile contains three links in different colours. Both players have five tiles in hand and take turns in placing them on the playing field. The figure to the right shows how the game could have progressed after nine played tiles.
There are four different link colours: red, green, yellow and blue. No two tiles are identical, and no tile is rotation symmetric. A tile will be described in the input as a six letter string, specifying the link colours in clockwise direction. The uppercase letters 'R', 'G', 'Y' and 'B' will be used for red, green, yellow and blue, respectively.
In this problem, a move is defined as placing one of the tiles in hand somewhere on the playing field, subject to these rules:
The first line in the input will contain the number of cases (at most 50).
Each case begins with a single line containing an integer n (1 ≤ n ≤ 20), the number of tiles that have already been played. Then follow n lines containing the coordinates and description of these tiles. The first character in the tile description belongs to the link facing up; the remaining colours follow as per usual in clockwise direction. Then follows a line with the description of the five tiles in hand, the tile descriptions being separated with a single space.
The mapping between the spaces and the coordinates is shown in the figure below (note that the playing field is infinite and not restricted to these coordinates). All tiles in the input will be valid and distinct. The layout will represent a position that could have arisen from a legal game. One of the played tiles will have coordinates 0,0.
For each test case, output a single line containing an integer: the number of legal moves.
2 6 0 0 BRYRBY 1 0 GRGBRB -1 1 GGYBYB 0 1 YYBBGG -2 2 YYBGBG -3 3 BYGYGB BBRRGG GBYBYG RBRBGG GYBGBY GRBBRG 4 0 0 BYYGBG -1 1 GRGBBR 1 0 YRBRYB 2 0 YGGRRY RBBRYY GBGYBY YBBRYR YBYBRR RBBRGG
46 2
Migrated from old NTUJ.
NWERC 2005
No. | Testdata Range | Score |
---|