门户网站建设模式包括网站群和商城手机网站建设多少钱

web/2025/9/28 3:11:26/文章来源:
门户网站建设模式包括网站群和,商城手机网站建设多少钱,淄博seo开发,wordpress 主题更改语言实现效果如下 类似 推箱子小游戏 的变种 C/C版本 BFS最短路径 黑色代表墙壁 不能越过 蓝色代表HOME点 灰色代表要找的小箱子 绿色代表路径 最终目标是将灰色的小箱子移动到蓝色的HOME点 需要两次搜索 第一次是 出发点到灰色小箱子 第二次是灰色小箱子到蓝色HOME点 BF…实现效果如下 类似 推箱子小游戏 的变种 C/C版本 BFS最短路径 黑色代表墙壁 不能越过 蓝色代表HOME点 灰色代表要找的小箱子 绿色代表路径   最终目标是将灰色的小箱子移动到蓝色的HOME点  需要两次搜索 第一次是 出发点到灰色小箱子  第二次是灰色小箱子到蓝色HOME点 BFS 搜索路径之后 找到一条最短路径  动画效果用的是JAVA的 一个jar包  完整的代码 包含动画效果已经上传点击这里下载 C语言编译 gcc box.c graphics.c -o boxC编译 g box.cpp graphics.c -o box需要安装jdk 17版本   如下图 将 安装包里的所有文件放到 如下的jdk bin目录   执行如下代码  最后的jar包 用绝对路径就可以  ./box | ./java -jar /home/QMCY/robot/drawppp.jar代码很乱  临时记录下  C语言版本 #include string.h #include graphics.h#define GRID_SIZE_X 10 #define GRID_SIZE_Y 10#define ROBOT R#define HOME_X 9 #define HOME_Y 2#define MARKER_X 7 #define MARKER_Y 7#define ROBOT_X 6 #define ROBOT_Y 5 #define MAX_N 105int g_father[MAX_N][MAX_N]; int dist[MAX_N][MAX_N]; int last_dir[MAX_N][MAX_N];int dir[MAX_N*MAX_N]; char g_has_visited[MAX_N][MAX_N]; //vis[x][y]表示xy点是否遍历过int Queue[MAX_N*MAX_N]; //用Q来模拟队列 给定两个下标 front和rear 那么入队则是Q[rear]u 出队是uQ[front]int coordinate[MAX_N*MAX_N];const int squareSize 50;const int windowSize 600;// Define the grid elements const char EMPTY ; const char BLOCK #; const char MARKER *; const char HOME H;// Define robot directions typedef enum { WEST , EAST, NORTH, SOUTH }Direction;// Define the robot struct typedef struct {int x;int y;Direction direction;char carryingMarker; }Robot;void drawStep(int homeX, int homeY) {background();setColour(pink);homeX homeX*squareSize;homeY homeY*squareSize;fillRect(homeX, homeY, squareSize, squareSize); }void drawMarker(int x,int y) {background();setColour(gray);x x*squareSize;y y*squareSize;fillRect(x, y, squareSize, squareSize); }void drawBlocks(int x,int y) {background();setColour(black);x x*squareSize;y y*squareSize;fillRect(x, y, squareSize, squareSize); }void drawEmpty(int x,int y) {foreground();setColour(white);x x*squareSize;y y*squareSize;fillRect(x, y, squareSize, squareSize); }// Function to initialize the grid void initializeGrid(char grid[][GRID_SIZE_Y]) {// Initialize the grid with empty spacesfor (int i 0; i GRID_SIZE_X; i) {for (int j 0; j GRID_SIZE_X; j) {grid[i][j] EMPTY;}}// Place blocks, markers, and home squaregrid[8][8] BLOCK;grid[9][5] BLOCK;grid[8][5] BLOCK;grid[7][5] BLOCK;grid[6][7] BLOCK;grid[8][7] BLOCK; grid[7][8] BLOCK; grid[7][8] BLOCK; grid[2][2] BLOCK; grid[3][3] BLOCK; grid[4][4] BLOCK; grid[5][5] BLOCK; grid[6][6] BLOCK; grid[MARKER_X][MARKER_Y] MARKER;grid[HOME_X][HOME_Y] HOME; }// Function to display the grid void displayGrid(const char grid[][GRID_SIZE_X]) {setWindowSize(windowSize, windowSize);background(); // Must draw on the background layer.int x;int y;for (x0; xGRID_SIZE_X; x) {for (y0; yGRID_SIZE_X; y){drawRect(x*squareSize, y*squareSize, squareSize, squareSize);}}}void draw_north(int x, int y) {int x_coords[] {x, x50, x25};int y_coords[] {y50, y50, y};fillPolygon(3, x_coords, y_coords); }void draw_east(int x, int y) {int x_coords[] {x, x, x50};int y_coords[] {y, y50, y25};fillPolygon(3, x_coords, y_coords); }void draw_south(int x, int y) {int x_coords[] {x, x50, x25};int y_coords[] {y, y, y50};fillPolygon(3, x_coords, y_coords); }void draw_west(int x, int y) {int x_coords[] {x50, x50, x};int y_coords[] {y, y50, y25};fillPolygon(3, x_coords, y_coords); }// Function to drop a marker void dropMarker(Robot *robot, char grid[][GRID_SIZE_X]) {if (!robot-carryingMarker) {return; // Robot is not carrying a marker}grid[robot-x][robot-y] MARKER;robot-carryingMarker 0;//drawRobot(robot.x, robot.y, (int)robot.direction);}void drawRobot(int x, int y, int direction) {foreground();clear();setColour(green);x x*squareSize;y y*squareSize;switch (direction){case NORTH: draw_north(x, y); break;case EAST: draw_east(x, y); break;case SOUTH: draw_south(x, y); break;case WEST: draw_west(x, y); break;}}void drawRobotWithBg(int x, int y, int direction) {foreground();clear();setColour(gray);x x*squareSize;y y*squareSize;fillRect(x, y, squareSize, squareSize); setColour(green);switch (direction){case NORTH: draw_north(x, y); break;case EAST: draw_east(x, y); break;case SOUTH: draw_south(x, y); break;case WEST: draw_west(x, y); break;}}void drawHome(int homeX, int homeY) {background();setColour(blue);homeX homeX*squareSize;homeY homeY*squareSize;fillRect(homeX, homeY, squareSize, squareSize); }void drawShort(int homeX, int homeY) {background();setColour(orange);homeX homeX*squareSize;homeY homeY*squareSize;fillRect(homeX, homeY, squareSize, squareSize); }void forward(Robot *robot, char grid[][GRID_SIZE_X]) {// Calculate the next position based on the directionint nextX robot-x;int nextY robot-y;if (robot-direction NORTH) {--nextX;} else if (robot-direction SOUTH) {nextX;} else if (robot-direction EAST) {nextY;} else if (robot-direction WEST) {--nextY;}// Check if the next position is validif (nextX 0 nextX GRID_SIZE_X nextY 0 nextY GRID_SIZE_X grid[nextX][nextY] ! BLOCK) {// Move the robotgrid[robot-x][robot-y] EMPTY;robot-x nextX;robot-y nextY;grid[robot-x][robot-y] ROBOT;}drawRobot(robot-x, robot-y, robot-direction);}char markersLeft(char grid[][GRID_SIZE_X]) {for (int i 0; i GRID_SIZE_X; i) {for (int j 0; j GRID_SIZE_X; j) {if (grid[i][j] MARKER) {return 1;}}}return 0; }void turn_left(Robot *robot) {if (robot-direction NORTH) {robot-direction WEST;} else if (robot-direction SOUTH) {robot-direction EAST;} else if (robot-direction EAST) {robot-direction NORTH;} else if (robot-direction WEST) {robot-direction SOUTH;}drawRobot(robot-x, robot-y, robot-direction);}void turn_right(Robot *robot) {if (robot-direction NORTH) {robot-direction EAST;} else if (robot-direction SOUTH) {robot-direction WEST;} else if (robot-direction EAST) {robot-direction SOUTH;} else if (robot-direction WEST) {robot-direction NORTH;}drawRobot(robot-x, robot-y, robot-direction);}// Function to pick up a marker void pickUpMarker(Robot *robot, char grid[][GRID_SIZE_Y]) {if (grid[robot-x][robot-y] MARKER) {robot-carryingMarker 1;grid[robot-x][robot-y] EMPTY;} }void findAndCollectMarkers(Robot *robot, char grid[][GRID_SIZE_X]) {while (markersLeft(grid)) {int initialX robot-x;int initialY robot-y;Direction initialDirection robot-direction;// Use the right hand rule to navigateif (robot-direction NORTH) {if (grid[robot-x][robot-y 1] ! BLOCK) {turn_right(robot);} else if (grid[robot-x - 1][robot-y] ! BLOCK) {forward(robot, grid);} else {turn_left(robot);}} else if (robot-direction SOUTH) {if (grid[robot-x][robot-y - 1] ! BLOCK) {turn_right(robot);} else if (grid[robot-x 1][robot-y] ! BLOCK) {forward(robot, grid);} else {turn_left(robot);}} else if (robot-direction EAST) {if (grid[robot-x 1][robot-y] ! BLOCK) {turn_right(robot);} else if (grid[robot-x][robot-y 1] ! BLOCK) {forward(robot, grid);} else {turn_left(robot);}} else if (robot-direction WEST) {if (grid[robot-x - 1][robot-y] ! BLOCK) {turn_right(robot);} else if (grid[robot-x][robot-y - 1] ! BLOCK) {forward(robot, grid);} else {turn_left(robot);}}if (initialX robot-x initialY robot-y initialDirection robot-direction) {// Robot is stuck, rotate 180 degreesturn_left(robot);turn_left(robot);}forward(robot, grid);sleep(500); // Adjust sleep duration for animation speedpickUpMarker(robot, grid);} }int canMoveForward(Robot *robot, char grid[][GRID_SIZE_X]) {int nextX robot-x;int nextY robot-y;if (robot-direction NORTH) {--nextY;} else if (robot-direction SOUTH) {nextY;} else if (robot-direction EAST) {nextX;} else if (robot-direction WEST) {--nextX;}// Check if the next position is validif (nextX 1 nextX GRID_SIZE_X nextY 1 nextY GRID_SIZE_X grid[nextX][nextY] ! BLOCK) {// Move the robot//grid[robot-x][robot-y] EMPTY;//robot-x nextX;//robot-y nextY;//grid[robot-x][robot-y] R; // Robot represented by Rreturn 1;}return 0;}// Function to turn the robot left (anti-clockwise) void left(Robot *robot) {if (robot-direction NORTH) {robot-direction WEST;} else if (robot-direction SOUTH) {robot-direction EAST;} else if (robot-direction EAST) {robot-direction NORTH;} else if (robot-direction WEST) {robot-direction SOUTH;}drawRobot(robot-x, robot-y, robot-direction);}void right(Robot *robot) {if (robot-direction NORTH) {robot-direction EAST;} else if (robot-direction SOUTH) {robot-direction WEST;} else if (robot-direction EAST) {robot-direction SOUTH;} else if (robot-direction WEST) {robot-direction NORTH;}drawRobot(robot-x, robot-y, robot-direction);}#if 0 bool findShortestPath(Robot robot, char grid[][GRID_SIZE_X]) {// Use BFS to find the shortest pathstd::queuestd::pairint, int q; // Queue for BFSstd::vectorstd::vectorbool visited(GRID_SIZE_X, std::vectorbool(GRID_SIZE_X, false));q.push({robot.x, robot.y});visited[robot.x][robot.y] true;int urobot.x*GRID_SIZE_Xrobot.y;father[robot.x][robot.y]u;sleep(2000);while (!q.empty()) {int x q.front().first;int y q.front().second;q.pop();//drawRobot(x, y, (int)robot.direction);if (grid[x][y] MARKER) {// Found a marker, pick it uppickUpMarker(robot, grid);//dropMarker(robot, grid);//drawMarker(MARKER_X,MARKER_Y);//drawRobot(x, y, (int)robot.direction);return true;}// Explore neighboring cellsint dx[] {-1, 1, 0, 0};int dy[] {0, 0, -1, 1};for (int i 0; i 4; i) {ux*GRID_SIZE_Xy;int nx x dx[i];int ny y dy[i];if (nx 0 nx GRID_SIZE_X ny 0 ny GRID_SIZE_X !visited[nx][ny] grid[nx][ny] ! BLOCK) {q.push({nx, ny});//drawRobot(nx, ny, (int)robot.direction);//drawStep(nx, ny);//printf(x%d y%d \n,nx,ny);visited[nx][ny] true;father[nx][ny]u;//dist[nx][ny]1dist[x][y];last_dir[nx][ny]i;}// printf(findShortestPath 2222\n);//sleep(200);}//drawRobot(robot.x, robot.y, (int)robot.direction);//sleep(10);}return false; // No markers found }#elsechar findShortestPath(int robot_x,int robot_y, char grid[][GRID_SIZE_X]) {// Use BFS to find the shortest path//std::queuestd::pairint, int q; // Queue for BFS//std::vectorstd::vectorbool visited(GRID_SIZE_X, std::vectorbool(GRID_SIZE_X, false));int front,rear;rearfront0;Robot robot;robot.x robot_x;robot.y robot_y;//q.push({robot.x, robot.y});g_has_visited[robot.x][robot.y] 1;int urobot.x*GRID_SIZE_Xrobot.y;g_father[robot.x][robot.y]u;Queue[rear]u;sleep(1000);//while (!q.empty()) while(rearfront){uQueue[front];//int x q.front().first;//int y q.front().second;//q.pop();//drawRobot(x, y, (int)robot.direction);int xu/GRID_SIZE_X;int yu%GRID_SIZE_X;if (grid[x][y] MARKER) {// Found a marker, pick it uppickUpMarker(robot, grid);//dropMarker(robot, grid);//drawMarker(MARKER_X,MARKER_Y);//drawRobot(x, y, (int)robot.direction);return 1;}// Explore neighboring cellsint dx[] {-1, 1, 0, 0};int dy[] {0, 0, -1, 1};for (int i 0; i 4; i) {//ux*GRID_SIZE_Xy;int nx x dx[i];int ny y dy[i];if (nx 0 nx GRID_SIZE_X ny 0 ny GRID_SIZE_X !g_has_visited[nx][ny] grid[nx][ny] ! BLOCK) {#if 0q.push({nx, ny});//drawRobot(nx, ny, (int)robot.direction);//drawStep(nx, ny);//printf(x%d y%d \n,nx,ny);visited[nx][ny] true;father[nx][ny]u;//dist[nx][ny]1dist[x][y];last_dir[nx][ny]i;#elseint vnx*GRID_SIZE_Xny;Queue[rear]v;g_has_visited[nx][ny]1;g_father[nx][ny]u;dist[nx][ny]1dist[x][y];last_dir[nx][ny]i;if (grid[nx][ny] MARKER){return 1;}#endif}// printf(findShortestPath 2222\n);//sleep(200);}//drawRobot(robot.x, robot.y, (int)robot.direction);//sleep(10);}return 0; // No markers found }#endifvoid print_path(int x,int y,char has_marker) {int steps0;int pos_x,pos_y,direction;while(1){int ug_father[x][y];int fxu/GRID_SIZE_X;int fyu%GRID_SIZE_X;if (fxx fyy){break;}dir[steps]last_dir[x][y];coordinate[steps] x*GRID_SIZE_Xy;xfx;yfy;}while(steps--){pos_x coordinate[steps]/GRID_SIZE_X;pos_y coordinate[steps]%GRID_SIZE_X;direction dir[steps];if(has_marker){drawRobotWithBg(pos_x,pos_y,direction);}else{drawRobot(pos_x, pos_y,direction);}sleep(300);}}int main(int argc, char **argv) {char grid[GRID_SIZE_X][GRID_SIZE_X];initializeGrid(grid);Robot robot;robot.x ROBOT_X; // Initial X positionrobot.y ROBOT_Y; // Initial Y positionrobot.direction EAST;robot.carryingMarker 0;// Display the initial griddisplayGrid(grid);drawHome(HOME_X, HOME_Y);drawMarker(MARKER_X,MARKER_Y);drawBlocks(8,8); drawBlocks(9,5);drawBlocks(8,5);drawBlocks(7,5);drawBlocks(6,7);drawBlocks(8,7);drawBlocks(7,8);drawBlocks(2,2);drawBlocks(3,3);drawBlocks(4,4);drawBlocks(5,5);drawBlocks(6,6);#if 0findAndCollectMarkers(robot, grid);#elif 0while (!robot.carryingMarker) {if(canMoveForward(robot, grid)){forward(robot, grid);}else{left(robot);}sleep(500);//printf(robot.x %d y %d dir %d\n,robot.x,robot.y,robot.direction);} #elsewhile (!findShortestPath(robot.x,robot.y, grid)) {forward(robot, grid);sleep(500); // Adjust sleep duration for animation speed}print_path(MARKER_X,MARKER_Y,0);robot.x MARKER_X;robot.y MARKER_Y;grid[MARKER_X][MARKER_Y] EMPTY;grid[HOME_X][HOME_Y] MARKER;memset(g_has_visited,0,sizeof(g_has_visited));while (!findShortestPath(robot.x,robot.y, grid)) {forward(robot, grid);sleep(500); // Adjust sleep duration for animation speed}print_path(HOME_X,HOME_Y,1);#endifreturn 0; } C版本 #include unistd.h // For sleep function#include graphics.h#define GRID_SIZE_X 10 #define GRID_SIZE_Y 10#define ROBOT Rconst int maxn105;#define HOME_X 0 #define HOME_Y 0#define MARKER_X 7 #define MARKER_Y 7#define ROBOT_X 9 #define ROBOT_Y 0int father[maxn][maxn]; int dist[maxn][maxn]; int last_dir[maxn][maxn];int dir[maxn*maxn]; bool visit_first[maxn][maxn]; //vis[x][y]表示xy点是否遍历过 bool visit_second[maxn][maxn]; //vis[x][y]表示xy点是否遍历过int Queue[maxn*maxn]; //用Q来模拟队列 给定两个下标 front和rear 那么入队则是Q[rear]u 出队是uQ[front]int coordinate[maxn*maxn];const int squareSize 50;const int windowSize 600;// Define the grid elements const char EMPTY ; const char BLOCK #; const char MARKER *; const char HOME H;// Define robot directions enum Direction { WEST , EAST, NORTH, SOUTH };// Define the robot struct struct Robot {int x;int y;Direction direction;bool carryingMarker; };void drawStep(int homeX, int homeY) {background();setColour(pink);homeX homeX*squareSize;homeY homeY*squareSize;fillRect(homeX, homeY, squareSize, squareSize); }void drawMarker(int x,int y) {background();setColour(gray);x x*squareSize;y y*squareSize;fillRect(x, y, squareSize, squareSize); }void drawBlocks(int x,int y) {background();setColour(black);x x*squareSize;y y*squareSize;fillRect(x, y, squareSize, squareSize); }void drawEmpty(int x,int y) {foreground();setColour(white);x x*squareSize;y y*squareSize;fillRect(x, y, squareSize, squareSize); }// Function to initialize the grid void initializeGrid(char grid[][GRID_SIZE_Y]) {// Initialize the grid with empty spacesfor (int i 0; i GRID_SIZE_X; i) {for (int j 0; j GRID_SIZE_X; j) {grid[i][j] EMPTY;}}// Place blocks, markers, and home squaregrid[8][8] BLOCK;grid[9][5] BLOCK;grid[8][5] BLOCK;grid[7][5] BLOCK;grid[6][7] BLOCK;grid[8][7] BLOCK; grid[7][8] BLOCK; grid[7][8] BLOCK; grid[2][2] BLOCK; grid[3][3] BLOCK; grid[4][4] BLOCK; grid[5][5] BLOCK; grid[6][6] BLOCK; grid[MARKER_X][MARKER_Y] MARKER;grid[HOME_X][HOME_Y] HOME; }// Function to display the grid void displayGrid(const char grid[][GRID_SIZE_X]) {setWindowSize(windowSize, windowSize);background(); // Must draw on the background layer.int x;int y;for (x0; xGRID_SIZE_X; x) {for (y0; yGRID_SIZE_X; y){drawRect(x*squareSize, y*squareSize, squareSize, squareSize);}}}void draw_north(int x, int y) {int x_coords[] {x, x50, x25};int y_coords[] {y50, y50, y};fillPolygon(3, x_coords, y_coords); }void draw_east(int x, int y) {int x_coords[] {x, x, x50};int y_coords[] {y, y50, y25};fillPolygon(3, x_coords, y_coords); }void draw_south(int x, int y) {int x_coords[] {x, x50, x25};int y_coords[] {y, y, y50};fillPolygon(3, x_coords, y_coords); }void draw_west(int x, int y) {int x_coords[] {x50, x50, x};int y_coords[] {y, y50, y25};fillPolygon(3, x_coords, y_coords); }// Function to drop a marker void dropMarker(Robot robot, char grid[][GRID_SIZE_X]) {if (!robot.carryingMarker) {return; // Robot is not carrying a marker}grid[robot.x][robot.y] MARKER;robot.carryingMarker false;//drawRobot(robot.x, robot.y, (int)robot.direction);}void drawRobot(int x, int y, int direction) {foreground();clear();setColour(green);x x*squareSize;y y*squareSize;switch (direction){case Direction::NORTH: draw_north(x, y); break;case Direction::EAST: draw_east(x, y); break;case Direction::SOUTH: draw_south(x, y); break;case Direction::WEST: draw_west(x, y); break;}}void drawRobotWithBg(int x, int y, int direction) {foreground();clear();setColour(gray);x x*squareSize;y y*squareSize;fillRect(x, y, squareSize, squareSize); setColour(green);switch (direction){case Direction::NORTH: draw_north(x, y); break;case Direction::EAST: draw_east(x, y); break;case Direction::SOUTH: draw_south(x, y); break;case Direction::WEST: draw_west(x, y); break;}}void drawHome(int homeX, int homeY) {background();setColour(blue);homeX homeX*squareSize;homeY homeY*squareSize;fillRect(homeX, homeY, squareSize, squareSize); }void drawShort(int homeX, int homeY) {background();setColour(orange);homeX homeX*squareSize;homeY homeY*squareSize;fillRect(homeX, homeY, squareSize, squareSize); }void forward(Robot *robot, char grid[][GRID_SIZE_X]) {// Calculate the next position based on the directionint nextX robot-x;int nextY robot-y;if (robot-direction NORTH) {--nextX;} else if (robot-direction SOUTH) {nextX;} else if (robot-direction EAST) {nextY;} else if (robot-direction WEST) {--nextY;}// Check if the next position is validif (nextX 0 nextX GRID_SIZE_X nextY 0 nextY GRID_SIZE_X grid[nextX][nextY] ! BLOCK) {// Move the robotgrid[robot-x][robot-y] EMPTY;robot-x nextX;robot-y nextY;grid[robot-x][robot-y] ROBOT;}drawRobot(robot-x, robot-y, robot-direction);}bool markersLeft(char grid[][GRID_SIZE_X]) {for (int i 0; i GRID_SIZE_X; i) {for (int j 0; j GRID_SIZE_X; j) {if (grid[i][j] MARKER) {return true;}}}return false; }void turn_left(Robot *robot) {if (robot-direction NORTH) {robot-direction WEST;} else if (robot-direction SOUTH) {robot-direction EAST;} else if (robot-direction EAST) {robot-direction NORTH;} else if (robot-direction WEST) {robot-direction SOUTH;}drawRobot(robot-x, robot-y, robot-direction);}void turn_right(Robot *robot) {if (robot-direction NORTH) {robot-direction EAST;} else if (robot-direction SOUTH) {robot-direction WEST;} else if (robot-direction EAST) {robot-direction SOUTH;} else if (robot-direction WEST) {robot-direction NORTH;}drawRobot(robot-x, robot-y, robot-direction);}// Function to pick up a marker void pickUpMarker(Robot *robot, char grid[][GRID_SIZE_Y]) {if (grid[robot-x][robot-y] MARKER) {robot-carryingMarker true;grid[robot-x][robot-y] EMPTY;} }void findAndCollectMarkers(Robot *robot, char grid[][GRID_SIZE_X]) {while (markersLeft(grid)) {int initialX robot-x;int initialY robot-y;Direction initialDirection robot-direction;// Use the right hand rule to navigateif (robot-direction NORTH) {if (grid[robot-x][robot-y 1] ! BLOCK) {turn_right(robot);} else if (grid[robot-x - 1][robot-y] ! BLOCK) {forward(robot, grid);} else {turn_left(robot);}} else if (robot-direction SOUTH) {if (grid[robot-x][robot-y - 1] ! BLOCK) {turn_right(robot);} else if (grid[robot-x 1][robot-y] ! BLOCK) {forward(robot, grid);} else {turn_left(robot);}} else if (robot-direction EAST) {if (grid[robot-x 1][robot-y] ! BLOCK) {turn_right(robot);} else if (grid[robot-x][robot-y 1] ! BLOCK) {forward(robot, grid);} else {turn_left(robot);}} else if (robot-direction WEST) {if (grid[robot-x - 1][robot-y] ! BLOCK) {turn_right(robot);} else if (grid[robot-x][robot-y - 1] ! BLOCK) {forward(robot, grid);} else {turn_left(robot);}}if (initialX robot-x initialY robot-y initialDirection robot-direction) {// Robot is stuck, rotate 180 degreesturn_left(robot);turn_left(robot);}forward(robot, grid);sleep(500); // Adjust sleep duration for animation speedpickUpMarker(robot, grid);} }int canMoveForward(Robot *robot, char grid[][GRID_SIZE_X]) {int nextX robot-x;int nextY robot-y;if (robot-direction Direction::NORTH) {--nextY;} else if (robot-direction Direction::SOUTH) {nextY;} else if (robot-direction Direction::EAST) {nextX;} else if (robot-direction Direction::WEST) {--nextX;}// Check if the next position is validif (nextX 1 nextX GRID_SIZE_X nextY 1 nextY GRID_SIZE_X grid[nextX][nextY] ! BLOCK) {// Move the robot//grid[robot-x][robot-y] EMPTY;//robot-x nextX;//robot-y nextY;//grid[robot-x][robot-y] R; // Robot represented by Rreturn 1;}return 0;}// Function to turn the robot left (anti-clockwise) void left(Robot *robot) {if (robot-direction Direction::NORTH) {robot-direction Direction::WEST;} else if (robot-direction Direction::SOUTH) {robot-direction Direction::EAST;} else if (robot-direction Direction::EAST) {robot-direction Direction::NORTH;} else if (robot-direction Direction::WEST) {robot-direction Direction::SOUTH;}drawRobot(robot-x, robot-y, robot-direction);}void right(Robot *robot) {if (robot-direction Direction::NORTH) {robot-direction Direction::EAST;} else if (robot-direction Direction::SOUTH) {robot-direction Direction::WEST;} else if (robot-direction Direction::EAST) {robot-direction Direction::SOUTH;} else if (robot-direction Direction::WEST) {robot-direction Direction::NORTH;}drawRobot(robot-x, robot-y, robot-direction);}// Function to pick up a marker void pickUpMarker(Robot robot, char grid[][GRID_SIZE_X]) {if (grid[robot.x][robot.y] MARKER) {robot.carryingMarker true;grid[robot.x][robot.y] EMPTY;//drawRobot(robot.x, robot.y, (int)robot.direction);} }#if 0 bool findShortestPath(Robot robot, char grid[][GRID_SIZE_X]) {// Use BFS to find the shortest pathstd::queuestd::pairint, int q; // Queue for BFSstd::vectorstd::vectorbool visited(GRID_SIZE_X, std::vectorbool(GRID_SIZE_X, false));q.push({robot.x, robot.y});visited[robot.x][robot.y] true;int urobot.x*GRID_SIZE_Xrobot.y;father[robot.x][robot.y]u;sleep(2000);while (!q.empty()) {int x q.front().first;int y q.front().second;q.pop();//drawRobot(x, y, (int)robot.direction);if (grid[x][y] MARKER) {// Found a marker, pick it uppickUpMarker(robot, grid);//dropMarker(robot, grid);//drawMarker(MARKER_X,MARKER_Y);//drawRobot(x, y, (int)robot.direction);return true;}// Explore neighboring cellsint dx[] {-1, 1, 0, 0};int dy[] {0, 0, -1, 1};for (int i 0; i 4; i) {ux*GRID_SIZE_Xy;int nx x dx[i];int ny y dy[i];if (nx 0 nx GRID_SIZE_X ny 0 ny GRID_SIZE_X !visited[nx][ny] grid[nx][ny] ! BLOCK) {q.push({nx, ny});//drawRobot(nx, ny, (int)robot.direction);//drawStep(nx, ny);//printf(x%d y%d \n,nx,ny);visited[nx][ny] true;father[nx][ny]u;//dist[nx][ny]1dist[x][y];last_dir[nx][ny]i;}// printf(findShortestPath 2222\n);//sleep(200);}//drawRobot(robot.x, robot.y, (int)robot.direction);//sleep(10);}return false; // No markers found }#elsebool findShortestPath(int robot_x,int robot_y, char grid[][GRID_SIZE_X],bool visit[][maxn]) {// Use BFS to find the shortest path//std::queuestd::pairint, int q; // Queue for BFS//std::vectorstd::vectorbool visited(GRID_SIZE_X, std::vectorbool(GRID_SIZE_X, false));int front,rear;rearfront0;Robot robot;robot.x robot_x;robot.y robot_y;//q.push({robot.x, robot.y});bool **visited NULL;visit[robot.x][robot.y] true;int urobot.x*GRID_SIZE_Xrobot.y;father[robot.x][robot.y]u;Queue[rear]u;sleep(1000);//while (!q.empty()) while(rearfront){uQueue[front];//int x q.front().first;//int y q.front().second;//q.pop();//drawRobot(x, y, (int)robot.direction);int xu/GRID_SIZE_X;int yu%GRID_SIZE_X;if (grid[x][y] MARKER) {// Found a marker, pick it uppickUpMarker(robot, grid);//dropMarker(robot, grid);//drawMarker(MARKER_X,MARKER_Y);//drawRobot(x, y, (int)robot.direction);return true;}// Explore neighboring cellsint dx[] {-1, 1, 0, 0};int dy[] {0, 0, -1, 1};for (int i 0; i 4; i) {//ux*GRID_SIZE_Xy;int nx x dx[i];int ny y dy[i];if (nx 0 nx GRID_SIZE_X ny 0 ny GRID_SIZE_X !visit[nx][ny] grid[nx][ny] ! BLOCK) {#if 0q.push({nx, ny});//drawRobot(nx, ny, (int)robot.direction);//drawStep(nx, ny);//printf(x%d y%d \n,nx,ny);visited[nx][ny] true;father[nx][ny]u;//dist[nx][ny]1dist[x][y];last_dir[nx][ny]i;#elseint vnx*GRID_SIZE_Xny;Queue[rear]v;visit[nx][ny]true;father[nx][ny]u;dist[nx][ny]1dist[x][y];last_dir[nx][ny]i;if (grid[nx][ny] MARKER){return true;}#endif}// printf(findShortestPath 2222\n);//sleep(200);}//drawRobot(robot.x, robot.y, (int)robot.direction);//sleep(10);}return false; // No markers found }#endifvoid print_path(int x,int y,bool has_marker) {int steps0;int pos_x,pos_y,direction;while(true){int ufather[x][y];int fxu/GRID_SIZE_X;int fyu%GRID_SIZE_X;if (fxx fyy){break;}dir[steps]last_dir[x][y];coordinate[steps] x*GRID_SIZE_Xy;xfx;yfy;}while(steps--){pos_x coordinate[steps]/GRID_SIZE_X;pos_y coordinate[steps]%GRID_SIZE_X;direction dir[steps];if(has_marker){drawRobotWithBg(pos_x,pos_y,direction);}else{drawRobot(pos_x, pos_y,direction);}sleep(300);}}int main(int argc, char **argv) {char grid[GRID_SIZE_X][GRID_SIZE_X];initializeGrid(grid);Robot robot;robot.x ROBOT_X; // Initial X positionrobot.y ROBOT_Y; // Initial Y positionrobot.direction Direction::EAST;robot.carryingMarker false;// Display the initial griddisplayGrid(grid);drawHome(HOME_X, HOME_Y);drawMarker(MARKER_X,MARKER_Y);drawBlocks(8,8); drawBlocks(9,5);drawBlocks(8,5);drawBlocks(7,5);drawBlocks(6,7);drawBlocks(8,7);drawBlocks(7,8);drawBlocks(2,2);drawBlocks(3,3);drawBlocks(4,4);drawBlocks(5,5);drawBlocks(6,6);#if 0findAndCollectMarkers(robot, grid);#elif 0while (!robot.carryingMarker) {if(canMoveForward(robot, grid)){forward(robot, grid);}else{left(robot);}sleep(500);//printf(robot.x %d y %d dir %d\n,robot.x,robot.y,robot.direction);} #elsewhile (!findShortestPath(robot.x,robot.y, grid,visit_first)) {forward(robot, grid);sleep(500); // Adjust sleep duration for animation speed}print_path(MARKER_X,MARKER_Y,false);robot.x MARKER_X;robot.y MARKER_Y;grid[MARKER_X][MARKER_Y] EMPTY;grid[HOME_X][HOME_Y] MARKER;while (!findShortestPath(robot.x,robot.y, grid,visit_second)) {forward(robot, grid);sleep(500); // Adjust sleep duration for animation speed}print_path(HOME_X,HOME_Y,true);#endifreturn 0; }

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/83110.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

建设代练网站简述网站的推广策略

Time Limit: 10 second Memory Limit: 2 MB 问题描述 同一平面内有n(n≤500)条直线,已知其中p(p≥2)条直线相交与同一点,则这n条直线最多能将平面分割成多少个不同的区域? Input 两个整数n&am…

高端型网站建设邯郸wap网站建设报价

假期第二篇,对于基础的知识点,我感觉自己还是很薄弱的。 趁着假期,再去复习一遍 之前已经记录了一篇【vue3基础知识点-computed和watch】 今天在学习的过程中发现,之前记录的这一篇果然是很基础的,很多东西都讲的不够…

可以随意建国际商城的网站吗苏州天狮建设监理有限公司网站

🎥博主:程序员不想YY啊 💫CSDN优质创作者,CSDN实力新星,CSDN博客专家 🤗点赞🎈收藏⭐再看💫养成习惯 ✨希望本文对您有所裨益,如有不足之处,欢迎在评论区提出…

国内论坛网站有哪些网站注册公司

一、导出数据库用mysqldump命令(注意mysql的安装路径,即此命令的路径): 1、导出数据和表结构: mysqldump -u用户名 -p密码 数据库名 > 数据库名.sql #/usr/local/mysql/bin/mysqldump -uroot -p abc > abc.sql 敲…

淄博桓台网站建设公司展示型的网站用

大家好,我是爱编程的喵喵。双985硕士毕业,现担任全栈工程师一职,热衷于将数据思维应用到工作与生活中。从事机器学习以及相关的前后端开发工作。曾在阿里云、科大讯飞、CCF等比赛获得多次Top名次。现为CSDN博客专家、人工智能领域优质创作者。喜欢通过博客创作的方式对所学的…

网站没有ftp 怎么推广会计证初级报考时间2023年报名

C11是由C标准委员会指定的语言规范。相比于C98/03,C11则带来了数量可观的变化,其中包含了约140 个新特性,以及对C03标准中约600个缺陷的修正,C11能更好地用于系统开发和库开发、语法更加泛华和简单化、更加稳定和安全,…

商城网站建设解决方案定西市网站建设企业

Oculus现在已向开发者公布了如何使用自己的设备Camera,本系列课程就来手把手地告诉你如何在Unity中使用这个特性。 第一步,既然用的是Quest的特性,那就需要先引入Quest的Unity开发SDK。并且完成基本的VR开发项目设置。 新建Unity项目后,在编辑器界面先点击Window,打开资…

网站seo关键字优化公众号视频网站怎么做

僵尸动画合集,包括成对攻击/抓取、各种移动方式、爬行、击中反应、死亡动画等。 生产说明 动画总数:99(包括22个位置变化) 配对动画:36 攻击次数:6次 爬网:9 命中反应:6 空转:14 行程2 跑步次数:9次 短跑:2 匝数:3 步行次数:12次 免责声明 任何游戏玩法蓝图都不包…

网站建设市场分析做电力 公司网站

学习需要,总结一些常用优化器。 目录 前言SGD:随机梯度下降BGD:批量梯度下降MBGD:小批量梯度下降MomentumAdaGradRMSpropAdam: Adaptive Moment EstimationAdamW参考文章 前言 优化器的本质是使用不同的策略进行参数更新。常用的…

网站开发设计流程深圳市住建局官网

1、Kafka是何如做到高性能的? a、消息批处理减少网络通信开销,提升系统吞吐能力(先攒一波,消息以“批”为单位进行处理) 生产端:无论是同步发送还是异步发送,Kafka都不会立即就把这条消息发送出…

加强网站建设说明报告范文Wordpress二次开发多少钱

目录 前言 一、问题的出现? 二、一体化架构中的慢请求排查如何做 三、分布式 Trace原理 四、如何来做分布式 Trace 前言 在分布式服务架构下,一个 Web 请求从网关流入,有可能会调用多个服务对请求进行处理,拿到最终结果。这个…

闸北做网站网页代理app

1.随意创建一个类,他都有UCLASS()。GENERATED_BODY()这样的默认的宏。 UCLASS() 告知虚幻引擎生成类的反射数据。类必须派生自UObject. (告诉引擎我是从远古大帝UObject中,继承而来,我们是一家人,只是我进化了其他功能…

有什么软件可以做网站国内室内设计师

Midjourney介绍 Midjourney 是生成式人工智能的一个很好的例子,它根据文本提示创建图像。它与 Dall-E 和 Stable Diffusion 一起成为最流行的 AI 艺术创作工具之一。与竞争对手不同,Midjourney 是自筹资金且闭源的,因此确切了解其幕后内容尚不…

专业网站运营托管网站ui设计例子

你想要实现一个JavaScript函数,用于根据时间段过滤搜索结果吗?可以尝试以下的示例代码: // 假设这是你的数据 const data [{ id: 1, name: Alice, timestamp: 1622382000000 }, // 2021-05-30 12:00:00 UTC{ id: 2, name: Bob, timestamp: …

中国建设银行深圳分行网站网站的投票 计数模块怎么做

UE发起计算服务申请后,网络侧处理的流程 UE发起服务的流程:service request网络侧处理服务涉及的通信数据通过PDU Session进行传输,涉及到SMF与UPF的交互。PDU Session的建立、管理全部由SMF(Session Management Function&#x…

普宁市做网站php 如何在网站根目录创建文件夹

我国有着众多的电商,这些电商为了促进消费总是想出千奇百怪的营销节日,比如年中大促、双十一、双十二、年终大促,在今年更是多出了6.18促销、双十萌节,还有一个慢慢火起来的“黑五”。“黑五”与之前提到的众多营销节日有所不同&a…

网站商城开发一个多少钱阳江做网站seo

主机是sunshine,客机是moonlight,一个太阳一个月光,两者真是太配啦! 下载sunshine sunshine是服务器端,去以下GitHub链接下载windows端的解压缩即用版 https://github.com/LizardByte/Sunshine/releases下载完毕解压…

网站制作宣传成都3d效果图制作公司

linux chown 命令详解 一、更改文件或目录的所有者和/或所属组二、更改用户权限三、chown与chmod的区别 一、更改文件或目录的所有者和/或所属组 它的基本语法如下: chown [选项]... [所有者][:[所属组]] 文件...其中,选项可以是-R(递归更改…

网站推广哪个好wordpress安装插件无法创建目录

本文收录于《Scratch等级认证CCF-GESP图形化真题解析》专栏,专栏总目录:点这里,订阅后可阅读专栏内所有文章。 一、单选题(共 10 题,每题 2 分,共 30 分) 第1题 小杨父母带他到某培训机构给他报名参加 CCF 组织的 GESP 认证考试的第 1 级,那他可以选择的认证语言有几…

新手怎么学习网站建设wordpress 设置版权信息

文章目录 常用图像增强技术调整大小灰度变换标准化随机旋转中心剪切随机裁剪高斯模糊亮度、对比度和饱和度调节水平翻转垂直翻转高斯噪声随机块中心区域 常用图像增强技术 图像增强技术是常用于数据增强的方法,可以帮助增加数据集中图像的多样性,提高深…