The famous game of Qwirkle has simple but intricate rules (See part 2 of this question for a summary of the rules!)
- The Challenge You are somehow (text input, function parameter, whatever) given a board of a Qwirkle game, like a snapshot from any current timeframe within a game. This board can be anything from completely empty to completely filled with tiles (max board size should be at least 32x32). Each tile can be one of six colors (red r, green g, blue b, orange o, purple p, yellow y) and one if six shapes (circle c, square s, flower f, zacks z, small star m, rhombus r). You can use any distinct letters as well! There are exactly three tiles of each shape-color combination in the whole set of tiles.
Simple rules are:
each line (horizontal or vertical) of touching tiles must contain any distinct tile at most once and only tiles of different color and same shape OR tiles of different shape and same color!
every tile has to touch ar least one neighboring tile! No single/islands of tiles!
Your task is to calculate wether the given board is in a valid state (see rules down below). That is, wether the given board does not break any of the rules. It can also be interpreted as 'a board that was created from a valid game, not breaking any of the game's rules'. The result is thus one of two possible values, either true or false, 1 or 0 or whatever you prefer.
The result can be anything from a text output, a returned boolean or other variable type or whatever you want. Just somehow publish the result (don't just keep it inside a variable)
- The Game Rules In a possibly infinite 2d checked board, tiles get laid. On every field on the board can either be one or no tile.
There are 36 different types of stones, each 3 times, makes a total of 108 tiles. A board doesn't contain more than one set of tiles. (you only play with one sack. When it's empty, the game ends)
- Special Things to Check
It's important to note that a valid game evolves around one start position. This means, any tile on the field has to touch any other tile through other tiles. There can't be single tiles or islands of tiles disconnected from the main starter island. So, any tile has to touch at least one other tile.
there are only 3 tiles of each color and shape in total. So there can't be, for example, 4 red square tiles or 4 green circles.
- Example Image This is an example of a valid qwirkle field: I think all of your questions can be answered by studying this image:
- Test Cases Note that test cases are going to be in an array (string with linebreaks or similar), for example: your program can take some other format (for example tabbed strings, semicolons as dividers or whatever! Doesn't have to accept any one! Just choose one specific format)
0,0,rs,rc,0,0 0,0,gs,gc,0,0 (this would be valid!)
In this case i specified the input as color first letter, shape second letter. So rs is red square, gc is green circle etc. Any other format is ok!
- This is code-golf so shortest working code in bytes wins!
Test cases (based from comments, commas separate columns, semicolons separate rows):
Truthy:
"" rc,gc,bc,oc,pc,yc;rs,gs,bs,os,ps,ys;rf,gf,bf,of,pf,yf;rz,gz,bz,oz,pz,yz;rm,gm,bm,om,pm,ym;rr,gr,br,or,pr,yr Falsy:
rc,rs,rf,rz,rm,rr,rf rc,rs,rf,yc 
""(empty string) -> truthy \$\endgroup\$