public static int numberMovesHV(int p) { // Returns the number of Horizontal/Vertical moves you can make of a person piece by discarding this piece. // Also useful for divining the # of certain directions in a tile before deciding whether to put it in the bag or not return((Pieces.up(p) ? 1 : 0) + (Pieces.down(p) ? 1 : 0) + (Pieces.left(p) ? 1 : 0) + (Pieces.right(p) ? 1 : 0)); }
private static int[] minMaxRoads(int p) { // Returns minimum and maximum road numbers for a piece to weed out those dumb ones that just turn right around in a tight space. // Minimum is returnValue[0], max is returnValue[1]. ArrayList a = new ArrayList(); a.Clear(); if (Pieces.northwest(p)) { a.Add(0); } if (Pieces.up(p)) { a.Add(1); } if (Pieces.northeast(p)) { a.Add(2); } if (Pieces.right(p)) { a.Add(3); } if (Pieces.southeast(p)) { a.Add(4); } if (Pieces.down(p)) { a.Add(5); } if (Pieces.southwest(p)) { a.Add(6); } if (Pieces.left(p)) { a.Add(7); } int minRoad = 9, maxRoad = -1; for (int i = 0; i < a.Count; i++) { if ((int)a[i] < minRoad) { minRoad = (int)a[i]; } if ((int)a[i] > maxRoad) { maxRoad = (int)a[i]; } } int[] returnValue = new int[2]; returnValue[0] = minRoad; returnValue[1] = maxRoad; return(returnValue); }
private static void connectPlaceTile(int p /* piece */, int x, int y, int[,] a) { // The piecesConnect routine now uses a 7x7 array of integers to calculate connections, which // represents a 3x3 grid of tiles each of which has 3 sides (left, right, center) that can have roads. // They intersect of course (hence a 7x7 grid instead of 9x9), and the purpose of this is to // modify the array to add in a tile's connections, with a +1 to any node where a road is. Connections // between tiles will appear as numbers > 1 at the tiles' edges. // The coordinates x and y are tile coordinates where the center is (0,0), so they range from -1 to +1. int cx = 3 + x * 2; //-- Center X: the position of the center of the tile in the array. int cy = 3 + y * 2; a[cy, cx]++; // tiles always serve their center if (Pieces.up(p)) { a[cy - 1, cx]++; } if (Pieces.down(p)) { a[cy + 1, cx]++; } if (Pieces.left(p)) { a[cy, cx - 1]++; } if (Pieces.right(p)) { a[cy, cx + 1]++; } if (Pieces.northwest(p)) { a[cy - 1, cx - 1]++; } if (Pieces.southeast(p)) { a[cy + 1, cx + 1]++; } if (Pieces.southwest(p)) { a[cy + 1, cx - 1]++; } if (Pieces.northeast(p)) { a[cy - 1, cx + 1]++; } }
public static int rotatePieceOneEighth(int p) { // Rotates a piece clockwise. int newPiece = p; newPiece = Pieces.setDirections(newPiece, Pieces.northwest(p), Pieces.southeast(p), Pieces.southwest(p), Pieces.northeast(p)); newPiece = Pieces.setDiagonals(newPiece, Pieces.left(p), Pieces.up(p), Pieces.down(p), Pieces.right(p)); return(newPiece); }