Example #1
0
        /*************** HELPER FUNCTIONS ****************************/

        // Returns the [row, col] of the next grid position a player at position p
        // will move to
        public int[] nextTileCoord(Posn p)
        {
            int currentRow      = p.returnRow();
            int currentCol      = p.returnCol();
            int currentTilePosn = p.returnLocationOnTile();

            int[] nextCoord = new int[] { currentRow, currentCol };

            switch (currentTilePosn)
            {
            case 0:
            case 1:
                nextCoord[0] = currentRow - 1;
                break;

            case 2:
            case 3:
                nextCoord[1] = currentCol + 1;
                break;

            case 4:
            case 5:
                nextCoord[0] = currentRow + 1;
                break;

            case 6:
            case 7:
                nextCoord[1] = currentCol - 1;
                break;
            }

            return(nextCoord);
        }
Example #2
0
        // Returns end position for the given start position, after following all
        // on board paths
        //
        // Does not actually move player on board
        public Posn followPathsMock(Posn startPos)
        {
            if (isElimPosn(startPos))
            {
                return(startPos);
            }

            int[] nextCoord = nextTileCoord(startPos);
            int   nextRow   = nextCoord[0];
            int   nextCol   = nextCoord[1];

            // End recursion if no more tiles along path
            if (grid[nextRow, nextCol] == null)
            {
                return(startPos);
            }
            else // Recursively follow path
            {
                // set the current location of the player to be the the next grid location
                Tile nextTile = grid[nextRow, nextCol];
                int  endPosn  = getEndOfPathOnTile(nextTile, startPos.returnLocationOnTile());
                Posn newPosn  = new Posn(nextRow, nextCol, endPosn);
                return(followPathsMock(newPosn));
            }
        }
Example #3
0
        /*************** GAME PLAY FUNCTIONS ****************************/

        // The player with the input color places tile t at the grid position they
        // are about to move to
        //
        // Returns the end position of the given player given the tile placement,
        // but does not actually move him/her
        public Posn placeTile(String color, Tile t)
        {
            int[] newGridLoc = new int[2];
            Posn  playerPosn = colorToPosnMap[color];

            // if player is not on the edge, if it is not the players first turn anymore
            // set new grid location to be the next location that player can place tile in
            newGridLoc = nextTileCoord(playerPosn);

            // get the current player location on their current tile
            int currentTilePosn = playerPosn.returnLocationOnTile();
            // get the new player location on the next tile
            int newTilePosn = getEndOfPathOnTile(t, currentTilePosn);

            int newRow = newGridLoc[0];
            int newCol = newGridLoc[1];

            // set the next grid location on the board to be the tile
            grid[newRow, newCol] = t;

            // Calculate end position of player on new tile
            Posn endPos = new Posn(newRow, newCol, newTilePosn);

            // Calculate end position of player if additional tiles to move across
            endPos = followPathsMock(endPos);
            return(endPos);
        }
Example #4
0
        public Posn moveMockPlayer(Posn startPos)
        {
            if (onEdge(startPos))
            {
                return(startPos);
            }

            int[] nextCoord = nextTileCoord(startPos);
            int   nextRow   = nextCoord[0];
            int   nextCol   = nextCoord[1];

            // End recursion if no more tiles along path
            if (!occupied(nextRow, nextCol))
            {
                return(startPos);
            }
            else // Recursively follow path
            {
                // set the current location of the player to be the the next grid location
                Tile nextTile = grid[nextRow, nextCol];
                int  endPosn  = getEndOfPathOnTile(nextTile, startPos.returnLocationOnTile());
                Posn newPosn  = new Posn(nextRow, nextCol, endPosn);
                return(moveMockPlayer(newPosn));
            }
        }
Example #5
0
 public bool isEqual(Posn checkP)
 {
     if ((checkP.returnRow() == row) && (checkP.returnCol() == col) &&
         (checkP.returnLocationOnTile() == locOnTile))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #6
0
        // Returns true if a position is on the edge of the board, due to elimination
        public bool isElimPosn(Posn p)
        {
            int row     = p.returnRow();
            int col     = p.returnCol();
            int tilePos = p.returnLocationOnTile();

            // Phantom tile positions are valid start positions on the board edge, and don't cause elimination
            bool phantomTile = col == -1 || col == 6 || row == -1 || row == 6;

            if (phantomTile)
            {
                return(false);
            }

            bool topEdgeElim    = row == 0 && (tilePos == 0 || tilePos == 1);
            bool bottomEdgeElim = row == 5 && (tilePos == 4 || tilePos == 5);
            bool leftEdgeElim   = col == 0 && (tilePos == 6 || tilePos == 7);
            bool rightEdgeElim  = col == 5 && (tilePos == 2 || tilePos == 3);

            return(topEdgeElim || bottomEdgeElim || leftEdgeElim || rightEdgeElim);
        }
Example #7
0
        public bool onEdge(Posn p)
        {
            int row     = p.returnRow();
            int col     = p.returnCol();
            int tilePos = p.returnLocationOnTile();

            if (row == 0 && (col != -1 && col != 6))
            {
                if (tilePos == 0 || tilePos == 1)
                {
                    return(true);
                }
            }
            if (row == 5 && (col != -1 && col != 6))
            {
                if (tilePos == 4 || tilePos == 5)
                {
                    return(true);
                }
            }

            if (col == 0 && (row != -1 && row != 6))
            {
                if (tilePos == 6 || tilePos == 7)
                {
                    return(true);
                }
            }
            if (col == 5 && (row != -1 && row != 6))
            {
                if (tilePos == 2 || tilePos == 3)
                {
                    return(true);
                }
            }
            return(false);
        }
Example #8
0
        public static XElement posnToPawnLocXML(Posn p)
        {
            XElement hv;
            int      loc = p.returnLocationOnTile();

            switch (loc)
            {
            case 0:
            case 1:
            case 4:
            case 5:
                hv = new XElement("h", "");
                break;

            case 2:
            case 3:
            case 6:
            case 7:
                hv = new XElement("v", "");
                break;

            default:
                hv = null;
                break;
            }

            XElement edge;

            switch (loc)
            {
            case 0:
            case 1:
                edge = new XElement("n", p.returnRow());
                break;

            case 5:
            case 4:
                edge = new XElement("n", p.returnRow() + 1);
                break;

            case 2:
            case 3:
                edge = new XElement("n", p.returnCol() + 1);
                break;

            case 6:
            case 7:
                edge = new XElement("n", p.returnCol());
                break;

            default:
                edge = null;
                break;
            }

            XElement locOnEdge;

            switch (loc)
            {
            case 0:
            case 5:
                locOnEdge = new XElement("n", p.returnCol() * 2);
                break;

            case 1:
            case 4:
                locOnEdge = new XElement("n", p.returnCol() * 2 + 1);
                break;

            case 2:
            case 7:
                locOnEdge = new XElement("n", p.returnRow() * 2);
                break;

            case 3:
            case 6:
                locOnEdge = new XElement("n", p.returnRow() * 2 + 1);
                break;

            default:
                locOnEdge = null;
                break;
            }

            if (hv == null || edge == null || locOnEdge == null)
            {
                throw new Exception("Invalid position input to posnToPawnLocXML!!!!!");
            }
            return(new XElement("pawn-loc", hv, edge, locOnEdge));
        }