Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Action {
- final ActionType type;
- Coord pos;
- final EntityType item;
- String message;
- private Action(ActionType command, Coord pos, EntityType item, String... message) {
- this.type = command;
- this.pos = pos;
- this.item = item;
- if(message.length == 1)
- {
- this.message = message[0];
- }
- }
- // none() == wait()
- static Action none(String... message) {
- return new Action(ActionType.WAIT, null, null, message);
- }
- static Action move(Coord pos, String... message) {
- return new Action(ActionType.MOVE, pos, null, message);
- }
- static Action dig(Coord pos, String... message) {
- return new Action(ActionType.DIG, pos, null, message);
- }
- static Action request(EntityType item, String... message) {
- return new Action(ActionType.REQUEST, null, item, message);
- }
- public Action clone()
- {
- return new Action(type, pos.clone(), item);
- }
- public String toString() {
- StringBuilder builder = new StringBuilder(type.toString());
- if (pos != null) {
- builder.append(' ').append(pos);
- }
- if (item != null) {
- builder.append(' ').append(item);
- }
- if (message != null) {
- builder.append(' ').append(message);
- }
- return builder.toString();
- }
- }
- class Entity {
- private static final Coord DEAD_POS = new Coord(-1, -1);
- // Updated every turn
- final int id;
- final EntityType type;
- Coord pos;
- final EntityType item;
- // Computed for my robots
- Action action = null;
- Action nextAction = null;
- Entity(Scanner in) {
- id = in.nextInt();
- type = EntityType.valueOf(in.nextInt());
- pos = new Coord(in);
- item = EntityType.valueOf(in.nextInt());
- }
- Entity(int id, EntityType type, Coord pos, EntityType item, Action action)
- {
- this.id = id;
- this.type = type;
- this.pos = pos;
- this.item = item;
- this.action = action;
- }
- public Entity clone()
- {
- return new Entity(id, type, pos.clone(), item, action.clone());
- }
- boolean isAlive() {
- return !DEAD_POS.equals(pos);
- }
- }
- class Game {
- // Given at startup
- final int width;
- final int height;
- // Updated each turn
- final Team myTeam = new Team();
- final Team opponentTeam = new Team();
- public Cell[][] cells;
- int myRadarCooldown;
- int myTrapCooldown;
- Map<Integer, Entity> entitiesById;
- ArrayList<Coord> myRadarPos;
- ArrayList<Coord> myTrapPos;
- }
- // visa mano boto logika
- // game dabartinio turn žaidimo state
- // lastGame praeito
- void think(Game game, Game lastGame)
- {
- turns++;
- this.game = game;
- this.lastGame = lastGame;
- // prediction of the enemy
- // jei žaidimas tęsiasi ilgiau nei 130 turns, pradedu kasti ores, kurie priklauso mano sukurtam bankui
- if(turns > 130)
- {
- MineBankOres = true;
- }
- // enemy prediction
- predictEnemy();
- // randa geriausią radarą
- Pair<Coord, Integer> radar = getBestRadarPosition();
- // randa geriausią robotą radarui nešti
- int id = getRadarBuyer();
- ArrayList<Entity> robotsLeft = new ArrayList<>();
- for (Entity robot : game.myTeam.robots) {
- // jeigu miręs robotas, nieko nedaryti
- if(!robot.isAlive())
- {
- robot.action = Action.none();
- continue;
- }
- //jeigu robotas neša ore, eiti į HQ
- if(robot.item == EntityType.AMADEUSIUM)
- {
- robot.action = Action.move(new Coord(0, robot.pos.y));
- continue;
- }
- // patikrinu ar galiu susisprogdinti ir tuo pačiu nužudyti priešų botą
- Cell suicide = suicideAttack(robot);
- if(suicide != null)
- {
- game.getCell(suicide.pos).possibilityOfBomb = 0;
- robot.action = Action.dig(suicide.pos, "REEEEEEEEE");
- continue;
- }
- // radaro logiką
- // ------------------
- if(game.getKnownSafeOres(MineBankOres).size() / 2 < game.myTeam.robots.size() && robot.id == radar.second)
- {
- if(!robot.item.equals(EntityType.RADAR))
- {
- robot.action = Action.request(EntityType.RADAR);
- }
- else
- {
- robot.action = Action.dig(radar.first);
- }
- continue;
- }
- else if(game.getKnownSafeOres(MineBankOres).size() / 2 < game.myTeam.robots.size() && robot.id == id && radar.second == -1)
- {
- robot.action = Action.move(new Coord(0, robot.pos.y));
- continue;
- }
- if(lastGame == null)
- {
- robot.action = Action.none();
- continue;
- }
- robot.action = null;
- // robotai like be komandų
- robotsLeft.add(robot);
- }
- // with left robots go mine minerals etc. Find most efficient ways to gather them
- findBestBotMineOrderNoRandom(robotsLeft);
- // jeigu vis dar yra robotų kurie neturi priskirto action, tada pritaikoma kita logika
- for(Entity robot : robotsLeft)
- {
- if(!robot.isAlive())
- continue;
- if(robot.action == null)
- {
- boolean found = false;
- for(int i = 3; i < 10;i++) {
- Coord bestPos = game.findClosestDigInRange(robot.pos, radar.first, i);
- if (radar.second != -1 && bestPos != null && bestPos.isValid()) {
- game.getCell(bestPos).hole = true;
- robot.action = Action.dig(bestPos);
- found = true;
- break;
- }
- }
- if(!found)
- {
- Coord bestPos2 = findClosestUnknownDig(robot).pos;
- game.getCell(bestPos2).hole = true;
- robot.action = Action.dig(bestPos2);
- }
- }
- }
- // now if robot is at x == 0
- // try to fake take bomb action, a.k.a wait
- faking();
- predictNextOre();
- // Jau turiu visus robotų action, dabar sutaisau judėjimą robotų, kad neįeičiau į priešų spastus ir pan.
- Movement.fixMovement(game);
- game.reset();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement