Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Viewable distance check fixed.

[FIXED]     BaseModule viewRange check was inverted.
[UPDATED]   Better variable naming on Functions.
  • Loading branch information...
commit ea588acd41e53ea14a494f3dae1faaa204ead6b2 1 parent c971a84
@lhunath lhunath authored
Showing with 101 additions and 87 deletions.
  1. +2 −2 omicron-api/src/main/java/com/lyndir/omicron/api/model/ResourceCost.java
  2. +17 −6 omicron-api/src/main/java/com/lyndir/omicron/api/util/PathUtils.java
  3. +2 −2 omicron-cli/src/main/java/com/lyndir/omicron/cli/command/FireCommand.java
  4. +4 −4 omicron-cli/src/main/java/com/lyndir/omicron/cli/command/MoveCommand.java
  5. +4 −4 omicron-cli/src/main/java/com/lyndir/omicron/cli/view/MapView.java
  6. +2 −1  omicron-cli/src/main/resources/logback.xml
  7. +1 −1  omicron-core/src/main/java/com/lyndir/omicron/api/model/BaseModule.java
  8. +10 −10 omicron-core/src/main/java/com/lyndir/omicron/api/model/ConstructorModule.java
  9. +2 −2 omicron-core/src/main/java/com/lyndir/omicron/api/model/CoreUtils.java
  10. +5 −5 omicron-core/src/main/java/com/lyndir/omicron/api/model/ExtractorModule.java
  11. +14 −14 omicron-core/src/main/java/com/lyndir/omicron/api/model/Game.java
  12. +4 −4 omicron-core/src/main/java/com/lyndir/omicron/api/model/GameController.java
  13. +6 −6 omicron-core/src/main/java/com/lyndir/omicron/api/model/MobilityModule.java
  14. +4 −4 omicron-core/src/main/java/com/lyndir/omicron/api/model/Player.java
  15. +2 −1  omicron-core/src/test/resources/logback.xml
  16. +6 −6 omicron-web/src/main/java/com/lyndir/omicron/webapp/resource/GameBuilderResource.java
  17. +16 −15 omicron-web/src/main/resources/logback.xml
View
4 omicron-api/src/main/java/com/lyndir/omicron/api/model/ResourceCost.java
@@ -148,8 +148,8 @@ public int get(final ResourceType resourceType) {
public boolean isZero() {
return FluentIterable.from( getResourceQuantities().values() ).filter( new PredicateNN<Integer>() {
@Override
- public boolean apply(@Nonnull final Integer input) {
- return input > 0;
+ public boolean apply(@Nonnull final Integer resourceQuantity) {
+ return resourceQuantity > 0;
}
} ).isEmpty();
}
View
23 omicron-api/src/main/java/com/lyndir/omicron/api/util/PathUtils.java
@@ -11,6 +11,7 @@
public abstract class PathUtils {
+ @SuppressWarnings("UnusedDeclaration")
private static final Logger logger = Logger.get( PathUtils.class );
/**
@@ -30,8 +31,10 @@
final NNFunctionNN<E, Iterable<E>> neighboursFunction) {
// Test the root.
- if (foundFunction.apply( root ))
+ if (foundFunction.apply( root )) {
+ logger.trc( "found root: %s", root );
return Optional.of( new Path<>( root, 0 ) );
+ }
// Initialize breath-first.
Set<E> testedNodes = new HashSet<>();
@@ -50,14 +53,19 @@
continue;
double neighbourCost = testPath.getCost() + costFunction.apply( new Step<>( testPath.getTarget(), neighbour ) );
- if (neighbourCost > maxCost)
+ if (neighbourCost > maxCost) {
// Stepping to neighbour from here would exceed maximum cost.
+ logger.trc( "neighbour exceeds maximum cost (%.2f > %.2f): %s", neighbourCost, maxCost, neighbour );
continue;
+ }
// Did we find the target?
Path<E> neighbourPath = new Path<>( testPath, neighbour, neighbourCost );
- if (foundFunction.apply( neighbour ))
+ if (foundFunction.apply( neighbour )) {
+ logger.trc( "found neighbour at cost %.2f: %s", neighbourCost, neighbour );
return Optional.of( neighbourPath );
+ }
+ logger.trc( "intermediate neighbour at cost %.2f: %s", neighbourCost, neighbour );
// Neighbour is not the target, add it for testing its neighbours later.
testPaths.add( neighbourPath );
@@ -100,13 +108,16 @@
// Neighbour was already tested.
continue;
- double neighbourCost = testPath.getCost() + 1;
- if (neighbourCost > radius)
+ double neighbourDistance = testPath.getCost() + 1;
+ if (neighbourDistance > radius) {
// Stepping to neighbour from here would exceed maximum cost.
+ logger.trc( "neighbour exceeds radius (%.2f > %.2f): %s", neighbourDistance, radius, neighbour );
continue;
+ }
// Add it for testing its neighbours later.
- testPaths.add( new Path<>( testPath, neighbour, neighbourCost ) );
+ logger.trc( "neighbour at distance %.2f: %s", neighbourDistance, neighbour );
+ testPaths.add( new Path<>( testPath, neighbour, neighbourDistance ) );
}
}
View
4 omicron-cli/src/main/java/com/lyndir/omicron/cli/command/FireCommand.java
@@ -91,9 +91,9 @@ public void evaluate(final Iterator<String> tokens) {
final String levelArgument = ifNotNullElse( weaponIndexOrLevelArgument, location.getLevel().getType().getName() );
Optional<? extends ILevel> level = FluentIterable.from( gameController.get().listLevels() ).firstMatch( new Predicate<ILevel>() {
@Override
- public boolean apply(final ILevel input) {
+ public boolean apply(final ILevel aLevel) {
- return input.getType().getName().equalsIgnoreCase( levelArgument );
+ return aLevel.getType().getName().equalsIgnoreCase( levelArgument );
}
} );
if (!level.isPresent()) {
View
8 omicron-cli/src/main/java/com/lyndir/omicron/cli/command/MoveCommand.java
@@ -56,16 +56,16 @@ public void evaluate(final Iterator<String> tokens) {
err( "No such side/level: %s. Valid sides are: %s, valid levels are: %s", side, //
FluentIterable.from( ImmutableList.copyOf( Side.values() ) ).transform( new Function<Side, String>() {
@Override
- public String apply(final Side input) {
+ public String apply(final Side aSide) {
- return input.name();
+ return aSide.name();
}
} ), //
FluentIterable.from( ImmutableList.copyOf( LevelType.values() ) ).transform( new Function<LevelType, String>() {
@Override
- public String apply(final LevelType input) {
+ public String apply(final LevelType levelType) {
- return input.name();
+ return levelType.name();
}
} )
);
View
8 omicron-cli/src/main/java/com/lyndir/omicron/cli/view/MapView.java
@@ -188,18 +188,18 @@ private void setHomeOffset() {
setOffset( FluentIterable.from( gameObjects ).filter( new PredicateNN<IGameObject>() {
@Override
- public boolean apply(@Nonnull final IGameObject input) {
+ public boolean apply(@Nonnull final IGameObject gameObject) {
// Only game objects in this map's displayed level.
- return input.checkLocation().get().getLevel().getType() == getLevelType();
+ return gameObject.checkLocation().get().getLevel().getType() == getLevelType();
}
} ).transform( new NNFunctionNN<IGameObject, Vec2>() {
@Nonnull
@Override
- public Vec2 apply(@Nonnull final IGameObject input) {
+ public Vec2 apply(@Nonnull final IGameObject gameObject) {
// Transform game objects into their offset from the center of the map.
hasUnits = true;
Box contentBox = getContentBoxOnScreen();
- return positionToMapCoordinate( input.checkLocation().get().getPosition() ) //
+ return positionToMapCoordinate( gameObject.checkLocation().get().getPosition() ) //
.translate( -contentBox.getSize().getWidth() / 2, -contentBox.getSize().getHeight() / 2 );
}
} ).first().or( new Supplier<Vec2>() {
View
3  omicron-cli/src/main/resources/logback.xml
@@ -1,6 +1,7 @@
<configuration scan="true">
- <logger name="com.lyndir.omicron" level="TRACE" />
+ <logger name="com.lyndir" level="INFO" />
+ <logger name="com.lyndir.omicron" level="DEBUG" />
<root level="INFO" />
View
2  omicron-core/src/main/java/com/lyndir/omicron/api/model/BaseModule.java
@@ -84,7 +84,7 @@ else if (observable instanceof IGameObject)
}
}
- return Maybool.from(ourLocation.get().getPosition().distanceTo( observableLocation.getPosition() ) > viewRange);
+ return Maybool.from(ourLocation.get().getPosition().distanceTo( observableLocation.getPosition() ) <= viewRange);
}
throw new AlreadyCheckedException( "Switch statement should handle all cases." );
View
20 omicron-core/src/main/java/com/lyndir/omicron/api/model/ConstructorModule.java
@@ -89,8 +89,8 @@ private void construct(final ConstructionSite site) {
// Initialize path finding functions.
PredicateNN<GameObject> foundFunction = new PredicateNN<GameObject>() {
@Override
- public boolean apply(@Nonnull final GameObject input) {
- for (final ContainerModule containerModule : input.getModules( ModuleType.CONTAINER ))
+ public boolean apply(@Nonnull final GameObject gameObject) {
+ for (final ContainerModule containerModule : gameObject.getModules( ModuleType.CONTAINER ))
if (resourceCost.get( containerModule.getResourceType() ) > 0 && containerModule.getStock() > 0)
return true;
@@ -100,7 +100,7 @@ public boolean apply(@Nonnull final GameObject input) {
NNFunctionNN<PathUtils.Step<GameObject>, Double> costFunction = new NNFunctionNN<PathUtils.Step<GameObject>, Double>() {
@Nonnull
@Override
- public Double apply(@Nonnull final PathUtils.Step<GameObject> input) {
+ public Double apply(@Nonnull final PathUtils.Step<GameObject> gameObjectStep) {
return 1d;
}
};
@@ -309,8 +309,8 @@ protected void onNewTurn() {
// Initialize path finding functions.
PredicateNN<GameObject> foundFunction = new PredicateNN<GameObject>() {
@Override
- public boolean apply(@Nonnull final GameObject input) {
- for (final ConstructorModule module : input.getModules( ModuleType.CONSTRUCTOR ))
+ public boolean apply(@Nonnull final GameObject gameObject) {
+ for (final ConstructorModule module : gameObject.getModules( ModuleType.CONSTRUCTOR ))
if (module.getRemainingSpeed() > 0 && !module.isResourceConstrained()
&& getRemainingWork( module.getBuildsModule() ) > 0)
return true;
@@ -321,7 +321,7 @@ public boolean apply(@Nonnull final GameObject input) {
NNFunctionNN<PathUtils.Step<GameObject>, Double> costFunction = new NNFunctionNN<PathUtils.Step<GameObject>, Double>() {
@Nonnull
@Override
- public Double apply(@Nonnull final PathUtils.Step<GameObject> input) {
+ public Double apply(@Nonnull final PathUtils.Step<GameObject> gameObjectStep) {
return 1d;
}
};
@@ -337,8 +337,8 @@ public Double apply(@Nonnull final PathUtils.Step<GameObject> input) {
.transform( new NFunctionNN<Tile, GameObject>() {
@Nullable
@Override
- public GameObject apply(@Nonnull final Tile input) {
- Optional<GameObject> contents = input.getContents();
+ public GameObject apply(@Nonnull final Tile tile) {
+ Optional<GameObject> contents = tile.getContents();
if (contents.isPresent()) {
for (final ConstructorModule module : contents.get()
.getModules(
@@ -373,8 +373,8 @@ public GameObject apply(@Nonnull final Tile input) {
synchronized (remainingWork) {
if (FluentIterable.from( remainingWork.values() ).filter( new PredicateNN<Integer>() {
@Override
- public boolean apply(@Nonnull final Integer input) {
- return input > 0;
+ public boolean apply(@Nonnull final Integer remainingWork) {
+ return remainingWork > 0;
}
} ).isEmpty())
// No more work remaining; create the constructed unit.
View
4 omicron-core/src/main/java/com/lyndir/omicron/api/model/CoreUtils.java
@@ -92,8 +92,8 @@ static VictoryConditionType coreVCT(final PublicVictoryConditionType object) {
return Lists.transform( checkNotNull( object ), new NNFunctionNN<PublicVictoryConditionType, VictoryConditionType>() {
@Nonnull
@Override
- public VictoryConditionType apply(@Nonnull final PublicVictoryConditionType input) {
- return coreVCT( input );
+ public VictoryConditionType apply(@Nonnull final PublicVictoryConditionType victoryConditionType) {
+ return coreVCT( victoryConditionType );
}
} );
}
View
10 omicron-core/src/main/java/com/lyndir/omicron/api/model/ExtractorModule.java
@@ -73,8 +73,8 @@ protected void onNewTurn() {
// Initialize path finding functions.
PredicateNN<GameObject> foundFunction = new PredicateNN<GameObject>() {
@Override
- public boolean apply(@Nonnull final GameObject input) {
- for (final ContainerModule containerModule : input.getModules( ModuleType.CONTAINER ))
+ public boolean apply(@Nonnull final GameObject gameObject) {
+ for (final ContainerModule containerModule : gameObject.getModules( ModuleType.CONTAINER ))
if (containerModule.getAvailable() > 0)
return true;
@@ -84,7 +84,7 @@ public boolean apply(@Nonnull final GameObject input) {
NNFunctionNN<PathUtils.Step<GameObject>, Double> costFunction = new NNFunctionNN<PathUtils.Step<GameObject>, Double>() {
@Nonnull
@Override
- public Double apply(@Nonnull final PathUtils.Step<GameObject> input) {
+ public Double apply(@Nonnull final PathUtils.Step<GameObject> gameObjectStep) {
return 1d;
}
};
@@ -95,8 +95,8 @@ public Double apply(@Nonnull final PathUtils.Step<GameObject> input) {
return FluentIterable.from( neighbour.getLocation().get().neighbours() ).transform( new NFunctionNN<Tile, GameObject>() {
@Nullable
@Override
- public GameObject apply(@Nonnull final Tile input) {
- return input.getContents().orNull();
+ public GameObject apply(@Nonnull final Tile tile) {
+ return tile.getContents().orNull();
}
} ).filter( Predicates.notNull() );
}
View
28 omicron-core/src/main/java/com/lyndir/omicron/api/model/Game.java
@@ -61,13 +61,13 @@ private Game(final Size levelSize, final Iterable<Player> players, final Iterabl
Map<ResourceType, Integer> remainingResources = new EnumMap<>( ResourceType.class );
remainingResources.putAll( FluentIterable.from( levels ).transformAndConcat( new Function<Level, Iterable<ResourceType>>() {
@Override
- public Iterable<ResourceType> apply(final Level input) {
- return input.getType().getSupportedResources();
+ public Iterable<ResourceType> apply(final Level level) {
+ return level.getType().getSupportedResources();
}
} ).toMap( new Function<ResourceType, Integer>() {
@Override
- public Integer apply(final ResourceType input) {
- return resourceConfig.quantity( input );
+ public Integer apply(final ResourceType resourceType) {
+ return resourceConfig.quantity( resourceType );
}
} ) );
while (true) {
@@ -91,8 +91,8 @@ public Integer apply(final ResourceType input) {
new NNFunctionNN<Tile, Iterable<Tile>>() {
@Nonnull
@Override
- public Iterable<Tile> apply(@Nonnull final Tile input) {
- return input.neighbours();
+ public Iterable<Tile> apply(@Nonnull final Tile tile) {
+ return tile.neighbours();
}
} );
@@ -135,8 +135,8 @@ public GameController getController() {
public Level getLevel(final LevelType levelType) {
return FluentIterable.from( levels ).firstMatch( new Predicate<Level>() {
@Override
- public boolean apply(final Level input) {
- return input.getType() == levelType;
+ public boolean apply(final Level level) {
+ return level.getType() == levelType;
}
} ).get();
}
@@ -229,8 +229,8 @@ public Builder setLevelSize(final Size levelSize) {
public Builder setPlayer(final PlayerKey playerKey, final String name, final Color primaryColor, final Color secondaryColor) {
IPlayer existingPlayer = Iterables.find( players, new PredicateNN<IPlayer>() {
@Override
- public boolean apply(@Nonnull final IPlayer input) {
- return input.hasKey( playerKey );
+ public boolean apply(@Nonnull final IPlayer player) {
+ return player.hasKey( playerKey );
}
}, null );
if (existingPlayer != null)
@@ -244,8 +244,8 @@ public boolean apply(@Nonnull final IPlayer input) {
public Builder addPlayer(final IPlayer player) {
IPlayer existingPlayer = Iterables.find( players, new PredicateNN<IPlayer>() {
@Override
- public boolean apply(@Nonnull final IPlayer input) {
- return input.getPlayerID() == player.getPlayerID();
+ public boolean apply(@Nonnull final IPlayer aPlayer) {
+ return aPlayer.getPlayerID() == player.getPlayerID();
}
}, null );
Preconditions.checkState( existingPlayer == null, "A player with this player's ID has already been added: %s", existingPlayer );
@@ -361,8 +361,8 @@ public void addUnits(final IGame game, final IPlayer player) {
GameObject engineer = new GameObject( UnitTypes.ENGINEER, coreGame, corePlayer );
engineer.onModule( ModuleType.CONTAINER, new PredicateNN<ContainerModule>() {
@Override
- public boolean apply(@Nonnull final ContainerModule input) {
- return input.getResourceType() == ResourceType.METALS;
+ public boolean apply(@Nonnull final ContainerModule module) {
+ return module.getResourceType() == ResourceType.METALS;
}
} ).addStock( Integer.MAX_VALUE );
engineerTile.get().setContents( engineer );
View
8 omicron-core/src/main/java/com/lyndir/omicron/api/model/GameController.java
@@ -240,11 +240,11 @@ else if (playerCondition.apply( gameListenerOwner ))
GameListener fireIfObservable(@Nonnull final ITile location) {
return fireIfPlayer( new PredicateNN<Player>() {
@Override
- public boolean apply(@Nonnull final Player input) {
+ public boolean apply(@Nonnull final Player player) {
return Security.godRun( new Job<Boolean>() {
@Override
public Boolean execute() {
- return input.canObserve( location ).isTrue();
+ return player.canObserve( location ).isTrue();
}
} );
}
@@ -260,11 +260,11 @@ public Boolean execute() {
GameListener fireIfObservable(@Nonnull final IGameObject gameObject) {
return fireIfPlayer( new PredicateNN<Player>() {
@Override
- public boolean apply(@Nonnull final Player input) {
+ public boolean apply(@Nonnull final Player player) {
return Security.godRun( new Job<Boolean>() {
@Override
public Boolean execute() {
- return input.canObserve( gameObject ).isTrue();
+ return player.canObserve( gameObject ).isTrue();
}
} );
}
View
12 omicron-core/src/main/java/com/lyndir/omicron/api/model/MobilityModule.java
@@ -175,15 +175,15 @@ public Movement movement(final ITile target)
// Initialize path finding data functions.
PredicateNN<Tile> foundFunction = new PredicateNN<Tile>() {
@Override
- public boolean apply(@Nonnull final Tile input) {
- return isEqual( input, target );
+ public boolean apply(@Nonnull final Tile tile) {
+ return isEqual( tile, target );
}
};
NNFunctionNN<Step<Tile>, Double> costFunction = new NNFunctionNN<Step<Tile>, Double>() {
@Nonnull
@Override
- public Double apply(@Nonnull final Step<Tile> input) {
- if (!input.getTo().checkAccessible())
+ public Double apply(@Nonnull final Step<Tile> tileStep) {
+ if (!tileStep.getTo().checkAccessible())
return Double.MAX_VALUE;
return stepCost;
@@ -192,8 +192,8 @@ public Double apply(@Nonnull final Step<Tile> input) {
NNFunctionNN<Tile, Iterable<Tile>> neighboursFunction = new NNFunctionNN<Tile, Iterable<Tile>>() {
@Nonnull
@Override
- public Iterable<Tile> apply(@Nonnull final Tile input) {
- return input.neighbours();
+ public Iterable<Tile> apply(@Nonnull final Tile tile) {
+ return tile.neighbours();
}
};
View
8 omicron-core/src/main/java/com/lyndir/omicron/api/model/Player.java
@@ -156,8 +156,8 @@ void removeObject(final IGameObject gameObject) {
if (lostObject != null)
getController().getGameController().fireIfPlayer( new PredicateNN<Player>() {
@Override
- public boolean apply(@Nonnull final Player input) {
- return ObjectUtils.isEqual( Player.this, input );
+ public boolean apply(@Nonnull final Player player) {
+ return ObjectUtils.isEqual( Player.this, player );
}
} ).onPlayerLostObject( this, gameObject );
}
@@ -170,8 +170,8 @@ void addObjects(final IGameObject gameObject) {
if (previousObject == null)
getController().getGameController().fireIfPlayer( new PredicateNN<Player>() {
@Override
- public boolean apply(@Nonnull final Player input) {
- return ObjectUtils.isEqual( Player.this, input );
+ public boolean apply(@Nonnull final Player player) {
+ return ObjectUtils.isEqual( Player.this, player );
}
} ).onPlayerGainedObject( this, gameObject );
}
View
3  omicron-core/src/test/resources/logback.xml
@@ -2,10 +2,11 @@
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
- <Pattern>%-8relative %22c{0} [%-5level] %msg%n</Pattern>
+ <Pattern>%-4relative | %15c{0}@%-5thread | %-5level | %msg%n</Pattern>
</layout>
</appender>
+ <logger name="com.lyndir" level="DEBUG" />
<logger name="com.lyndir.omicron" level="TRACE" />
<root level="INFO">
View
12 omicron-web/src/main/java/com/lyndir/omicron/webapp/resource/GameBuilderResource.java
@@ -82,8 +82,8 @@ public GetResponse(final IGame.IBuilder gameBuilder) {
players = Collections2.transform( gameBuilder.getPlayers(), new NNFunctionNN<IPlayer, HumanPlayer>() {
@Nonnull
@Override
- public HumanPlayer apply(@Nonnull final IPlayer input) {
- return new HumanPlayer( input );
+ public HumanPlayer apply(@Nonnull final IPlayer player) {
+ return new HumanPlayer( player );
}
} );
victoryConditions = gameBuilder.getVictoryConditions();
@@ -126,10 +126,10 @@ public void handle(@Nonnull final IGame.IBuilder gameBuilder, @Nonnull final Use
public HumanPlayer() {
}
- public HumanPlayer(final IPlayer input) {
- name = input.getName();
- primaryColor = input.getPrimaryColor();
- secondaryColor = input.getSecondaryColor();
+ public HumanPlayer(final IPlayer player) {
+ name = player.getName();
+ primaryColor = player.getPrimaryColor();
+ secondaryColor = player.getSecondaryColor();
}
String name;
View
31 omicron-web/src/main/resources/logback.xml
@@ -1,15 +1,16 @@
-<configuration>
-
- <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <layout class="ch.qos.logback.classic.PatternLayout">
- <Pattern>%-4relative | %15c{0}@%-5thread | %-5level | %msg%n</Pattern>
- </layout>
- </appender>
-
- <logger name="com.lyndir" level="DEBUG" />
-
- <root level="info">
- <appender-ref ref="STDOUT" />
- </root>
-
-</configuration>
+<configuration>
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <Pattern>%-4relative | %15c{0}@%-5thread | %-5level | %msg%n</Pattern>
+ </layout>
+ </appender>
+
+ <logger name="com.lyndir" level="INFO" />
+ <logger name="com.lyndir.omicron" level="DEBUG" />
+
+ <root level="INFO">
+ <appender-ref ref="STDOUT" />
+ </root>
+
+</configuration>
Please sign in to comment.
Something went wrong with that request. Please try again.