When I run the engine and my code, initially everything starts up fine. But when it comes to executing actions the graphical window and the console shows no change in the players position.
Here is my code:
import Enums.InputCommand;
import Models.*;
import Models.Dtos.*;
import Services.*;
import com.microsoft.signalr.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Logger logger = LoggerFactory.getLogger(Main.class);
BotService botService = new BotService();
String environmentIp = System.getenv("RUNNER_IPV4");
String environmentNickname = System.getenv("BOT_NICKNAME");
String token = "410d392c-ecf5-43b9-a228-299c0a8d224a";
token = (token != null) ? token : System.getenv("REGISTRATION_TOKEN");
String ip = (environmentIp != null && !environmentIp.isBlank()) ? environmentIp : "localhost";
ip = ip.startsWith("http://") ? ip : "http://" + ip;
String url = ip + ":" + "5000" + "/runnerhub";
// create the connection
HubConnection hubConnection = HubConnectionBuilder.create(url)
.build();
String nickname = environmentNickname != null ? environmentNickname : "JavaBot";
hubConnection.on("Disconnect", (reason) -> {
logger.info("Disconnected: {}",
reason);
botService.setShouldQuit(true);
hubConnection.stop();
}, UUID.class);
hubConnection.on("Registered", (id) -> {
System.out.println("Registered with the runner, bot ID is: " + id);
botService.setBotId(id);
}, UUID.class);
hubConnection.on("ReceiveBotState", (botStateDto) -> {
botService.setReceivedBotState(true);
botService.setBotState(botStateDto);
}, BotStateDto.class);
hubConnection.start().blockingAwait();
Thread.sleep(1000);
System.out.println("Registering with the runner...");
hubConnection.send("Register", token, nickname);
hubConnection.on("ReceiveGameComplete", (state) -> {
System.out.println("Game complete");
botService.setShouldQuit(true);
}, String.class);
GraphicalMap graphicalMap = new GraphicalMap();
graphicalMap.showMap();
// This is a blocking call
// hubConnection.start().subscribe(()-> {
//
//
// });
while (!botService.getShouldQuit()) {
Thread.sleep(20);
if (botService.getReceivedBotState()) {
//System.out.println(botService.getBotState().toString());
int action = graphicalMap.updateMap(botService
.getBotState().getHeroWindow());
int playerX = Math.floorDiv(graphicalMap.COLS, 2);
int playerY = Math.floorDiv(graphicalMap.ROWS, 2);
//graphicalMap.setPlayerLocation(playerX, playerY);
System.out.println(playerX);
if (!graphicalMap.isShowing){
graphicalMap.showMap();
}
BotCommand botCommand = botService.computeNextPlayerAction();
hubConnection.send("SendPlayerCommand", new BotCommand(
botService.getBotId(), InputCommand.valueOf(new Random().nextInt(9) + 1).get()
));
System.out.println(
new BotCommand(
botService.getBotId(), InputCommand.valueOf(new Random().nextInt(9) + 1).get()
).toString()
);
botService.setReceivedBotState(false);
}
}
hubConnection.stop();
}
public static String convertToString(int[][] array) {
String map = "";
for (int[] row : array) {
for (int k : row){
map = map + k;
}
}
return map;
}
}
I even unzipped a new engine and used the start bot code. Still the same issue. I got the output as follows:
Registering with the runner...
Registered with the runner, bot ID is: 410d392c-ecf5-43b9-a228-299c0a8d224a
Position: (23, 20), Level: 0, Collected: 1
1111100111111111111000000050000000
1111111111111111111000000050000000
1111111111111111111000000050000000
1111111111111111111000000050000000
1111111111111111111000000050000000
1111111110000000000000000050000000
1111111110000000000000000050200020
1111111110000000000000000050000000
1111111100000000000000000055444434
1111111100000000000000000055000000
1111111100000000000002000255000000
1111111110000000000000000055000000
1111111100000000444444444455000000
1111111100000000000000000000000000
1111111110000000000000000000000000
1111111110000000000000000000000000
1111111110000000000000000000000000
1111111110000000000000000000000000
1111111110000000000000000000000000
1111111110000000000000000000000000
1111111111000000000000000000000000
1111111111100001111111111111111111
Position: (23, 20), Level: 0, Collected: 1
1111100111111111111000000050000000
1111111111111111111000000050000000
1111111111111111111000000050000000
1111111111111111111000000050000000
1111111111111111111000000050000000
1111111110000000000000000050000000
1111111110000000000000000050200020
1111111110000000000000000050000000
1111111100000000000000000055444434
1111111100000000000000000055000000
1111111100000000000002000255000000
1111111110000000000000000055000000
1111111100000000444444444455000000
1111111100000000000000000000000000
1111111110000000000000000000000000
1111111110000000000000000000000000
1111111110000000000000000000000000
1111111110000000000000000000000000
1111111110000000000000000000000000
1111111110000000000000000000000000
1111111111000000000000000000000000
1111111111100001111111111111111111