Example #1
0
 public int getCell(Coordinates c)
 {
     if (c.notFound())
     {
         return(Pieces.createFailurePiece());
     }
     return(this.getCell(c.x(), c.y()));
 }
Example #2
0
        //-- Creating a goal piece (with or without a house on it-- put zero for no house/person)
        //   at a particular place on the edge of the board.
        public int createGoalPiece(int houseNumber, int personNumber, Coordinates c)
        {
            int p = Pieces.createGreenGrassPiece();

            p = Pieces.setHouseNumber(p, houseNumber);
            p = Pieces.setPersonNumber(p, personNumber);
            p = this.setGoalDirections(p, c);
            return(p);
        }
Example #3
0
        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);
        }
Example #4
0
 public static int getPersonPieceFrom(int p)
 {
     // given a piece with a person on it, get the corresponding person piece.
     // Returns the failure piece if no person is on it.
     if (Pieces.personNumber(p) == 0)
     {
         return(createFailurePiece());
     }
     return(createPersonPiece(Pieces.personNumber(p)));
 }
Example #5
0
 public static int getHousePieceFrom(int p)
 {
     // given a piece with a house on it, get the corresponding house piece.
     // Returns the failure piece if no house is on it.
     if (Pieces.houseNumber(p) == 0)
     {
         return(createFailurePiece());
     }
     return(createHousePiece(Pieces.houseNumber(p)));
 }
Example #6
0
 //-- Sets the directions appropriately for a goal piece or origin piece.
 public int setGoalDirections(int p, Coordinates c)
 {
     p = Pieces.setDirections(p, (c.y() == this.height - 1), (c.y() == 0), (c.x() == this.width - 1), (c.x() == 0));
     //-- I decided diagonals on the goal piece made it too easy, but I'll keep the code in case I add levels or something.
     //if (c.y()==0) p = Pieces.setDiagonals(p,false,false,true,true);
     //if (c.x()==0) p = Pieces.setDiagonals(p,false,true,false,true);
     //if (c.y()==this.getHeight()-1) p = Pieces.setDiagonals(p,true,true,false,false);
     //if (c.x()==this.getWidth()-1) p = Pieces.setDiagonals(p ,true,false,true,false);
     return(p);
 }
Example #7
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);
        }
Example #8
0
        // Static method for creating a piece (which is of course actually an integer)
        public static int createPiece(bool up, bool down, bool left, bool right, bool silver, bool gold, int pieceNumber, int personNumber, int houseNumber)
        {
            int p = 0;

            p  = Pieces.setDirections(p, up, down, left, right);
            p  = Pieces.setCoins(p, silver, gold);
            p |= (pieceNumber << 6);
            p |= (personNumber << 12);
            p |= (houseNumber << 15);
            return(p);
        }
 public int getNextPiece()
 {
     // during a turn, this returns the next piece to play, which can be displayed
     // in the next piece area.  Returns the End of Turn piece if none remain.
     if (this._movingPerson)
     {
         return(Pieces.getPersonPieceFrom(this.currentBoard.getCell(this.personCoordinates)));
     }
     if (!this.piecesLeftThisTurn())
     {
         return(Pieces.createEndOfTurnPiece());
     }
     return(this.currentTurnPieces[0]);
 }
Example #10
0
 //-- Locate people and houses
 public Coordinates locatePerson(int personNumber)
 {
     for (int i = 0; i < this.height; i++)
     {
         for (int j = 0; j < this.width; j++)
         {
             if (Pieces.personNumber(this.board[i, j]) == personNumber)
             {
                 return(new Coordinates(j, i, false));
             }
         }
     }
     return(new Coordinates(0, 0, true));
 }
Example #11
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);
        }
Example #12
0
        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]++;
            }
        }
Example #13
0
 public static int combinePieces(int p1, int p2)
 {
     // Combines a piece that is a person or house, with a regular piece.  Order is unimportant.
     // Returns the failure piece if neither piece is a plain person or house.
     if (Pieces.isTile(p1))
     {
         int t = p1; p1 = p2; p2 = t;
     }
     if (Pieces.isPerson(p1) && Pieces.isTile(p2))
     {
         return(Pieces.setPersonNumber(p2, Pieces.personNumber(p1)));
     }
     if (Pieces.isHouse(p1) && Pieces.isTile(p2))
     {
         return(Pieces.setHouseNumber(p2, Pieces.houseNumber(p1)));
     }
     return(Pieces.createFailurePiece());
 }
Example #14
0
 public int distanceToPartner(int p, Coordinates c)
 {
     // Given a person or house piece, and proposed coordinates for placing it, compute
     // the distance to its corresponding partner.  Returns Integer.MAX_VALUE if the
     // partner is not found or the input is not a pure person/house piece.
     if (Pieces.isPerson(p))
     {
         return(this.distance(this.locateHouse(Pieces.personNumber(p)), c));
     }
     else if (Pieces.isHouse(p))
     {
         return(this.distance(this.locatePerson(Pieces.houseNumber(p)), c));
     }
     else
     {
         return(int.MaxValue);
     }
 }
Example #15
0
 //-- Determining if a board is a winning board
 public bool isWinningBoard()
 {
     for (int i = 1; i <= Pieces.numberOfPeople(); i++)
     {
         Coordinates ch = this.locateHouse(i);
         Coordinates cp = this.locatePerson(i);
         if (!ch.notFound() && !cp.notFound())
         {
             if (!ch.equals(cp))
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
     return(true);
 }
 public int playPieceDiscard(int p)
 {
     //  Discards a piece.  Of course you can't discard people or house pieces, and discarding
     //  doesn't work if you started moving a person.
     //  Returns the success or failure piece.
     if (this._movingPerson)
     {
         return(this.setFailure("You can't discard a person piece that you are moving."));
     }
     if (Pieces.isHouse(p))
     {
         return(this.setFailure("You can't discard a house piece."));
     }
     if (Pieces.isPerson(p))
     {
         return(this.setFailure("You can't discard a person piece."));
     }
     this.setCurrentPiecePlayed();  // put the piece in the played pile
     return(Pieces.createSuccessPiece());
 }
Example #17
0
 public WoodsyBoardData()
 {
     // board constructor: board starts out empty.
     this.board  = new int[8, 8]; // rows first, then columns.  .
     this.height = 8;
     this.width  = 8;
     // note: the edges have Green Grass pieces, showing where the people and houses go.
     for (int i = 0; i < this.height; i++)
     {
         for (int j = 0; j < this.width; j++)
         {
             if (i == 0 || j == 0 || i + 1 == this.height || j + 1 == this.width)
             {
                 this.board[i, j] = Pieces.createGreenGrassPiece();
             }
             else
             {
                 this.board[i, j] = Pieces.createBlankPiece();
             }
         }
     }
 }
        public bool rotateNextPiece()
        {
            // rotates a piece and sends a success or error message.  Returns true on success.
            setFailureBoolean("You spent " + priceRotation() + " to rotate the piece.");
            if (priceRotation() == 0)
            {
                setFailureBoolean("You rotated the piece.");
            }
            if (this._movingPerson)
            {
                return(setFailureBoolean("You can't rotate a person who is moving."));                     // no rotating people)
            }
            if (!this.piecesLeftThisTurn())
            {
                return(setFailureBoolean("You have no pieces left to rotate."));
            }
            int originalPiece = this.currentTurnPieces[0];

            if (Pieces.isPerson(originalPiece))
            {
                return(setFailureBoolean("You can't rotate a person."));
            }
            if (Pieces.isHouse(originalPiece))
            {
                return(setFailureBoolean("You can't rotate a house."));
            }
            if (!spendCoins(priceRotation()))
            {
                return(setFailureBoolean("You can't afford to rotate.  Rotation costs " + priceRotation() + " coins."));
            }
            this.currentTurnPieces[0] = Pieces.rotatePiece(originalPiece);
            if (this.piecesToPlay[this.currentParticipant][0] == originalPiece)
            {
                this.piecesToPlay[this.currentParticipant][0] = Pieces.rotatePiece(originalPiece);
            }
            return(true);
        }
Example #19
0
 public static bool isFailurePiece(int p)
 {
     return(p == Pieces.createFailurePiece());
 }
Example #20
0
 public static bool isSuccessPiece(int p)
 {
     return(p == Pieces.createSuccessPiece());
 }
Example #21
0
 public static bool isEndOfTurnPiece(int p)
 {
     return(p == Pieces.createEndOfTurnPiece());
 }
Example #22
0
 public static int createGreenGrassPiece()
 {
     return(Pieces.createPiece(false, false, false, false, false, false, 60, 0, 0));
 }
Example #23
0
 public static bool isEndOfTurn(int p)
 {
     return(Pieces.pieceNumber(p) == 63);
 }
Example #24
0
 public static int createSuccessPiece()
 {
     return(Pieces.createPiece(false, false, false, false, false, false, 62, 0, 0));
 }
Example #25
0
 public static int createEndOfTurnPiece()
 {
     return(Pieces.createPiece(false, false, false, false, false, false, 63, 0, 0));
 }
Example #26
0
 public static int createPersonPiece(int p)
 {
     return(Pieces.createPiece(false, false, false, false, false, false, 0, p, 0));
 }
Example #27
0
 public static int createHousePiece(int h)
 {
     return(Pieces.createPiece(false, false, false, false, false, false, 0, 0, h));
 }
Example #28
0
 public static bool isGreenGrassPiece(int p)
 {
     return(p == Pieces.createGreenGrassPiece());
 }
Example #29
0
 public static int createFailurePiece()
 {
     return(Pieces.createPiece(false, false, false, false, false, false, 61, 0, 0));
 }
Example #30
0
 public static int numberMoves(int p)
 {
     return(Pieces.numberMovesDiag(p) + Pieces.numberMovesHV(p));
 }