Search in sources :

Example 1 with Player

use of bwapi.Player in project Ecgberht by Jabbo16.

the class ChoosePosition method execute.

@Override
public State execute() {
    try {
        Game juego = ((GameState) this.handler).getGame();
        Player jugador = ((GameState) this.handler).getPlayer();
        TilePosition origin = null;
        if (((GameState) this.handler).chosenToBuild.isRefinery()) {
            if (!((GameState) this.handler).refineriesAssigned.isEmpty()) {
                for (Pair<Pair<Unit, Integer>, Boolean> g : ((GameState) this.handler).refineriesAssigned) {
                    if (!g.second) {
                        ((GameState) this.handler).chosenPosition = g.first.first.getTilePosition();
                        return State.SUCCESS;
                    }
                }
            }
        } else {
            if (!((GameState) this.handler).workerBuild.isEmpty()) {
                for (Pair<Unit, Pair<UnitType, TilePosition>> w : ((GameState) this.handler).workerBuild) {
                    ((GameState) this.handler).testMap.updateMap(w.second.second, w.second.first, false);
                }
            }
            if (!((GameState) this.handler).chosenToBuild.equals(UnitType.Terran_Bunker) && !((GameState) this.handler).chosenToBuild.equals(UnitType.Terran_Missile_Turret)) {
                if (((GameState) this.handler).strat.proxy && ((GameState) this.handler).chosenToBuild == UnitType.Terran_Barracks) {
                    origin = new TilePosition(((GameState) this.handler).getGame().mapWidth() / 2, ((GameState) this.handler).getGame().mapHeight() / 2);
                } else {
                    // origin = BWTA.getRegion(jugador.getStartLocation()).getCenter().toTilePosition();
                    origin = jugador.getStartLocation();
                }
            } else {
                if (((GameState) this.handler).chosenToBuild.equals(UnitType.Terran_Missile_Turret)) {
                    if (((GameState) this.handler).DBs.isEmpty()) {
                        origin = BWTA.getNearestChokepoint(jugador.getStartLocation()).getCenter().toTilePosition();
                    } else {
                        for (Unit b : ((GameState) this.handler).DBs.keySet()) {
                            origin = b.getTilePosition();
                            break;
                        }
                    }
                } else {
                    if (((GameState) this.handler).EI.naughty && ((GameState) this.handler).enemyRace == Race.Zerg) {
                        TilePosition raxTile = ((GameState) this.handler).MBs.iterator().next().getTilePosition();
                        origin = ((GameState) this.handler).testMap.findBunkerPositionAntiPool(raxTile.toPosition(), ((GameState) this.handler).closestChoke);
                        if (origin != null) {
                            ((GameState) this.handler).testMap = ((GameState) this.handler).map.clone();
                            ((GameState) this.handler).chosenPosition = origin;
                            return State.SUCCESS;
                        } else {
                            origin = ((GameState) this.handler).getBunkerPositionAntiPool();
                            if (origin != null) {
                                ((GameState) this.handler).testMap = ((GameState) this.handler).map.clone();
                                ((GameState) this.handler).chosenPosition = origin;
                                return State.SUCCESS;
                            } else {
                                origin = raxTile;
                            }
                        }
                    } else {
                        if (((GameState) this.handler).Ts.isEmpty()) {
                            if (((GameState) this.handler).closestChoke != null) {
                                origin = ((GameState) this.handler).testMap.findBunkerPosition(((GameState) this.handler).closestChoke);
                                if (origin != null) {
                                    ((GameState) this.handler).testMap = ((GameState) this.handler).map.clone();
                                    ((GameState) this.handler).chosenPosition = origin;
                                    return State.SUCCESS;
                                } else {
                                    origin = ((GameState) this.handler).closestChoke.getCenter().toTilePosition();
                                }
                            }
                        // else {
                        // origin = BWTA.getNearestChokepoint(jugador.getStartLocation()).getCenter().toTilePosition();
                        // }
                        } else {
                            for (Unit b : ((GameState) this.handler).Ts) {
                                origin = b.getTilePosition();
                                break;
                            }
                        }
                    }
                }
            }
            TilePosition posicion = ((GameState) this.handler).testMap.findPosition(((GameState) this.handler).chosenToBuild, origin);
            ((GameState) this.handler).testMap = ((GameState) this.handler).map.clone();
            if (posicion != null) {
                ((GameState) this.handler).chosenPosition = posicion;
                return State.SUCCESS;
            }
        }
        TilePosition posicion = juego.getBuildLocation(((GameState) this.handler).chosenToBuild, BWTA.getRegion(jugador.getStartLocation()).getCenter().toTilePosition(), 500);
        if (posicion != null) {
            if (juego.canBuildHere(posicion, ((GameState) this.handler).chosenToBuild)) {
                ((GameState) this.handler).chosenPosition = posicion;
                return State.SUCCESS;
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : Player(bwapi.Player) Game(bwapi.Game) TilePosition(bwapi.TilePosition) GameState(ecgberht.GameState) Unit(bwapi.Unit) Pair(bwapi.Pair)

Example 2 with Player

use of bwapi.Player in project BWJSAL by RobinsonMann.

the class UnitTrackerTest method onFrame_propertyChangedSinceDiscovery_latestPropertyReturned.

@Test
public void onFrame_propertyChangedSinceDiscovery_latestPropertyReturned() {
    final Unit unit = createMockUnit(true);
    final Player originalUnitOwner = Mockito.mock(Player.class);
    when(unit.getPlayer()).thenReturn(originalUnitOwner);
    this.target.onUnitDiscover(unit, 0);
    // Owner has changed and unit still exists, so tracked owner should change at next onFrame()
    final Player newUnitOwner = Mockito.mock(Player.class);
    when(unit.getPlayer()).thenReturn(newUnitOwner);
    this.target.onFrame(1);
    assertThat(this.target.getPlayer(unit)).isEqualTo(newUnitOwner);
}
Also used : Player(bwapi.Player) Unit(bwapi.Unit) Test(org.junit.Test)

Example 3 with Player

use of bwapi.Player in project BWJSAL by RobinsonMann.

the class UnitTrackerTest method onDiscovery_unitDiscovered_unitTracked.

@Test
public void onDiscovery_unitDiscovered_unitTracked() {
    final Unit unit = createMockUnit(true);
    final Player unitOwner = Mockito.mock(Player.class);
    when(unit.getPlayer()).thenReturn(unitOwner);
    this.target.onUnitDiscover(unit, 0);
    assertThat(this.target.getPlayer(unit)).isEqualTo(unitOwner);
}
Also used : Player(bwapi.Player) Unit(bwapi.Unit) Test(org.junit.Test)

Aggregations

Player (bwapi.Player)3 Unit (bwapi.Unit)3 Test (org.junit.Test)2 Game (bwapi.Game)1 Pair (bwapi.Pair)1 TilePosition (bwapi.TilePosition)1 GameState (ecgberht.GameState)1