Compare commits
16 commits
creeps-liv
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89fe594e3b | ||
|
|
0ce900886f | ||
|
|
000b23c9f4 | ||
|
|
bc238b05dc | ||
|
|
47527f5b0b | ||
|
|
86a7194ec5 | ||
|
|
9f9d8be802 | ||
|
|
40ae3b048d | ||
|
|
204f626f11 | ||
|
|
dfd3e4b7fa | ||
|
|
e70073b7fe | ||
|
|
4c74873c65 | ||
|
|
4bf4cf89e2 | ||
|
|
66fd1ce173 | ||
|
|
8be4907c25 | ||
|
|
c294c61a85 |
4 changed files with 29 additions and 59 deletions
|
|
@ -1,15 +1,13 @@
|
||||||
package com.epita.creeps;
|
package com.epita.creeps;
|
||||||
|
|
||||||
import com.epita.creeps.commands.Basics;
|
import com.epita.creeps.commands.Basics;
|
||||||
|
import com.epita.creeps.given.extra.Cartographer;
|
||||||
import com.epita.creeps.given.vo.geometry.Direction;
|
import com.epita.creeps.given.vo.geometry.Direction;
|
||||||
import com.epita.creeps.given.vo.geometry.Point;
|
import com.epita.creeps.given.vo.geometry.Point;
|
||||||
import com.epita.creeps.given.vo.response.CommandResponse;
|
import com.epita.creeps.given.vo.response.CommandResponse;
|
||||||
import com.epita.creeps.given.vo.response.InitResponse;
|
import com.epita.creeps.given.vo.response.InitResponse;
|
||||||
import com.epita.creeps.given.vo.response.StatisticsResponse;
|
import com.epita.creeps.given.vo.response.StatisticsResponse;
|
||||||
import com.epita.creeps.units.Building;
|
import com.epita.creeps.units.*;
|
||||||
import com.epita.creeps.units.Citizen;
|
|
||||||
import com.epita.creeps.units.Turret;
|
|
||||||
import com.epita.creeps.units.Unit;
|
|
||||||
import kong.unirest.core.HttpResponse;
|
import kong.unirest.core.HttpResponse;
|
||||||
import kong.unirest.core.JsonNode;
|
import kong.unirest.core.JsonNode;
|
||||||
import kong.unirest.core.Unirest;
|
import kong.unirest.core.Unirest;
|
||||||
|
|
@ -63,7 +61,6 @@ public class Program {
|
||||||
logger.error("Cannot connect to the server. Aborting...");
|
logger.error("Cannot connect to the server. Aborting...");
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
// AsyncExec.justWait(0);
|
|
||||||
|
|
||||||
// Create account and get init infos
|
// Create account and get init infos
|
||||||
logger.info("Creating account");
|
logger.info("Creating account");
|
||||||
|
|
@ -76,59 +73,11 @@ public class Program {
|
||||||
Unit.getUnits().add(citizen1);
|
Unit.getUnits().add(citizen1);
|
||||||
Unit.getUnits().add(citizen2);
|
Unit.getUnits().add(citizen2);
|
||||||
|
|
||||||
StatisticsResponse statistics = Basics.getStatistics();
|
// Et voilà, machtou pichtou
|
||||||
logger.debug(statistics.toString());
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
for (var player : statistics.players) {
|
|
||||||
if (player.name == login)
|
|
||||||
continue;
|
|
||||||
citizen1.sendMessage(player.name, "Nicole");
|
|
||||||
citizen2.sendMessage(player.name,"Ouvre");
|
|
||||||
citizen1.waitFinished();
|
|
||||||
citizen2.waitFinished();
|
|
||||||
citizen1.sendMessage(player.name, "Nicole");
|
|
||||||
citizen2.sendMessage(player.name, "MAIS MOI JE VEUX FAIRE L'AMOUUUUR");
|
|
||||||
citizen1.waitFinished();
|
|
||||||
citizen2.waitFinished();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
logger.info("Done");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// logger.info("Done");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ### Get statistics
|
|
||||||
//GET http://localhost:1664/statistics
|
|
||||||
//
|
|
||||||
//### Get status
|
|
||||||
//GET http://localhost:1664/status
|
|
||||||
//
|
|
||||||
//### Get report
|
|
||||||
//GET http://localhost:1664/report/148997e9b
|
|
||||||
//
|
|
||||||
//### Login with user login_l
|
|
||||||
//POST http://localhost:1664/init/login_l
|
|
||||||
//
|
|
||||||
//> {%
|
|
||||||
//client.global.set("baseId", response.body.baseId);
|
|
||||||
//client.global.set("probeId", response.body.probeId);
|
|
||||||
//client.global.set("login", response.body.login);
|
|
||||||
//%}
|
|
||||||
//
|
|
||||||
//### Post noop commande
|
|
||||||
//POST http://localhost:1664/command/{{login}}/{{probeId}}/noop
|
|
||||||
//
|
|
||||||
//###
|
|
||||||
//POST http://localhost:1664/command/dumeig_a/8d87eea10/inspect
|
|
||||||
//
|
|
||||||
//###
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import com.epita.creeps.given.json.Json;
|
||||||
import com.epita.creeps.given.vo.report.*;
|
import com.epita.creeps.given.vo.report.*;
|
||||||
import com.epita.creeps.given.vo.response.InitResponse;
|
import com.epita.creeps.given.vo.response.InitResponse;
|
||||||
import com.epita.creeps.given.vo.response.StatisticsResponse;
|
import com.epita.creeps.given.vo.response.StatisticsResponse;
|
||||||
|
import com.epita.creeps.units.BomberBot;
|
||||||
import com.epita.creeps.units.Turret;
|
import com.epita.creeps.units.Turret;
|
||||||
import com.epita.creeps.units.Unit;
|
import com.epita.creeps.units.Unit;
|
||||||
import kong.unirest.core.HttpResponse;
|
import kong.unirest.core.HttpResponse;
|
||||||
|
|
@ -110,8 +111,8 @@ public class Basics {
|
||||||
Unit.getUnits().add(turret);
|
Unit.getUnits().add(turret);
|
||||||
}
|
}
|
||||||
else if (spawnReport.spawnedUnit.opcode.endsWith("bomber-bot")) {
|
else if (spawnReport.spawnedUnit.opcode.endsWith("bomber-bot")) {
|
||||||
Turret turret = new Turret(Program.getLogin(), spawnReport.spawnedUnitId, spawnReport.spawnedUnit.position);
|
BomberBot bombhero = new BomberBot(Program.getLogin(), spawnReport.spawnedUnitId, spawnReport.spawnedUnit.position);
|
||||||
Unit.getUnits().add(turret);
|
Unit.getUnits().add(bombhero);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logger.warn("Spawned unit is an unknown type. Ignored...");
|
logger.warn("Spawned unit is an unknown type. Ignored...");
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,26 @@
|
||||||
package com.epita.creeps.units;
|
package com.epita.creeps.units;
|
||||||
|
|
||||||
|
import com.epita.creeps.given.extra.Cartographer;
|
||||||
|
import com.epita.creeps.given.json.Json;
|
||||||
import com.epita.creeps.given.vo.geometry.Point;
|
import com.epita.creeps.given.vo.geometry.Point;
|
||||||
|
import com.epita.creeps.given.vo.parameter.FireParameter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class BomberBot extends Unit {
|
public class BomberBot extends Unit {
|
||||||
|
|
||||||
public BomberBot(String login, String id, Point position) {
|
public BomberBot(String login, String id, Point position) {
|
||||||
super(login, id, position);
|
super(login, id, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Retrieves all units that are turrets
|
||||||
|
public static List<Unit> getBomberBotUnits() {
|
||||||
|
return getUnits().stream().filter(unit -> unit.getClass() == BomberBot.class).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BomberBot fire() {
|
||||||
|
FireParameter fp = new FireParameter(this.position);
|
||||||
|
sendActionWithBody("fire:bomber-bot", Json.serialize(fp), 2);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,11 @@ public abstract class Unit {
|
||||||
// Sends a specific action to the server using it's HTTPS string representation
|
// Sends a specific action to the server using it's HTTPS string representation
|
||||||
// Sets pending action accordingly and asks for a report after `delay` ticks
|
// Sets pending action accordingly and asks for a report after `delay` ticks
|
||||||
public void sendActionWithBody(String actionCode, String body, long delay) {
|
public void sendActionWithBody(String actionCode, String body, long delay) {
|
||||||
// Move
|
if (!idle) {
|
||||||
|
// logger.warn("Unit is already busy, queuing action");
|
||||||
|
this.waitFinished();
|
||||||
|
}
|
||||||
|
// Do
|
||||||
idle = false;
|
idle = false;
|
||||||
pendingAction = AsyncExec.asyncExec(() -> Unirest.post(command_uri + actionCode).body(body).asJson(), delay)
|
pendingAction = AsyncExec.asyncExec(() -> Unirest.post(command_uri + actionCode).body(body).asJson(), delay)
|
||||||
.thenApplyAsync( x -> x );
|
.thenApplyAsync( x -> x );
|
||||||
|
|
@ -83,7 +87,7 @@ public abstract class Unit {
|
||||||
logger.warn("Invalid report received: null value");
|
logger.warn("Invalid report received: null value");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
logger.debug("Got report: " + lastReport);
|
// logger.debug("Got report: " + lastReport);
|
||||||
idle = true;
|
idle = true;
|
||||||
|
|
||||||
return lastReport.errorCode != null;
|
return lastReport.errorCode != null;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue