private void initTiles ( )

{

// Forgive me Gang of Four wherever you are.

/* 4 fields, 4 forest, 4 pasture, 3 mountains, 3 hills, 1 desert

19 total

+ water */

/* These 18+1 tiles represent the positions (hungarian-notated as p)

on the board. Their roll numbers and terrain types will be assigned

randomly, from the contents of a game box. */

Tile. UnfinishedTile p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11,

p12, p13, p14, p15, p16, p17, p18, water ;

/* This line initializes all the ts to null so that I can refer to them

later, because otherwise it thinks the try block can fail and leave

them uninitialized, even though the exception is never actually

thrown. */

p0 = p1 = p2 = p3 = p4 = p5 = p6 = p7 = p8 = p9 = p10 = p11 = p12 = p13 = p14 = p15 = p16 = p17 = p18 = null ;

water = null ;

/* These numbers are the tokens that come in the box: */

Integer [ ] ns = shuffle (

2 , 3 , 3 , 4 , 4 , 5 , 5 , 6 , 6 , 7 , 7 , 8 , 8 , 9 , 9 , 10 , 10 , 11 , 11 , 12

) ;

/* And these are how many of each terrain type comes in the box: */

Tile. Terrain [ ] ts = shuffle (

FIELD, FIELD, FIELD, FIELD,

FOREST, FOREST, FOREST, FOREST,

PASTURE, PASTURE, PASTURE, PASTURE,

MOUNTAIN, MOUNTAIN, MOUNTAIN,

HILL, HILL, HILL,

DESERT

) ;

try { /* Here we're assigning the terrains (ts) and the numbers (ns) */

int i = 0 ;

p0 = new Tile. UnfinishedTile ( ts [ i ] , ns [ i ++ ] ) ;

p1 = new Tile. UnfinishedTile ( ts [ i ] , ns [ i ++ ] ) ;

p2 = new Tile. UnfinishedTile ( ts [ i ] , ns [ i ++ ] ) ;

p3 = new Tile. UnfinishedTile ( ts [ i ] , ns [ i ++ ] ) ;

p4 = new Tile. UnfinishedTile ( ts [ i ] , ns [ i ++ ] ) ;

p5 = new Tile. UnfinishedTile ( ts [ i ] , ns [ i ++ ] ) ;

p6 = new Tile. UnfinishedTile ( ts [ i ] , ns [ i ++ ] ) ;

p7 = new Tile. UnfinishedTile ( ts [ i ] , ns [ i ++ ] ) ;

p8 = new Tile. UnfinishedTile ( ts [ i ] , ns [ i ++ ] ) ;

p9 = new Tile. UnfinishedTile ( ts [ i ] , ns [ i ++ ] ) ;

p10 = new Tile. UnfinishedTile ( ts [ i ] , ns [ i ++ ] ) ;

p11 = new Tile. UnfinishedTile ( ts [ i ] , ns [ i ++ ] ) ;

p12 = new Tile. UnfinishedTile ( ts [ i ] , ns [ i ++ ] ) ;

p13 = new Tile. UnfinishedTile ( ts [ i ] , ns [ i ++ ] ) ;

p14 = new Tile. UnfinishedTile ( ts [ i ] , ns [ i ++ ] ) ;

p15 = new Tile. UnfinishedTile ( ts [ i ] , ns [ i ++ ] ) ;

p16 = new Tile. UnfinishedTile ( ts [ i ] , ns [ i ++ ] ) ;

p17 = new Tile. UnfinishedTile ( ts [ i ] , ns [ i ++ ] ) ;

p18 = new Tile. UnfinishedTile ( ts [ i ] , ns [ i ] ) ;

water = new Tile. UnfinishedTile ( WATER, 0 ) ;

} catch ( Tile. NeedsNeighborsException e ) {

// Duly noted, and addressed below.

/* This exception is never thrown by any code, but it exists as

a checked exception to ensure that everyone who uses an

UnfinishedTile is reminded and forced to acknowledge that the

tile is unfinished and its neighbors must be set */

}

/* We know about magic numbers and magic strings, here's magic code.

I came up with this unreadable abomination by taking a hex grid

and labelling it in an organized manner with its positions.

Then I transcribed the neighbors of each hex into this code.

*/

p0. setNeighbors ( water, water, p2, p4, p1, water ) ;

p1. setNeighbors ( water, p0, p4, p6, p3, water ) ;

p2. setNeighbors ( water, water, p5, p7, p4, p0 ) ;

p3. setNeighbors ( water, p1, p6, p8, water, water ) ;

p4. setNeighbors ( p0, p2, p7, p9, p6, p1 ) ;

p5. setNeighbors ( water, water, water, p10, p7, p2 ) ;

p6. setNeighbors ( p1, p4, p9, p11, p8, p3 ) ;

p7. setNeighbors ( p2, p5, p10, p12, p9, p4 ) ;

p8. setNeighbors ( p3, p6, p11, p13, water, water ) ;

p9. setNeighbors ( p4, p7, p12, p14, p11, p6 ) ;

p10. setNeighbors ( p5, water, water, p15, p12, p7 ) ;

p11. setNeighbors ( p6, p9, p14, p16, p13, p8 ) ;

p12. setNeighbors ( p7, p10, p15, p17, p14, p9 ) ;

p13. setNeighbors ( p8, p11, p16, water, water, water ) ;

p14. setNeighbors ( p9, p12, p17, p18, p16, p11 ) ;

p15. setNeighbors ( p10, water, water, water, p17, p12 ) ;

p16. setNeighbors ( p11, p14, p18, water, water, p13 ) ;

p17. setNeighbors ( p12, p15, water, water, p18, p14 ) ;

p18. setNeighbors ( p14, p17, water, water, water, p16 ) ;