Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
 public bool isEqual(Posn checkP)
 {
     if ((checkP.returnRow() == row) && (checkP.returnCol() == col) &&
         (checkP.returnLocationOnTile() == locOnTile))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 3
0
        // Returns a position on the board from the 2 options, after parsing pawn loc XML
        // Needed because board has 2 positions per location
        public static Posn pawnLocToPosn(List <Posn> possiblePosns, Board board)
        {
            if (possiblePosns.Count != 2)
            {
                throw new Exception("There should only be two possible pawn locations.");
            }
            // if on edge
            // start game or eliminated
            // check if there is a tile in the onedge position
            //not on edge
            // check if there is a tile on a posn and choose that one

            Posn phantomPosn = null;
            Posn edgePosn    = null;

            if (board.isElimPosn(possiblePosns[0]))
            {
                phantomPosn = possiblePosns[1];
                edgePosn    = possiblePosns[0];
            }
            else if (board.isElimPosn(possiblePosns[1]))
            {
                phantomPosn = possiblePosns[0];
                edgePosn    = possiblePosns[1];
            }
            if (phantomPosn != null)
            {
                if (board.getTileAt(edgePosn.returnRow(), edgePosn.returnCol()) != null)
                {
                    return(edgePosn);
                }
                return(phantomPosn);
            }

            // Player is always on a tile, about to move to an empty space
            // Valid positions must be on a tile
            Posn posn1 = possiblePosns[0];
            Posn posn2 = possiblePosns[1];

            if (board.getTileAt(posn1.returnRow(), posn1.returnCol()) != null)
            {
                return(posn1);
            }
            else if (board.getTileAt(posn2.returnRow(), posn2.returnCol()) != null)
            {
                return(posn2);
            }
            else
            {
                throw new Exception("Invalid posn of player (not on edge and don't have tiles anywhere around it).");
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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));
        }