public static void floodfill(State state, boolean[][] map, int startX, int startY, boolean token)
    {
        /* Create stack to store nodes */
        Stack<Position> nodes = new Stack<Position>();
        /* Declare an positionobject to pop to from stack */
        Position currentPosition = new Position(startX, startY);

        /* Push the start position node, for the search on the stack */
        nodes.push(currentPosition);

        /* Search for a path to the wanted goal */
        while (!nodes.empty()){
            currentPosition = nodes.pop();
            int x = currentPosition.x;
            int y = currentPosition.y;
            map[x][y] = token;

            /* Create child nodes */
            if (map[x+1][y] != token && state.isFree(x+1, y))
            {
                nodes.add(new Position(x+1, y));
            }
            if (map[x-1][y] != token && state.isFree(x-1, y))
            {
                nodes.add(new Position(x-1, y));
            }
            if (map[x][y+1] != token && state.isFree(x, y+1))
            {
                nodes.add(new Position(x, y+1));
            }
            if (map[x][y-1] != token && state.isFree(x, y-1))
            {
                nodes.add(new Position(x, y-1));
            }
        }
    }