很簡單,首先創(chuàng)建一個“人工智能”接口,然后就可以使用其他類實現(xiàn)該接口了2333333
為衛(wèi)輝等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務,及衛(wèi)輝網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務為成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、衛(wèi)輝網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務,秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!
public class Bot {
private ArrayListString commands;
public Bot(){
commands = new ArrayList();
}
public ArrayListString getCommands(){
return commands;
}
public static void main(String[ ] args){
Bot bot = new Bot();
Scanner sc = new Scanner(System.in);
System.out.println("請輸入一個整數(shù):");
int n = sc.nextInt();
int i = 0;
String command;
sc.nextLine();
while (i n){
command = sc.nextLine();
if (!isCorrectCommand(command)){
System.out.println("每條指令只由L、R和數(shù)字組成(數(shù)字是0~100之間的整數(shù))。");
}else if (command.length() 256){
System.out.println("每條指令的長度不超過256個字符。");
} else{
bot.getCommands().add(command);
i++;
}
}
i = 0;
while (i n){
System.out.printf("%.2f",bot.go(i));
i++;
}
}
public double go(int index){
int direction = 2;
double x = 0;
double y = 0;
String command = commands.get(index);
String str="0";
int i = 0;
char temp;
while (i command.length()){
temp = command.charAt(i);
if (temp = 47 temp = 57){
str += temp;
}else if (temp == 'L'){
int length = Integer.parseInt(str);
switch(direction){
case 1: x = x - length;break;
case 2: y = y + length;break;
case 3: x = x + length;break;
case 4: y = y - length;break;
}
str = "0";
direction = (direction - 1)%4;
if (direction == 0){
direction = 4;
}
}else{
int length = Integer.parseInt(str);
switch(direction){
case 1: x = x - length;break;
case 2: y = y + length;break;
case 3: x = x + length;break;
case 4: y = y - length;break;
}
str = "0";
direction = (direction + 1)%4;
}
i++;
}
int length = Integer.parseInt(str);
switch(direction){
case 1: x = x - length;break;
case 2: y = y + length;break;
case 3: x = x + length;break;
case 4: y = y - length;break;
}
return Math.sqrt(x * x + y * y);
}
public static boolean isCorrectCommand(String command){
Pattern pt = Pattern點抗 pile("(?:L\\d{1,3}|R\\d{1,3}|\\d{1,3})+");
if (pt.matcher(command).matches()){
return true;
}
return false;
}
}
根據(jù)機器人的用途與硬件設(shè)計,由編程人員編寫驅(qū)動程序,最簡單的代碼,比如:01010100011110001,0代表關(guān),1代表開,換句話說就是在不懂編程的人看來是一段亂碼,但是對機器來說是一個命令,它告訴機器下一步該做什么,再高級一點的代碼就是,我該怎么做,如果這一步行不通就執(zhí)行另一段命令,亂序指令。
目前的機器人還算不上真正的智能,因為它仍然跟著程序走,而程序還是人寫的,納米技術(shù)的今天,強大硬件的支持,巨大的網(wǎng)絡(luò)流量沖擊下,我認為未來的機器可能產(chǎn)生邏輯思維,只需要基本命令,它們就能自由發(fā)揮,具備學習能力,這是很有可能的。
文章標題:java智能機器人源代碼 java機器人編程
地址分享:http://www.rwnh.cn/article26/ddgoccg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、網(wǎng)站改版、面包屑導航、網(wǎng)站維護、網(wǎng)站制作、電子商務
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)