예제 #1
0
        }                                                    // overload method to provide default value for pieces()

        public static int[] pieces_static()
        {
            // Returns the list of all pieces similar to the game that inspired Woodsy Walk.  Now deprecated, but keep around for reference.
            // The pieces are shuffled randomly before being returned.
            // Note that since they are expressed in binary, you can more easily modify them using the definition above.
            int[] pieceArray = new int[] {
                ((1 << 6) | 0b001100), ((7 << 6) | 0b001100), ((13 << 6) | 0b011110), ((19 << 6) | 0b011010), ((25 << 6) | 0b011100), ((31 << 6) | 0b011100),
                ((2 << 6) | 0b111100), ((8 << 6) | 0b111100), ((14 << 6) | 0b100110), ((20 << 6) | 0b101010), ((26 << 6) | 0b101110), ((32 << 6) | 0b101100),
                ((3 << 6) | 0b001110), ((9 << 6) | 0b001101), ((15 << 6) | 0b001110), ((21 << 6) | 0b001101), ((27 << 6) | 0b110000), ((33 << 6) | 0b110000),
                ((4 << 6) | 0b001100), ((10 << 6) | 0b001100), ((16 << 6) | 0b010000), ((22 << 6) | 0b001000), ((28 << 6) | 0b110100), ((34 << 6) | 0b111000),
                ((5 << 6) | 0b111100), ((11 << 6) | 0b111100), ((17 << 6) | 0b100110), ((23 << 6) | 0b101000), ((29 << 6) | 0b110100), ((35 << 6) | 0b111000),
                ((6 << 6) | 0b110010), ((12 << 6) | 0b110001), ((18 << 6) | 0b110010), ((24 << 6) | 0b110001), ((30 << 6) | 0b110000), ((36 << 6) | 0b110000)
            };
            Pieces.shuffleArray(pieceArray);
            return(pieceArray);
        }
예제 #2
0
        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);
        }