1 //////////////////////////////////////////////
3 // tileSearch is a program to solve the
6 // Find all arrangements of N square tiles
7 // that evaluate to the highest possible score.
9 // Each tile has an integer on its north, south
10 // east and west faces. Tiles faces may only
11 // be adjacent to other tile faces with the
14 // Tiles may not be rotated.
16 // All tiles in the final arrangement must
17 // be adjacent to at least one other tile.
19 // The score of an arrangement is the sum of
20 // all tile face values that are not adjacent
25 // +-----+ +-----+ +-----+ +-----+
26 // | 3 | | 4 | | 9 | | 3 |
27 // |2 1| |5 5| |1 1| |5 2|
28 // | 4 | | 3 | | 4 | | 9 |
29 // +-----+, +-----+, +-----+, +-----+
31 // A valid arrangement could be:
46 // 3 + 9 + 1 + 3 + 2 + 9 + 3 + 5 + 4 + 2 = 41
49 // What is the highest possible score for a
52 //////////////////////////////////////////////
54 public class TileSearch {
56 public static void main(String args[]) {
57 SubProblem top = new SubProblem();
59 top.tilesToFit = new Tile[2];
60 top.tilesToFit[0] = new Tile( 3, 2, 3, 1 );
61 top.tilesToFit[1] = new Tile( 2, -4, -4, -4 );
63 top.tilesFitted = new Tile[1];
64 top.tilesFitted[0] = new Tile( -1, -1, 1, -1 );
68 top.tilesToFit = new Tile[3];
69 top.tilesToFit[0] = new Tile( 2, 1, -1, 0 );
70 top.tilesToFit[1] = new Tile( 1, 3, 0, -1 );
71 top.tilesToFit[2] = new Tile( -1, 1, -1, 0 );
72 //top.tilesToFit[3] = new Tile( 1, 2, 2, -1 );
73 //top.tilesToFit[4] = new Tile( 2, 2, 1, 2 );
74 //top.tilesToFit[5] = new Tile( -1, 1, 0, 1 );
76 top.tilesFitted = new Tile[1];
77 top.tilesFitted[0] = new Tile( 1, -1, 0, 2 );
81 top.workingGrid = new TileGrid( (top.tilesToFit.length+5)*2 + 4 ); //new TileGrid( (top.tilesToFit.length+1)*2 + 1 );
83 // put first fitted tile in the middle of the grid
84 top.tilesFitted[0].x = top.workingGrid.gridSize/2;
85 top.tilesFitted[0].y = top.workingGrid.gridSize/2;
86 top.workingGrid.grid[top.tilesFitted[0].x]
87 [top.tilesFitted[0].y] = 0;
91 int score = top.highestScore();
92 System.printString("Highest score: " + score + "\n");