public static int numberMoves(int p) { return(Pieces.numberMovesDiag(p) + Pieces.numberMovesHV(p)); }
public static int[] pieces(int numPieces) { //--- New version of pieces, which generates the shuffled bag to use in the game; it is //--- randomly generated instead of static, and includes the new diagonal directions. int[] a = new int[numPieces]; int randomPiece = 0; int maxBitPattern = (int)Math.Pow(2, 22) - 1; //by getting random bits of this size, we can make a whole mess of weird pieces. for (int i = 0; i < numPieces; i++) { bool pieceWanted = false; while (!pieceWanted) { // Make a random, but valid, path piece. Its piece number is the array index. randomPiece = Pieces.randomInt(0, maxBitPattern); randomPiece &= 0b1111000000000000111111; // zero out house #, person #, piece ID, etc. randomPiece = Pieces.setPieceNumber(randomPiece, i); // Throw out pieces that have various non-game-preferred attributes. These are aspects of game play that I might adjust after playing. int nm = Pieces.numberMoves(randomPiece); if (nm > 4) { continue; // no more than 4 directions } if (nm < 2) { continue; // No dead-end pieces } //-- Some code to alter proportions of pieces.... if (i < 3 * numPieces / 40) { randomPiece = Pieces.setAsLake(randomPiece); // 3 in every game are lakes. } else if (i < 20 * numPieces / 40) { if (nm != 2) { continue; } } // then pieces 4 through 20 are two-roads else if (i < 30 * numPieces / 40) { if (nm != 3) { continue; } } // 20-30 are three-roads else { if (nm != 4) { continue; } } // rest are 4-roads //-- not too many coins if (Pieces.rnd.NextDouble() < 0.3) { randomPiece = Pieces.takeCoins(randomPiece); } // 30% of the time coins get buried... //-- Below, we don't want very many pieces with, say, 3 straight lines and 1 diagonal. Two-move pieces with one straight and one diagonal are fine, and can be used to convert straight to diagonal. if (Pieces.numberMovesHV(randomPiece) == 1 && Pieces.numberMoves(randomPiece) > 2 && Pieces.rnd.NextDouble() > 0.75) { continue; } if (Pieces.numberMovesDiag(randomPiece) == 1 && Pieces.numberMoves(randomPiece) > 2 && Pieces.rnd.NextDouble() > 0.75) { continue; } //-- not too scrunched up of a piece int[] maxmin = Pieces.minMaxRoads(randomPiece); int mmDiff = Math.Abs(maxmin[0] - maxmin[1]); if (nm == 2 && (mmDiff < 2 || (maxmin[0] == 0 && maxmin[1] == 7))) { continue; } if (nm == 3 && (mmDiff < 5)) { continue; } // We like this piece pieceWanted = true; } a[i] = randomPiece; } Pieces.shuffleArray(a); return(a); }