- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我正在创建一个程序来驱动机器人到迷宫的右上角。迷宫的一个例子是:
这是我的代码:
#include "simpletools.h"
#include "abdrive.h"
#include "ping.h"
int whichCase = 0;
//int caseArray[] = {0,1,2,3};
int irLeft, irRight;
void turnRight () {
drive_goto(26, -25);
drive_goto(125,125);
whichCase = (whichCase + 1) % 4;
}
void turnLeft () {
whichCase = (whichCase - 1) % 4;
drive_goto(-25,26);
drive_goto(125,125);
}
void forward () {
drive_goto(125,125);
}
void backward(){
drive_goto(26, -25);
drive_goto(26, -25);
whichCase = (whichCase + 2) % 4;
}
void priority(int whichCase) {
switch (whichCase) {
case (0):
/* (1) go right */ if (irRight == 1) { turnRight(); }
/* (2) go forward */ else if (ping_cm(8) > 30) { forward(); }
/* (3) go left */ else if (irLeft == 1) { turnLeft(); }
/* (4) go backward */ else if (irRight == 0 && irLeft == 0 && ping_cm(8) < 30){ backward();}
break;
case (1):
/* (1) go forward */ if (ping_cm(8) > 30) { forward(); }
/* (2) go left */ else if (irLeft == 1) { turnLeft(); }
/* (3) go backward */else if (irRight == 0 && irLeft == 0 && ping_cm(8) < 30){ backward();}
/* (4) go right */ else if (irRight == 1) { turnRight(); }
break;
case (2):
/* (1) go left */ if (irLeft == 1) { turnLeft(); }
/* (2) go backward */ else if (irRight == 0 && irLeft == 0 && ping_cm(8) < 30){ backward();}
/* (3) go right */ else if (irRight == 1) { turnRight(); }
/* (4) go forward */ else if (ping_cm(8) > 30) { forward(); }
break;
case (3):
/* (1) go backward */ if (irRight == 0 && irLeft == 0 && ping_cm(8) < 30){ backward();}
/* (2) go right */ else if (irRight == 1) { turnRight(); }
/* (3) go forward */ else if (ping_cm(8) > 30) { forward(); }
/* (4) go left */ else if (irLeft == 1) { turnLeft(); }
break;
}
}
void main () {
drive_goto(145,145);
low(26); // D/A0 & D/A1 to 0 V
low(27);
drive_setRampStep(12);
freqout(11, 1, 38000); // Check left & right objects
irLeft = input(10);
freqout(1, 1, 38000);
irRight = input(2);
while(1) {
priority(whichCase);
}
}
所以在这段代码中我基本上做了 4 种情况来代表机器人的不同位置:面朝上、面朝右、面朝下和左。根据不同的位置,机器人会以不同的方式使用传感器。代码的思路是这样的:
我认为逻辑非常简单并且应该可行。但事实并非如此。
请帮忙:(
最佳答案
正如 B. Wolf 所建议的,您需要在 while 循环中更新 irLeft 和 irRight。此外,你的看起来像一个墙壁跟随器,它只会跟随墙壁(无休止地)。您需要在代码中添加一个结束条件,因为您需要跟踪当前处于迷宫的哪个方 block 。由于迷宫是 4x4,因此您会准确地知道何时停止以这种方式
我会提醒你,在第一阶段你需要访问所有其他 3 个角落,所以仅仅到达对面的角落是行不通的。是的,我是你的同学之一,你最好询问完成作业的同学,除了来自 stack Overflow 的人,他们不知道类(class)的全部内容:)
关于c - 事件机器人 : Going to the corner on the upper right side in a maze,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42965364/
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 5年前关闭。 Improve this questi
我正在尝试创建一个程序,该程序将遍历一个随机生成的迷宫,其中 1 是开放的,0 是墙壁。从左上角开始,到右下角结束。该路径可以向上、向下、向左、向右。 目前,我的程序为我提供了一种解决方案,但我无法让
这个小程序应该打印出迷宫中所有可能的路线,入口/起点总是从左上角向下一个,所有可能的导出总是在右墙上。它从文本文件中检索迷宫。 迷宫其实就是一堆文字。迷宫由 n x n 网格组成,由作为墙壁的“#”符
解迷宫的可能方法有哪些? 我有两个想法,但我认为它们不是很优雅。 基本情况:我们有一个矩阵,这个矩阵中的元素以一种表示迷宫的方式排序,有一条进路和一条出路。 我的第一个想法是让机器人沿着迷宫的一侧穿过
首先让我为尺寸道歉我会尽量保持它尽可能小 在尝试完全按照维基百科上所说的那样构建 prim 的算法后,我发现它无法按照我构建的迷宫方式运行。所以我尝试做同样的想法来适应我的迷宫,但我看到了一个奇怪的错
所以我的任务是创建一个迷宫解算器,其中包含一个队列、一个集合、一个位置对象和最终形成一个迷宫对象的单元格对象。 快速浏览一下我完成后所有代码的基本功能: 7 10 _ _ _ _ _ _ _ _
题目地址:https://leetcode-cn.com/problems/the-maze-ii/ 题目描述 There is a ball in a maze with empty space
我的问题本质上是对递归的怀疑。我正在解决经典的“迷宫中的老鼠”DFS 遍历问题。我的输入是一个 n*n int 数组 a[][],其中索引 i 和 j,a[i][j] 可以是 0 或 1。 0 表示假
我正在尝试为一个迷宫创建一个 BFS,该迷宫将在到达某个点时停止。在测试它时,我遇到了段错误(核心转储)错误。我正在尝试修改我在此 site 上找到的代码.我正在尝试做的事情与该站点中的代码之间的主要
我正在编写代码以读取代表“迷宫”的文件中的 7x15 文本 block 。 #include #include #include #include "board.h" int main() {
我正在开发一个合作伙伴项目,我的合作伙伴为游戏创建一个解算器类,而我的部分是创建 MazeGUI。 当您单击 Solve JButton 时,它应该突出显示它在 GUI 本身上所采取的路径,但它只突出
这个问题已经有答案了: What is a NullPointerException, and how do I fix it? (12 个回答) 已关闭 7 年前。 我正在尝试使用 DisjSet
我一直在研究代码 war ,并且遇到了 mazerunner (https://www.codewars.com/kata/maze-runner/train/javascript),我已经被难住了大
我的目标是生成一个由 Cell 对象的二维数组组成的迷宫。下面是单元格和迷宫的代码。使用调试器我可以看到 boolean 值正在改变,并且生成按预期进行,但是当它得到打印时,没有路径。所有的墙都还在原
运行时检查失败 #2 变量“迷宫”周围的堆栈已损坏。每当我编译并运行我的程序时,只要程序完成运行,我就会收到此错误。我相信问题出在我的实现中的 addPaths 函数中。为了以防万一,我发布了所有代码
所以我在学习 C++ 的同时正在做学校作业。我不是在寻找给我的代码,而是在帮助理解/提出解决这个问题的正确算法。 我需要创建一个由 1 和 0 组成的 (5x5x5) 3d 迷宫。随机填充它(除了 0
我想创建一个带有迷宫(不是真的)的游戏。整个 map 应该被墙包围,而在这些墙内应该有一个迷宫。这个迷宫应该是随机创建的。在没有放置墙的每一 block 瓷砖上,玩家应该随机放置。 SpriteKit
我最近出现在一个工作面试中,我被问到一个流行的 RAT IN A MAZE 问题,其中有一个由二维数组表示的迷宫,其中分别包含 0 和 1 表示开放路径和墙壁,我们必须打印最短的路径。 我使用回溯法解
我最近一直在尝试在 Haskell 中创建一个迷宫求解器,并且我已经设法拼凑出一个大部分可用的算法。但是,我不知道如何确定给定的迷宫是否无法解决。 solveMazeQuickly :: Maze -
我尝试随机生成一个迷宫,但在编译下面的程序时出现段错误 这是代码 void spread(int v, int x, int y, int *t,int w, int *count){ //t
我是一名优秀的程序员,十分优秀!