public class Bot {
創(chuàng)新互聯(lián)主營蒲縣網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,重慶APP開發(fā)公司,蒲縣h5成都小程序開發(fā)搭建,蒲縣網(wǎng)站營銷推廣歡迎蒲縣等地區(qū)企業(yè)咨詢
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.compile("(?:L\\d{1,3}|R\\d{1,3}|\\d{1,3})+");
if (pt.matcher(command).matches()){
return true;
}
return false;
}
}
機(jī)器人類(源類):
public class Robot {
public void cry(){
System.out.println("機(jī)器人叫");
}
public void run(){
System.out.println("機(jī)器人跑");
}
}
狗類(目標(biāo)類):
public class Dog {
public void cry(){
System.out.println("像狗一樣叫");
}
public void run(){
System.out.println("像狗一樣跑");
}
}
適配器類(繼承源類并重寫它的方法,目標(biāo)類作為屬性):
public class Adaper extends Robot{
private Dog dog;
public Adaper(Dog dog) {
this.dog=dog;
}
@Override
public void cry() {
dog.cry();
}
@Override
public void run() {
dog.run();
}
}
測試類
public class Test {
public static void main(String[] args) {
Dog dog=new Dog();
Robot robot=new Adaper(dog);
robot.cry();
robot.run();
}
}
OICQ機(jī)器人轉(zhuǎn)Java:
1. 下載OICQ SDK并安裝:從OICQ官網(wǎng)上下載SDK并安裝到你的電腦上。
2. 創(chuàng)建一個新的Java工程:使用Eclipse或者其他IDE來創(chuàng)建一個新的Java工程。
3. 導(dǎo)入OICQ SDK庫文件:將SDK中的庫文件添加到你的工程中。
4. 生成OICQ機(jī)器人代碼:根據(jù)你想要實現(xiàn)的功能生成相應(yīng)的代碼。
5. 生成可執(zhí)行文件并測試機(jī)器人代碼:將生成的代碼生成可執(zhí)行文件并測試機(jī)器人代碼是否正常工作。
java機(jī)器人游戲最經(jīng)典的是Robocode項目,里面有詳細(xì)的文檔以及源碼,可以自己學(xué)習(xí)修改。(不要說自己參加這個項目,自己不認(rèn)真學(xué)些東西,那可以面壁了)。下面是它的項目主頁
腳本程序就有問題。java腳本機(jī)器人模塊錯誤的原因是腳本程序就有問題,Java是一門面向?qū)ο蟮木幊陶Z言,不僅吸收了C++語言的各種優(yōu)點,還摒棄了C++里難以理解的多繼承、指針等概念,因此Java語言具有功能強大和簡單易用兩個特征。
本文標(biāo)題:java代碼機(jī)器人 java人工智能代碼
當(dāng)前鏈接:http://m.kartarina.com/article24/dodssce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、域名注冊、電子商務(wù)、外貿(mào)網(wǎng)站建設(shè)、虛擬主機(jī)、自適應(yī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)