|
|
@ -1,13 +1,17 @@ |
|
|
|
package com.kob.botRunningSystem.Service.impl.utils; |
|
|
|
package com.kob.botRunningSystem.Service.impl.utils; |
|
|
|
|
|
|
|
|
|
|
|
import com.kob.botRunningSystem.utils.BotInterface; |
|
|
|
|
|
|
|
import org.joor.Reflect; |
|
|
|
import org.joor.Reflect; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.util.LinkedMultiValueMap; |
|
|
|
import org.springframework.util.LinkedMultiValueMap; |
|
|
|
import org.springframework.util.MultiValueMap; |
|
|
|
import org.springframework.util.MultiValueMap; |
|
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
|
|
|
import java.io.FileNotFoundException; |
|
|
|
|
|
|
|
import java.io.PrintWriter; |
|
|
|
import java.util.UUID; |
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
import java.util.function.Supplier; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Component |
|
|
|
@Component |
|
|
@ -17,7 +21,7 @@ public class Consumer extends Thread{ |
|
|
|
|
|
|
|
|
|
|
|
private static RestTemplate restTemplate; |
|
|
|
private static RestTemplate restTemplate; |
|
|
|
|
|
|
|
|
|
|
|
private static final String receiveBotMoveUrl = "http://127.0.0.1:3000/pk/receive/bot/move/"; |
|
|
|
private static final String receiveBotMoveUrl = "http://127.0.0.1:4000/pk/receive/bot/move/"; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private void setRestTemplate(RestTemplate restTemplate) { |
|
|
|
private void setRestTemplate(RestTemplate restTemplate) { |
|
|
@ -37,7 +41,7 @@ public class Consumer extends Thread{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String addUid(String code,String uid) { // 在Code的bot类名后添加uid
|
|
|
|
private String addUid(String code,String uid) { // 在Code的bot类名后添加uid
|
|
|
|
int k = code.indexOf(" implements com.kob.botRunningSystem.utils.BotInterface"); |
|
|
|
int k = code.indexOf(" implements java.util.function.Supplier<Integer>"); |
|
|
|
return code.substring(0,k) + uid + code.substring(k); |
|
|
|
return code.substring(0,k) + uid + code.substring(k); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
@ -49,10 +53,19 @@ public class Consumer extends Thread{ |
|
|
|
UUID uuid = UUID.randomUUID(); |
|
|
|
UUID uuid = UUID.randomUUID(); |
|
|
|
String uid = uuid.toString().substring(0,8); // 获取8位随机字符串
|
|
|
|
String uid = uuid.toString().substring(0,8); // 获取8位随机字符串
|
|
|
|
|
|
|
|
|
|
|
|
BotInterface botInterface = Reflect.compile( |
|
|
|
Supplier<Integer> botInterface = Reflect.compile( |
|
|
|
"com.kob.botRunningSystem.utils.Bot" + uid, |
|
|
|
"com.kob.botRunningSystem.utils.Bot" + uid, |
|
|
|
addUid(bot.getBotCode(),uid)).create().get(); |
|
|
|
addUid(bot.getBotCode(),uid)).create().get(); |
|
|
|
Integer direction = botInterface.nextMove(bot.getInput()); |
|
|
|
File file = new File("input.txt"); |
|
|
|
|
|
|
|
try (PrintWriter fout = new PrintWriter(file)){ |
|
|
|
|
|
|
|
fout.println(bot.getInput()); |
|
|
|
|
|
|
|
fout.flush(); |
|
|
|
|
|
|
|
} catch (FileNotFoundException e) { |
|
|
|
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Integer direction = botInterface.get(); |
|
|
|
System.out.println("move-direction: " + bot.getUserId() + " " + direction); |
|
|
|
System.out.println("move-direction: " + bot.getUserId() + " " + direction); |
|
|
|
|
|
|
|
|
|
|
|
MultiValueMap<String,String> data = new LinkedMultiValueMap<>(); |
|
|
|
MultiValueMap<String,String> data = new LinkedMultiValueMap<>(); |
|
|
|