Search in sources :

Example 6 with BaseLocation

use of bwta.BaseLocation in project Ecgberht by Jabbo16.

the class ChooseBaseLocation method execute.

@Override
public State execute() {
    try {
        if (((GameState) this.handler).chosenBaseLocation != null) {
            return State.SUCCESS;
        }
        TilePosition main = null;
        if (((GameState) this.handler).MainCC != null) {
            main = ((GameState) this.handler).MainCC.getTilePosition();
        } else {
            main = ((GameState) this.handler).getPlayer().getStartLocation();
        }
        List<BaseLocation> valid = new ArrayList<>();
        for (BaseLocation b : ((GameState) this.handler).BLs) {
            if (!((GameState) this.handler).CCs.containsKey(b.getRegion().getCenter()) && BWTA.isConnected(b.getTilePosition(), main)) {
                valid.add(b);
            }
        }
        List<BaseLocation> remove = new ArrayList<>();
        for (BaseLocation b : valid) {
            for (Unit u : ((GameState) this.handler).enemyCombatUnitMemory) {
                if (BWTA.getRegion(u.getPosition()) == null || !u.getType().canAttack() || u.getType().isWorker()) {
                    continue;
                }
                if (BWTA.getRegion(u.getPosition()).getCenter().equals(BWTA.getRegion(b.getPosition()).getCenter())) {
                    remove.add(b);
                    break;
                }
            }
            for (EnemyBuilding u : ((GameState) this.handler).enemyBuildingMemory.values()) {
                if (BWTA.getRegion(u.pos) == null) {
                    continue;
                }
                if (BWTA.getRegion(u.pos).getCenter().equals(BWTA.getRegion(b.getPosition()).getCenter())) {
                    remove.add(b);
                    break;
                }
            }
        }
        valid.removeAll(remove);
        if (valid.isEmpty()) {
            System.out.println("wut");
            ((GameState) this.handler).chosenBaseLocation = null;
            ((GameState) this.handler).movingToExpand = false;
            ((GameState) this.handler).chosenBuilderBL.stop();
            ((GameState) this.handler).workerIdle.add(((GameState) this.handler).chosenBuilderBL);
            ((GameState) this.handler).chosenBuilderBL = null;
            ((GameState) this.handler).expanding = false;
            ((GameState) this.handler).deltaCash.first -= UnitType.Terran_Command_Center.mineralPrice();
            ((GameState) this.handler).deltaCash.second -= UnitType.Terran_Command_Center.gasPrice();
            return State.FAILURE;
        }
        ((GameState) this.handler).chosenBaseLocation = valid.get(0).getTilePosition();
        // System.out.println("----------------------------");
        return State.SUCCESS;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : TilePosition(bwapi.TilePosition) ArrayList(java.util.ArrayList) GameState(ecgberht.GameState) Unit(bwapi.Unit) BaseLocation(bwta.BaseLocation) EnemyBuilding(ecgberht.EnemyBuilding)

Example 7 with BaseLocation

use of bwta.BaseLocation in project Ecgberht by Jabbo16.

the class BaseLocationComparator method compare.

@Override
public int compare(BaseLocation a, BaseLocation b) {
    try {
        TilePosition start = null;
        if (!enemy) {
            if (getGs().MainCC != null) {
                start = getGs().MainCC.getTilePosition();
            }
            if (start == null) {
                start = getGs().getPlayer().getStartLocation();
            }
            BaseLocation closestBase = BWTA.getNearestBaseLocation(start);
            if (closestBase != null) {
                if (BWTA.getNearestBaseLocation(start).getTilePosition().equals(a.getTilePosition())) {
                    return -1;
                }
                if (BWTA.getNearestBaseLocation(start).getTilePosition().equals(b.getTilePosition())) {
                    return 1;
                }
            }
            if (a.isIsland()) {
                return 1;
            }
            if (b.isIsland()) {
                return -1;
            }
            double distA = getGs().getGroundDistance(a.getTilePosition(), start);
            double distB = getGs().getGroundDistance(b.getTilePosition(), start);
            if (distA == 0.0 && distB > 0.0) {
                return 1;
            }
            if (distB == 0.0 && distA > 0.0) {
                return -1;
            }
            if (a.isMineralOnly() && !b.isMineralOnly()) {
                return 1;
            }
            if (b.isMineralOnly() && !a.isMineralOnly()) {
                return -1;
            }
            if (distA < distB && distA > 0.0) {
                if (getGs().blockedBLs.contains(a)) {
                    return 1;
                }
                return -1;
            } else {
                if (distA > distB && distB > 0.0) {
                    if (getGs().blockedBLs.contains(b)) {
                        return -1;
                    }
                    return 1;
                }
            }
            return 1;
        } else {
            if (getGs().enemyBase != null) {
                start = getGs().enemyBase.getTilePosition();
            } else {
                return -1;
            }
            if (a.isIsland()) {
                return 1;
            }
            if (b.isIsland()) {
                return -1;
            }
            double distA = getGs().getGroundDistance(a.getTilePosition(), start);
            double distB = getGs().getGroundDistance(b.getTilePosition(), start);
            if (distA == 0.0 && distB > 0.0) {
                return 1;
            }
            if (distB == 0.0 && distA > 0.0) {
                return -1;
            }
            if (a.isMineralOnly() && !b.isMineralOnly()) {
                return 1;
            }
            if (b.isMineralOnly() && !a.isMineralOnly()) {
                return -1;
            }
            if (distA < distB && distA > 0.0) {
                if (getGs().blockedBLs.contains(a)) {
                    return 1;
                }
                return 1;
            } else {
                if (distA > distB && distB > 0.0) {
                    if (getGs().blockedBLs.contains(b)) {
                        return -1;
                    }
                    return 1;
                }
            }
            return 1;
        }
    } catch (Exception e) {
        System.err.println("Sorter");
        System.err.println(e);
    }
    return 0;
}
Also used : TilePosition(bwapi.TilePosition) BaseLocation(bwta.BaseLocation)

Example 8 with BaseLocation

use of bwta.BaseLocation in project Ecgberht by Jabbo16.

the class CheckScan method execute.

@Override
public State execute() {
    try {
        if (((GameState) this.handler).CSs.isEmpty()) {
            return State.FAILURE;
        }
        if (((GameState) this.handler).getGame().elapsedTime() - ((GameState) this.handler).startCount > 1) {
            for (Unit u : ((GameState) this.handler).enemyCombatUnitMemory) {
                if ((u.isCloaked() || u.isBurrowed()) && !u.isDetected() && u.getType().canAttack()) {
                    ((GameState) this.handler).checkScan = u.getTilePosition();
                    return State.SUCCESS;
                }
            }
        }
        List<BaseLocation> valid = new ArrayList<>();
        for (BaseLocation b : ((GameState) this.handler).EnemyBLs) {
            if (((GameState) this.handler).getGame().isVisible(b.getTilePosition()) || b.isIsland()) {
                continue;
            }
            if (((GameState) this.handler).enemyBase != null) {
                if (((GameState) this.handler).enemyBase.getTilePosition().equals(b.getTilePosition())) {
                    continue;
                }
            }
            valid.add(b);
        }
        if (valid.isEmpty()) {
            return State.FAILURE;
        }
        for (Unit u : ((GameState) this.handler).CSs) {
            if (u.getEnergy() == 200) {
                Random random = new Random();
                ((GameState) this.handler).checkScan = valid.get(random.nextInt(valid.size())).getTilePosition();
                return State.SUCCESS;
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) GameState(ecgberht.GameState) Unit(bwapi.Unit) BaseLocation(bwta.BaseLocation)

Example 9 with BaseLocation

use of bwta.BaseLocation in project Ecgberht by Jabbo16.

the class SendScout method execute.

@Override
public State execute() {
    try {
        if (((GameState) this.handler).enemyBase == null) {
            if (!((GameState) this.handler).ScoutSLs.isEmpty()) {
                List<BaseLocation> aux = new ArrayList<BaseLocation>();
                for (BaseLocation b : ((GameState) this.handler).ScoutSLs) {
                    if (BWTA.isConnected(b.getTilePosition(), ((GameState) this.handler).chosenScout.getTilePosition())) {
                        if (((GameState) this.handler).chosenScout.move(b.getPosition().makeValid())) {
                            return State.SUCCESS;
                        }
                    } else {
                        aux.add(b);
                    }
                }
                ((GameState) this.handler).ScoutSLs.removeAll(aux);
            }
        }
        ((GameState) this.handler).workerIdle.add(((GameState) this.handler).chosenScout);
        ((GameState) this.handler).chosenScout.stop();
        ((GameState) this.handler).chosenScout = null;
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : ArrayList(java.util.ArrayList) GameState(ecgberht.GameState) BaseLocation(bwta.BaseLocation)

Example 10 with BaseLocation

use of bwta.BaseLocation in project BWAPI4J by OpenBW.

the class TestListener method onFrame.

@Override
public void onFrame() {
    if (frame == 5) {
        System.out.println(this.bwta.getBaseLocations().size() + " base locations found.");
        for (BaseLocation base : this.bwta.getBaseLocations()) {
            System.out.println("location at " + base.getPosition().getX() + ", " + base.getPosition().getY());
        }
        System.out.println(this.bwta.getChokepoints().size() + " chokepoints found.");
        for (Chokepoint choke : this.bwta.getChokepoints()) {
            System.out.println("choke side 1: " + choke.getRegions().first + ", side 2: " + choke.getRegions().second);
        }
        System.out.println(this.bwta.getRegions().size() + " regions found.");
    }
    if (bw.getInteractionHandler().isKeyPressed(Key.K_D)) {
        System.out.println("D");
    }
    for (Player player : bw.getAllPlayers()) {
        System.out.println("Player " + player.getName() + " has minerals " + player.minerals());
    }
    this.frame++;
    System.err.println("tester");
    throw new RuntimeException("test");
}
Also used : Chokepoint(bwta.Chokepoint) BaseLocation(bwta.BaseLocation)

Aggregations

BaseLocation (bwta.BaseLocation)13 Unit (bwapi.Unit)7 TilePosition (bwapi.TilePosition)4 GameState (ecgberht.GameState)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 RaceUtils.createMockRace (BWJSAL.utils.RaceUtils.createMockRace)2 UnitTypeUtils.mockResourceDepotUnitType (BWJSAL.utils.UnitTypeUtils.mockResourceDepotUnitType)2 Race (bwapi.Race)2 UnitType (bwapi.UnitType)2 Position (bwapi.Position)1 Chokepoint (bwta.Chokepoint)1 Region (bwta.Region)1 EnemyBuilding (ecgberht.EnemyBuilding)1 Random (java.util.Random)1