写道
package qlcoder.robot2;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Room {
private int level;
private int x;
private int y;
private boolean[] map;
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public boolean[] getMap() {
return map;
}
public void setMap(boolean[] map) {
this.map = map;
}
public Room(){
String str = getJsonString();
//String str = "level=1x=3y=3map=100000001";
this.level = Integer.valueOf(getMatcherNumber("level=",str));
this.x = Integer.valueOf(getMatcherNumber("x=",str));
this.y = Integer.valueOf(getMatcherNumber("y=",str));
char[] mapChars = getMatcherNumber("map=",str).toCharArray();
this.map = new boolean[x * y];
for(int i=0;i<y;i++){
for(int j=0;j<x;j++){
int index = i * x + j;
map[index] = (mapChars[index] == '1');
}
}
}
private String getJsonString(){
StringBuilder sb = new StringBuilder();
File file = new File(new File("").getAbsolutePath() + "\\file\\rbot.txt");
Reader reader;
BufferedReader br;
try {
reader = new FileReader(file);
br = new BufferedReader(reader);
String result = null;
while((result = br.readLine())!=null){
sb.append(result);
}
reader.close();
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
return sb.toString().trim();
}
private String getMatcherNumber(String patternStr,String str){
String value = null;
Pattern pattern = Pattern.compile(patternStr + "(\\d+)");
Matcher matcher = pattern.matcher(str);
if(matcher.find()){
value = matcher.group(0);
value = value.substring(patternStr.length());
}
return value;
}
public void show(){
System.out.println("level = " + level + ",x= " + x + ",y= " + y + ",map:");
for(int i=0;i<x;i++){
for(int j=0;j<y;j++){
String str = map[i * x + j]?"1":"0";
System.out.print( str + " ");
}
System.out.println();
}
}
}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Room {
private int level;
private int x;
private int y;
private boolean[] map;
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public boolean[] getMap() {
return map;
}
public void setMap(boolean[] map) {
this.map = map;
}
public Room(){
String str = getJsonString();
//String str = "level=1x=3y=3map=100000001";
this.level = Integer.valueOf(getMatcherNumber("level=",str));
this.x = Integer.valueOf(getMatcherNumber("x=",str));
this.y = Integer.valueOf(getMatcherNumber("y=",str));
char[] mapChars = getMatcherNumber("map=",str).toCharArray();
this.map = new boolean[x * y];
for(int i=0;i<y;i++){
for(int j=0;j<x;j++){
int index = i * x + j;
map[index] = (mapChars[index] == '1');
}
}
}
private String getJsonString(){
StringBuilder sb = new StringBuilder();
File file = new File(new File("").getAbsolutePath() + "\\file\\rbot.txt");
Reader reader;
BufferedReader br;
try {
reader = new FileReader(file);
br = new BufferedReader(reader);
String result = null;
while((result = br.readLine())!=null){
sb.append(result);
}
reader.close();
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
return sb.toString().trim();
}
private String getMatcherNumber(String patternStr,String str){
String value = null;
Pattern pattern = Pattern.compile(patternStr + "(\\d+)");
Matcher matcher = pattern.matcher(str);
if(matcher.find()){
value = matcher.group(0);
value = value.substring(patternStr.length());
}
return value;
}
public void show(){
System.out.println("level = " + level + ",x= " + x + ",y= " + y + ",map:");
for(int i=0;i<x;i++){
for(int j=0;j<y;j++){
String str = map[i * x + j]?"1":"0";
System.out.print( str + " ");
}
System.out.println();
}
}
}
写道
package qlcoder.robot2;
public class Robot {
private boolean[] map;
private int Max_width = 0;
private int Max_higth = 0;
private int old_width = 0;
private int old_higth = 0;
public void setRoom(Room room){
this.map = room.getMap();
this.Max_width = room.getX();
this.Max_higth = room.getY();
}
public boolean getRoute(int higth,int width){
this.old_higth = higth;
this.old_width = width;
boolean[] mapper = map.clone();
mapper[higth * Max_width + width] = true;
return nextRout(higth,width,mapper,"");
}
public boolean nextRout(int higth,int width,boolean[] mapper, String sb){
if(complete(mapper)){
System.out.println("start point:[x = " + (1+old_width) + ",y=" + (1+old_higth) + "]. route = " + sb.toLowerCase());
return true;
}
if(doLeft(higth,width,mapper,sb)){
return true;
}
if(doRight(higth,width,mapper,sb)){
return true;
}
if(doUp(higth,width,mapper,sb)){
return true;
}
if(doDown(higth,width,mapper,sb)){
return true;
}
return false;
}
private boolean complete(boolean[] mapper){
for(int i=0;i<mapper.length;i++){
if(!mapper[i]){
return false;
}
}
return true;
}
public boolean doLeft(int higth,int width,boolean[] mapper, String sb){
int index = higth * Max_width + width;
if(width == 0 || mapper[index-1]){
return false;
}
sb = sb + "L";
while(width > 0 && !mapper[index-1]){
width = width -1;
index = index -1;
mapper[higth * Max_width + width] = true;
}
return nextRout(higth,width,mapper.clone(),sb);
}
public boolean doRight(int higth,int width,boolean[] mapper, String sb){
int index = higth * Max_width + width;
if(width == Max_width -1 || mapper[index+1]){
return false;
}
sb = sb + "R";
while(width < Max_width - 1 && !mapper[index+1]){
width = width + 1;
index = index + 1;
mapper[higth * Max_width + width] = true;
}
return nextRout(higth,width,mapper.clone(),sb);
}
public boolean doUp(int higth,int width,boolean[] mapper, String sb){
int index = higth * Max_width + width;
if(higth == 0 || mapper[index - Max_width]){
return false;
}
sb = sb + "U";
while(higth > 0 && !mapper[index - Max_width]){
higth = higth - 1;
index = index - Max_width;
mapper[higth * Max_width + width] = true;
}
return nextRout(higth,width,mapper.clone(), sb);
}
public boolean doDown(int higth,int width,boolean[] mapper, String sb){
int index = higth * Max_width + width;
if(higth == Max_higth -1 || mapper[index + Max_width]){
return false;
}
sb = sb + "D";
while(higth < Max_higth -1 && !mapper[index + Max_width]){
higth = higth + 1;
index = index + Max_width;
mapper[higth * Max_width + width] = true;
}
return nextRout(higth,width,mapper.clone(), sb);
}
public void show(boolean[] map){
System.out.println("map:");
for(int i=0;i<Max_higth;i++){
for(int j=0;j<Max_width;j++){
String str = map[i * Max_width + j]?"1":"0";
System.out.print( str + " ");
}
System.out.println();
}
}
}
public class Robot {
private boolean[] map;
private int Max_width = 0;
private int Max_higth = 0;
private int old_width = 0;
private int old_higth = 0;
public void setRoom(Room room){
this.map = room.getMap();
this.Max_width = room.getX();
this.Max_higth = room.getY();
}
public boolean getRoute(int higth,int width){
this.old_higth = higth;
this.old_width = width;
boolean[] mapper = map.clone();
mapper[higth * Max_width + width] = true;
return nextRout(higth,width,mapper,"");
}
public boolean nextRout(int higth,int width,boolean[] mapper, String sb){
if(complete(mapper)){
System.out.println("start point:[x = " + (1+old_width) + ",y=" + (1+old_higth) + "]. route = " + sb.toLowerCase());
return true;
}
if(doLeft(higth,width,mapper,sb)){
return true;
}
if(doRight(higth,width,mapper,sb)){
return true;
}
if(doUp(higth,width,mapper,sb)){
return true;
}
if(doDown(higth,width,mapper,sb)){
return true;
}
return false;
}
private boolean complete(boolean[] mapper){
for(int i=0;i<mapper.length;i++){
if(!mapper[i]){
return false;
}
}
return true;
}
public boolean doLeft(int higth,int width,boolean[] mapper, String sb){
int index = higth * Max_width + width;
if(width == 0 || mapper[index-1]){
return false;
}
sb = sb + "L";
while(width > 0 && !mapper[index-1]){
width = width -1;
index = index -1;
mapper[higth * Max_width + width] = true;
}
return nextRout(higth,width,mapper.clone(),sb);
}
public boolean doRight(int higth,int width,boolean[] mapper, String sb){
int index = higth * Max_width + width;
if(width == Max_width -1 || mapper[index+1]){
return false;
}
sb = sb + "R";
while(width < Max_width - 1 && !mapper[index+1]){
width = width + 1;
index = index + 1;
mapper[higth * Max_width + width] = true;
}
return nextRout(higth,width,mapper.clone(),sb);
}
public boolean doUp(int higth,int width,boolean[] mapper, String sb){
int index = higth * Max_width + width;
if(higth == 0 || mapper[index - Max_width]){
return false;
}
sb = sb + "U";
while(higth > 0 && !mapper[index - Max_width]){
higth = higth - 1;
index = index - Max_width;
mapper[higth * Max_width + width] = true;
}
return nextRout(higth,width,mapper.clone(), sb);
}
public boolean doDown(int higth,int width,boolean[] mapper, String sb){
int index = higth * Max_width + width;
if(higth == Max_higth -1 || mapper[index + Max_width]){
return false;
}
sb = sb + "D";
while(higth < Max_higth -1 && !mapper[index + Max_width]){
higth = higth + 1;
index = index + Max_width;
mapper[higth * Max_width + width] = true;
}
return nextRout(higth,width,mapper.clone(), sb);
}
public void show(boolean[] map){
System.out.println("map:");
for(int i=0;i<Max_higth;i++){
for(int j=0;j<Max_width;j++){
String str = map[i * Max_width + j]?"1":"0";
System.out.print( str + " ");
}
System.out.println();
}
}
}
写道
package qlcoder.robot2;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class IRobotScooba {
public void doAction(){
Room room = new Room();
room.show();
ExecutorService service = Executors.newFixedThreadPool(room.getY());
for(int i=0;i<room.getY();i++){
service.submit(new Task(i,room));
}
service.shutdown();
}
public class Task implements Runnable{
private int taskId;
private Room room;
public Task(int id,Room room){
this.taskId = id;
this.room = room;
}
public void run() {
for(int j=0;j<room.getX();j++){
if(!room.getMap()[taskId * room.getX() + j]){
Robot robot = new Robot();
robot.setRoom(room);
if(robot.getRoute(taskId,j)){
}
}
}
System.out.println("任务"+ taskId +"已成!");
}
}
public static void main(String[] args) {
IRobotScooba test = new IRobotScooba();
test.doAction();
}
}
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class IRobotScooba {
public void doAction(){
Room room = new Room();
room.show();
ExecutorService service = Executors.newFixedThreadPool(room.getY());
for(int i=0;i<room.getY();i++){
service.submit(new Task(i,room));
}
service.shutdown();
}
public class Task implements Runnable{
private int taskId;
private Room room;
public Task(int id,Room room){
this.taskId = id;
this.room = room;
}
public void run() {
for(int j=0;j<room.getX();j++){
if(!room.getMap()[taskId * room.getX() + j]){
Robot robot = new Robot();
robot.setRoom(room);
if(robot.getRoute(taskId,j)){
}
}
}
System.out.println("任务"+ taskId +"已成!");
}
}
public static void main(String[] args) {
IRobotScooba test = new IRobotScooba();
test.doAction();
}
}
相关推荐
"扫地机器人设计制作课程设计" 扫地机器人设计制作是机器人技术和自动化领域中的一个重要方向,本课程设计报告将对扫地机器人的设计和制作进行详细的介绍和分析。 第一章 绪论 扫地机器人是一种自动化的家用...
学号:914104220137 姓名: 赵振 指导老师: 任明武 智能扫地机器人 智能扫地机器人全文共12页,当前为第1页。 摘要: 智能扫地机器人,又名智能扫地机,智能吸尘器,是智能家用电器的一种。 可通过预约定时清洁,...
《小米扫地机器人工程源码解析——基于STM32与FreeRTOS》 小米扫地机器人作为智能家居的一员,其内部蕴含了丰富的嵌入式系统技术。本篇将深度探讨这款产品背后的工程源码,主要涉及STM32微控制器以及FreeRTOS实时...
毕业设计基于51单片机扫地机器人设计与实现(源码+PCB+仿真).zip毕业设计基于51单片机扫地机器人设计与实现(源码+PCB+仿真).zip毕业设计基于51单片机扫地机器人设计与实现(源码+PCB+仿真).zip毕业设计基于51...
【扫地机器人仿真实验C++】项目是一个深入探索机器人技术与编程的实践平台,它结合了Matlab和Visual Studio(VS)两个强大的工具,并利用C++和C这两种高效的编程语言进行开发。该项目的主要目标是设计一个能够在虚拟...
扫地机器人的设计方案涉及到多个方面的技术知识,包括机器人设计、自动化控制、传感器技术、人工智能以及电子工程等。以下是对这些知识点的详细说明: 1. **机器人设计**:扫地机器人是一种融合了工程力学、机械...
本论文自主研发了一套智能扫地机器人模型机,并研究了智能扫地机器人的定位导航技术,提出了一套基于传感器探测生成栅格地图的智能扫地机器人全覆盖路径规划算法。经过研究现有智能扫地机器人的技术指标和功能特点,...
扫地机器人的源码是开发智能清洁设备的关键组成部分,它包含了一系列控制机器人行为、路径规划、传感器处理和决策制定的程序。在这个特定的压缩包中,我们有一个名为"综合例程一:扫地机器人"的文件,这通常代表一个...
智能扫地机器人是一种结合了人工智能、传感器技术和自动化控制的设备,它能自主规划路径,进行清洁工作。在本项目中,我们重点讨论的是基于Matlab和Visual Studio平台,使用C++和C语言编写的仿真代码。这样的组合...
根据给定文件信息,将介绍STM32在智能扫地机器人避障系统设计中的应用以及相关知识点。 知识点1:STM32单片机 STM32是由ST-Microelectronics(意法半导体)推出的一系列32位ARM Cortex-M微控制器产品线。STM32微...
STM32扫地机器人开源资料分享。STM32扫地机器人开源资料分享。STM32扫地机器人开源资料分享。STM32扫地机器人开源资料分享。STM32扫地机器人开源资料分享。STM32扫地机器人开源资料分享。STM32扫地机器人开源资料...
扫地机器人基本功能实现,内部各个模块驱动完成,能按照正常的弓字行路劲行走
在IT领域,路径规划是机器人学中的一个关键问题,特别是在智能扫地机器人设计中。本文将深入探讨基于C++的智能扫地机器人路径选择算法,旨在帮助开发者理解并实现高效、可靠的路径规划策略。 首先,我们需要理解...
【扫地机器人路径规划1】涉及的知识点主要集中在路径规划算法和人工智能的应用上。路径规划是扫地机器人的重要组成部分,其目标是在满足清扫房间全区域覆盖的前提下,使机器人移动的行进总路径最短,从而提高扫地...
本项目“基于STM32单片机的扫地机器人”深入探讨了如何利用这种微控制器构建一个功能完善的自动清扫设备。STM32F103VC型号是STM32系列中的一个变种,具有高性能、低功耗的特点,适用于此类智能系统。 首先,项目的...
在现代智能家居系统中,扫地机器人的应用越来越普及,它们能够自动完成地面的清扫工作,减少人们的家务劳动。本文将详细探讨基于单片机的扫地机器人的设计与实现过程,重点关注硬件组成、避障原理以及模块电路设计等...
其中,本体是智能扫地机器人的主体部分,充电电池是智能扫地机器人的能源来源,充电座是智能扫地机器人充电的地方,集尘盒是智能扫地机器人吸尘的关键部分,遥控器是控制智能扫地机器人的主要工具。 组成结构: ...
标题所提及的知识点为“基于STC89C52单片机的智能扫地机器人设计”,而描述部分重申了这一主题。根据给出的内容,以下是详细的知识点: 1. 单片机STC89C52的应用:在设计中,STC89C52单片机作为智能扫地机器人的...