23
6
The board game
In the board game "Carcassonne" players place tiles by matching their edges and earn the highest scores through creating large contiguous areas of terrain. The following are (roughly) the types and quantities of tiles included in the game:
#01
x4
#02
x5
#03
x8
#04
x2
#05
x9
#06
x4
#07
x1
#08
x3
#09
x3
#10
x3
#11
x4
#12
x5
#13
x3
#14
x3
#15
x2
#16
x5
#17
x5
#18
x2
#19
x3
#20
x1
#21
x5
#22
x2
#23
x1
#24
x1
#25
x1
The Task
You must place a tile by matching edges, while trying to maintain the largest possible contiguous areas of terrain.
Placement
- Tiles can only be placed in one of the (up to 4) blank spaces adjacent to any existing tile (or tiles) in the play area.
- Tiles can be rotated 90, 180 or 270 degrees.
Edge-matching
- Edges of a placed tile must match the touching edges of the (up to 4) neighbouring tiles, i.e. touching pixels are the same colour.
Contiguous terrain
- "Closing an area of terrain" refers to placing a tile such that any contiguous area of colour could not then be continued with further tile placements.
- If an alternative placement is possible, it must be chosen over any tile placement that would close an area of terrain.
- If you have to choose between a number of closing placements, choose any. If you have to choose between a number of non-closing placements, choose any.
- Disregard #ff00ff (the corner pixels) when calculating contiguous areas. Also disregard buildings, i.e. areas of colour already fully enclosed within a tile.
Input
Input is two images:
The play area.
- The initial play area consists of tile
#11
(a single tile). - The augmented play area created as output must also be supported as input.
- The initial play area consists of tile
The tile to be placed.
- All of the example tiles must be supported as input.
Determine matching edges/contiguous terrain using this image data alone. No hardcoding.
Output
- Output is an image showing the resultant play area after placing the tile.
- The image must be compatible with your own program, i.e. it can be used as play area input.
- If it's impossible to place a tile, return an error.
You can assume that
- Tiles are always 55 px by 55 px
- Tiles will only ever feature the colours currently used in the example tiles.
Notes
- Your answer must feature example output after at least 2 passes (more is encouraged).
- This is a partial and inaccurate rendering of the original board game, you don't need to apply any of the rules or tactics not mentioned here.
Score
- Your score is your submission's byte count.
- Image data isn't included in your score.
- Lowest score wins.
Playing a full game
You may wish to write a script that uses your submissison to play a full game, which might consist of:
- Placing a tile chosen pseudorandomly from the full set of 85.
- Returning the tile to the set if it can't be placed.
- Repeating until every tile has been placed - or until two tiles in a row can't be placed.
It won't be included in your byte count, or improve your score, but I'll likely offer a bounty to this kind of answer.
1what is the differenct between 12, 15, and 17? – kaine – 2014-11-07T16:22:19.870
thanks for catching that, 17 was a duplicate. however 15 does differ as it can potentially close an area of terrain. (btw, areas of colour aren't contiguous if only the corners of pixels touch) – jsh – 2014-11-07T16:33:52.277
So one 15 and two 2s could make 2 separate black sections of size 2. While one 12 and two 2s could make a black sections that is 3 big instead. Ok. – kaine – 2014-11-07T16:37:37.340
A few questions: 1. What exactly is a "contiguous area of colour"? If I put down tiles 9, 14, 15, 20 from left to right, I take it that's a "contiguous area of colour", even though it's composed of many colours? If so, why not call just it "4-connected group of tiles"? 2. When you say that the input is two images, do you mean command-line arguments specifying two image filenames? 3. In the output image, what fills any empty tiles on the game board? Transparent pixels? – COTO – 2014-11-07T23:37:07.383
2>
Tile #18 seems to have an additional pixel of blue on the left edge, at least if it is supposed to line up with, for example, tile #21. – jlahd – 2014-11-09T21:34:33.050
Where is #11 to be positioned in the initial input play area? In the top-left corner? – None – 2014-11-09T22:57:02.897
1@hosch250 the play area is infinite (extends as necessary). With just the first tile on the play, the first tile is the whole play area. – jlahd – 2014-11-10T01:19:12.560
@jlahd OK, I get it. – None – 2014-11-10T02:37:58.013
What about the river monastary and the bridge? Also, the headwater/lake tiles actually have roads extending from them as well. – AJMansfield – 2014-11-10T21:06:55.727
It's not entirely faithful to the tile set (or rules) in the game. You can include improved tiles in your answer if you want (as long as the example tiles are supported). – jsh – 2014-11-10T22:37:23.057