Search in sources :

Example 71 with Unit

use of bwapi.Unit in project BWJSAL by RobinsonMann.

the class UnitsMutexTest method isUnitUnlocked_unitIsLocked_returnsFalse.

@Test
public void isUnitUnlocked_unitIsLocked_returnsFalse() {
    final Unit unit = UnitBuilder.mockUnit();
    this.target.lockUnit(unit);
    assertThat(this.target.isUnitUnlocked(unit)).isFalse();
}
Also used : Unit(bwapi.Unit) Test(org.junit.Test)

Example 72 with Unit

use of bwapi.Unit in project BWJSAL by RobinsonMann.

the class UnitsMutex method lockUnits.

/**
 * Attempts to lock all of the given unit.
 * @param units Units to lock.
 * @return Returns true if locks were acquired for all of the units, false otherwise.
 */
public synchronized boolean lockUnits(final Iterable<Unit> units) {
    nonNull(units, "units");
    final Set<Unit> unitsWhereLockedAcquired = new HashSet<Unit>();
    for (final Unit unitToLock : units) {
        if (lockUnit(unitToLock)) {
            // Acquired lock.
            unitsWhereLockedAcquired.add(unitToLock);
        } else {
            // Failed to get lock.  Rollback all acquired unit locks and return that we have failed.
            unlockUnits(unitsWhereLockedAcquired);
            return false;
        }
    }
    // all locks acquired, return success.
    return true;
}
Also used : Unit(bwapi.Unit) HashSet(java.util.HashSet)

Example 73 with Unit

use of bwapi.Unit in project BWJSAL by RobinsonMann.

the class BfsBuildingPlacer method canBuildHereWithSpace.

private boolean canBuildHereWithSpace(ReservedMap reservedMap, UnitType type, TilePosition position, Unit builder, int buildDist) {
    if (type.isAddon()) {
        type = type.whatBuilds().first;
    }
    if (builder != null) {
        if (!reservedMap.canBuildHere(builder, position, type)) {
            return false;
        }
    } else {
        if (!reservedMap.canBuildHere(position, type)) {
            return false;
        }
    }
    if (type.isRefinery()) {
        return true;
    }
    int width = type.tileWidth();
    int height = type.tileHeight();
    // make sure we leave space for add - ons. These types of units can have addons:
    if (type == UnitType.Terran_Command_Center || type == UnitType.Terran_Factory || type == UnitType.Terran_Starport || type == UnitType.Terran_Science_Facility) {
        width += 2;
    }
    int startx = position.getX() - buildDist;
    if (startx < 0) {
        return false;
    }
    int starty = position.getY() - buildDist;
    if (starty < 0) {
        return false;
    }
    int endx = position.getX() + width + buildDist;
    if (endx > game.mapWidth()) {
        return false;
    }
    int endy = position.getY() + height + buildDist;
    if (endy > game.mapHeight()) {
        return false;
    }
    for (int x = startx; x < endx; x++) {
        for (int y = starty; y < endy; y++) {
            if (!isBuildable(builder, x, y) || reservedMap.isReserved(x, y)) {
                return false;
            }
        }
    }
    if (position.getX() > 3) {
        int startx2 = Math.max(startx - 2, 0);
        for (int x = startx2; x < startx; x++) {
            for (int y = starty; y < endy; y++) {
                for (Unit u : game.getUnitsOnTile(x, y)) {
                    if (!u.isLifted() && u != builder) {
                        UnitType type2 = u.getType();
                        if (type2 == UnitType.Terran_Command_Center || type2 == UnitType.Terran_Factory || type2 == UnitType.Terran_Starport || type2 == UnitType.Terran_Science_Facility) {
                            return false;
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : UnitType(bwapi.UnitType) Unit(bwapi.Unit)

Aggregations

Unit (bwapi.Unit)73 GameState (ecgberht.GameState)36 Test (org.junit.Test)21 Position (bwapi.Position)14 TilePosition (bwapi.TilePosition)10 BaseLocation (bwta.BaseLocation)7 Pair (bwapi.Pair)6 UnitType (bwapi.UnitType)6 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 Player (bwapi.Player)3 EnemyBuilding (ecgberht.EnemyBuilding)3 RaceUtils.createMockRace (BWJSAL.utils.RaceUtils.createMockRace)2 UnitTypeUtils.mockResourceDepotUnitType (BWJSAL.utils.UnitTypeUtils.mockResourceDepotUnitType)2 Race (bwapi.Race)2 Squad (ecgberht.Squad)2 Game (bwapi.Game)1 UnitCommand (bwapi.UnitCommand)1 Region (bwta.Region)1 Random (java.util.Random)1