void dfs(int x, int y, int value)
{
    if (x==TO_X && y==TO_Y)
    {
        if (value > g_maxValue)
        {
            g_maxValue = value;
        }
        return ;
    }

    for (int dir=0; dir<DIR_COUNT; ++dir)
    {
        int next_x = x + DIR_X[dir];
        int next_y = y + DIR_Y[dir];
        if (IsInBound(next_x, next_y)
            && !g_visit[next_x][next_y]
            && value+g_chess[next_x][next_y]<=g_maxLimit)
        {
            g_visit[next_x][next_y] = true;
            dfs(next_x, next_y, value+g_chess[next_x][next_y]);
            g_visit[next_x][next_y] = false;
        }
    }
}
Beispiel #2
0
void dfs(int x, int y, int ti, int bt)
{
    //-------------------------------------
    printf("%d %d %d %d\n", x, y, ti, bt);
    //-------------------------------------
    
    if (maze[x][y]==3 && bt>0)
    {
        IsSolved = true;
        if (ti < min)
            min = ti;
        return ;
    }/* End of If */
    
    for (int i=0; i<4; ++i)
    {
        int nx = x + dx[i];
        int ny = y + dy[i];
        
        if (!hash[nx][ny] && bt-1>0
            && maze[nx][ny] && IsInBound(nx, ny))
        {
            hash[nx][ny] = true;
            if (maze[nx][ny] == 4)
                dfs(nx, ny, ti+1, 6);
            else
                dfs(nx, ny, ti+1, bt-1);
            hash[nx][ny] = false;
        }
    }
}/* dfs */
Beispiel #3
0
int CGUIList::GetIndexAt(float x, float y) const
{
	if (!IsInBound(x, y)) return -1;
	x -= Parent->GetX() + m_offsetX + X;
	y -= Parent->GetY() + m_offsetY + Y;

	int i = (int)floor(y / m_itemHeight);
	if ( i < 0 || i >= m_lines) return -1;
	i += m_topline;
	if (i >= (int)Items.size()) return -1;
	return i;
}
Beispiel #4
0
void DFS()
{
    int dir, IsFind, top = -1;
    struct path cur, next;
    
    cur.x = 0;
    cur.y = 0;
    cur.dir = -1;
    stack[++top] = cur;
    
    maze[0][0] = -1;
    while (top != -1)
    {
        cur = stack[top], dir = stack[top].dir;
        if (cur.x==4 && cur.y==4)
        {   /* 表示已经找到出口,打印路径 */ 
            PrintPath(top);
            break;
        }/* End of If */
        
        IsFind = 0;
        while (dir<4 && IsFind==0)
        {   /* 从上下左右4个方向分别探索 */ 
            ++dir;
            
            next.x = cur.x + dx[dir];
            next.y = cur.y + dy[dir];
            
            if (IsInBound(next.x, next.y) && !maze[next.x][next.y])
            {   /* 可行位置 */
                IsFind = 1;
            }
        }/* End of For */
        if (IsFind)
        {
            next.dir = -1;
            stack[top].dir = dir;
            stack[++top] = next;
            maze[stack[top].x][stack[top].y] = -1;
        }
        else
        {
            maze[stack[top].x][stack[top].y] = 0;
            --top;
        }
    }/* End of While */
}/* DFS */
Beispiel #5
0
void dfs(int x, int y)
{
    for (int i=0; i<8; ++i)
    {
        int nx = x + dx[i];
        int ny = y + dy[i];
        
        if (!vis[nx][ny] && IsInBound(nx, ny))
        {
            ++grids;
            vis[nx][ny] = 1;
            path[grids].row = nx+1;
            path[grids].col = ny+'A';
            
            dfs(nx, ny);
        }
    }
}/* dfs */
int Solve()
{
    int rear = -1;
    int front = -1;
    
    cur.x = sx;
    cur.y = sy;
    vis[sx][sy] = 1; /* 从起始位置开始的探索标记为 1 */ 
    q[++rear] = cur; /* 起始坐标入队 */ 
    
    next.x = tx;
    next.y = ty;
    vis[tx][ty] = 2;  /* 从终点位置开始的探索标记为 2 */ 
    q[++rear] = next; /* 终点坐标入队 */ 
    
    while (front < rear)
    {
        cur = q[++front]; /* 队首节点坐标出队 */
        
        for (i=0; i<8; ++i)
        {
            next.x = cur.x + dx[i];
            next.y = cur.y + dy[i];
            
            if (!IsInBound(next.x, next.y))
                continue;
                
            if (!vis[next.x][next.y])
            {
                vis[next.x][next.y] = vis[cur.x][cur.y];     /* 设为与当前探索路径相同的标记 */
                mat[next.x][next.y] = mat[cur.x][cur.y] + 1; /* 记录步数 */ 
                q[++rear] = next; /* 当前合法坐标位置入队 */ 
            }
            else if (vis[cur.x][cur.y] != vis[next.x][next.y])
            {   /* 说明从起点出发的探索与从终点出发的探索重合 */ 
                return mat[cur.x][cur.y]+mat[next.x][next.y]+1;
            }
        }/* End of For */
    }/* End of While */
}/* Solve */