Exemple #1
0
node* getOriginNode()
{
	node* mazeArrayElement_pst = &mazeArray[originNodePos_i32];

	if(NULLDIRECTION == getAvailableDirections(mazeArrayElement_pst))
	{
		return NULL;
	}
	else
	{
		return mazeArrayElement_pst;
	}
}
Exemple #2
0
node* searchMazeArray(int32 f_xCord_i32, int32 f_yCord_i32)
{
	node* mazeArrayElement_pst = NULL;

	uint32 it = 0; // better to initialize here

	for(; it < mazeArrayElements_ui32; it++)
	{
		mazeArrayElement_pst = &mazeArray[it];

		if (NULL != mazeArrayElement_pst)
		{
			coordinates mazeElementCoordinate_st = getNodeCoordinates(mazeArrayElement_pst);

			if((f_xCord_i32 == mazeElementCoordinate_st.x_Coordinate_i32) &&
				(f_yCord_i32 == mazeElementCoordinate_st.y_Coordinate_i32))
			{
				if(NULLDIRECTION == getAvailableDirections(mazeArrayElement_pst))
				{
					return NULL;
				}

				break;
			}
			else
			{
				// Left Intentionally blank
			}
		}

	}

	if((NULL == mazeArrayElement_pst) || (mazeArrayElements_ui32 == it))
	{
		return NULL;
	}
	else
	{
		return mazeArrayElement_pst;
	}
}
static direction chooseDirection(direction currentDirection, struct node *node, uint8_t x, uint8_t y)
{
    getAvailableDirections(currentDirection);

    if (getNextNode(node, dirs[0]) != empty) {
        return dirs[1];
    } else if (getNextNode(node, dirs[1]) != empty) {
        return dirs[0];
    }

    uint8_t diffX = abs(x - targetX);
    uint8_t diffY = abs(y - targetY);

    if (diffX > diffY) {
        if (x > targetX) {
            if ((dirs[0] == WEST) || (dirs[1] == WEST)) {
                return WEST;
            }
        }
        if (x < targetX) {
            if ((dirs[0] == EAST) || (dirs[1] == EAST)) {
                return EAST;
            }
        }
        if (y > targetY) {
            if ((dirs[0] == NORTH) || (dirs[1] == NORTH)) {
                return NORTH;
            }
        }
        if (y < targetY) {
            if ((dirs[0] == SOUTH) || (dirs[1] == SOUTH)) {
                return SOUTH;
            }
        }
    } else {
        if (y > targetY) {
            if ((dirs[0] == NORTH) || (dirs[1] == NORTH)) {
                return NORTH;
            }
        }
        if (y < targetY) {
            if ((dirs[0] == SOUTH) || (dirs[1] == SOUTH)) {
                return SOUTH;
            }
        }
        if (x > targetX) {
            if ((dirs[0] == WEST) || (dirs[1] == WEST)) {
                return WEST;
            }
        }
        if (x < targetX) {
            if ((dirs[0] == EAST) || (dirs[1] == EAST)) {
                return EAST;
            }
        }
    }

    if (dirs[0] != NONE) {
        return dirs[0];
    }

    return currentDirection;
}