Remove the ai-service

This commit is contained in:
Andrew Guibert 2019-10-03 16:56:56 -05:00
parent 241585b80e
commit 1dcef76321
9 changed files with 0 additions and 285 deletions

View File

@ -1,4 +0,0 @@
build/
!build/libs/
src/
!src/main/liberty/config/

View File

@ -1,20 +0,0 @@
ext {
httpPort = 8083
httpsPort = 8275
appUrl = "http://${hostname}:${httpPort}/ai"
}
liberty {
server {
name = "ai-service"
dropins = [war]
configDirectory = file('src/main/liberty/config')
// TODO: make configurable
jvmOptions = ['-Dorg.libertybikes.ai.restclient.GameServiceClient/mp-rest/url=http://localhost:8080']
bootstrapProperties = ['httpPort': httpPort, 'httpsPort': httpsPort]
}
}
// The installLiberty task doesn't work when run in parallel with other installLiberty tasks
installLiberty.mustRunAfter ':frontend:installLiberty'

View File

@ -1,50 +0,0 @@
/**
*
*/
package org.libertybikes.ai;
import org.libertybikes.ai.service.AIWebSocket;
import org.libertybikes.ai.service.AIWebSocket.DIRECTION;
public class AIClass {
int startX, startY;
AIWebSocket socket;
public AIClass(AIWebSocket socket, int x, int y) {
this.socket = socket;
startX = x;
startY = y;
}
int count = 0;
/*
* This should contain the main logic of the AI, it receives a JSON of all the
* objects on the board
* TODO: describe possible values in json
*/
public void processAiMove(String message) {
count++;
int mod = count % 4;
switch (mod) {
case 0:
socket.sendDirection(DIRECTION.RIGHT);
break;
case 1:
socket.sendDirection(DIRECTION.DOWN);
break;
case 2:
socket.sendDirection(DIRECTION.LEFT);
break;
default:
socket.sendDirection(DIRECTION.UP);
break;
}
if (count > 100) {
count = 0;
}
}
}

View File

@ -1,38 +0,0 @@
/**
*
*/
package org.libertybikes.ai.restclient;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
@RegisterRestClient
@Path("/")
public interface GameServiceClient {
@GET
@Path("/round/available")
@Produces(MediaType.TEXT_HTML)
public String getAvailableRounds();
@GET
@Path("/round/join/{roundId}")
@Produces(MediaType.TEXT_HTML)
public String joinRound(@PathParam("roundId") String id);
@GET
@Path("/round/ws/{roundId}")
@Produces(MediaType.TEXT_HTML)
public String joinSession(@PathParam("roundId") String id);
@GET
@Path("/party/{partyId}/round")
@Produces(MediaType.APPLICATION_JSON)
public String getRoundId(@PathParam("partyId") String partyId);
}

View File

@ -1,50 +0,0 @@
/**
*
*/
package org.libertybikes.ai.service;
import java.net.URL;
import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import org.eclipse.microprofile.rest.client.RestClientBuilder;
import org.libertybikes.ai.restclient.GameServiceClient;
@ApplicationScoped
@Path("open")
public class AIRoundService {
// TODO - url prop not working
// @Inject
// @RestClient
// GameServiceClient client;
private GameServiceClient getClient() {
try {
return RestClientBuilder.newBuilder().baseUrl(new URL("http://localhost:8080")).build(GameServiceClient.class);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@GET
@Path("/join/{partyId}")
public String joinSession(@PathParam("partyId") String partyId) {
System.out.println("Trying to join " + partyId + " party.");
// get party's current round
String roundId = getClient().getRoundId(partyId);
System.out.println("got current round for party: " + roundId);
// open a websocket and join it.
AIWebSocket socket = new AIWebSocket(roundId);
return "successful?";
}
}

View File

@ -1,10 +0,0 @@
/**
*
*/
package org.libertybikes.ai.service;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("/")
public class AIServiceApp extends Application {}

View File

@ -1,99 +0,0 @@
/**
*
*/
package org.libertybikes.ai.service;
import java.io.IOException;
import java.net.URI;
import javax.websocket.ClientEndpoint;
import javax.websocket.ContainerProvider;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
import org.libertybikes.ai.AIClass;
// how to join a game currently: http://localhost:8083/ai-service/open/join/{partyID}
@ClientEndpoint
public class AIWebSocket {
// TODO: obviously shouldn't be hard coded
private static String uri = "ws://localhost:8080" + "/round/ws/";
public Session session;
public enum DIRECTION {
UP, DOWN, LEFT, RIGHT
};
AIClass AI;
public AIWebSocket(String roundId) {
System.out.println("Initializing WebSocket with round " + roundId);
try {
// Connect to LibertyBikes GameRoundWebsocket
URI endpointURI = new URI(uri + roundId);
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
container.connectToServer(this, endpointURI);
// Tell the websocket we are joining, TODO: don't want to hardcode bender
String dataai = "{\"playerjoined\":\"BOT:Bender\"}";
sendMessage(dataai);
// BOT TODO: parse the "playerlist" Json we get back to determine spot position
AI = new AIClass(this, 0, 0);
} catch (Exception e) {
e.printStackTrace();
}
}
@OnOpen
public void onOpen(Session session) {
this.session = session;
System.out.println("Opened Websocket");
}
@OnClose
public void onClose(Session session) {
System.out.println("Close Websocket");
}
@OnMessage
public void onMessage(Session session, String message) throws IOException {
System.out.println("On Message: " + message);
/*
* TODO: Describe the JSON we get back:
*/
AI.processAiMove(message);
}
public void sendDirection(DIRECTION dir) {
switch (dir) {
case RIGHT:
sendMessage("{\"direction\":\"RIGHT\"}");
break;
case DOWN:
sendMessage("{\"direction\":\"DOWN\"}");
break;
case LEFT:
sendMessage("{\"direction\":\"LEFT\"}");
break;
default:
sendMessage("{\"direction\":\"UP\"}");
break;
}
}
public void sendMessage(String message) {
this.session.getAsyncRemote().sendText(message);
}
}

View File

@ -1,13 +0,0 @@
<server>
<featureManager>
<feature>servlet-4.0</feature>
<feature>jaxrs-2.1</feature>
<feature>jsonb-1.0</feature>
<feature>mpRestClient-1.2</feature>
<feature>cdi-2.0</feature>
<feature>mpConfig-1.3</feature>
<feature>websocket-1.1</feature>
</featureManager>
<httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="${httpPort}" httpsPort="${httpsPort}" />
</server>

View File

@ -20,4 +20,3 @@ include 'auth-service'
include 'game-service'
include 'player-service'
include 'frontend'
include 'ai-service'