好的,下面是使用 C 语言写的一个使小人在一个 16x16 的迷宫里做随机运动的程序。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MAZE_SIZE 16
int main() {
// 定义迷宫和小人的位置
int maze[MAZE_SIZE][MAZE_SIZE] = {0};
int x = 0, y = 0;
// 设置随机数种子
srand(time(NULL));
// 循环做随机运动
while (1) {
// 随机生成一个运动方向