Skip to content

Commit

Permalink
Merge pull request #55 from EntelectChallenge/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
DaanKeun committed May 11, 2018
2 parents 74e8211 + 5b3d0ef commit a4bd822
Show file tree
Hide file tree
Showing 109 changed files with 3,207 additions and 414 deletions.
2 changes: 1 addition & 1 deletion game-engine-interface/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>za.co.entelect.challenge</groupId>
<artifactId>game-engine-interface</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>

<distributionManagement>
<repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
public interface GameEngine {

boolean isGameComplete(GameMap gameMap);

}
4 changes: 2 additions & 2 deletions game-engine/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>game-engine</artifactId>
<groupId>za.co.entelect.challenge</groupId>
<version>1.0.1</version>
<version>1.1.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -27,7 +27,7 @@
<dependency>
<groupId>za.co.entelect.challenge</groupId>
<artifactId>domain</artifactId>
<version>1.0.1</version>
<version>1.1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

public class TowerDefenseGameEngine implements GameEngine {

public TowerDefenseGameEngine(String configLocation) {
GameConfig.initConfig(configLocation);
}

@Override
public boolean isGameComplete(GameMap gameMap) {
TowerDefenseGameMap towerDefenseGameMap = (TowerDefenseGameMap) gameMap;
Expand All @@ -16,4 +20,5 @@ public boolean isGameComplete(GameMap gameMap) {

return (towerDefenseGameMap.getDeadPlayers().size() > 0);
}

}
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
package za.co.entelect.challenge.core.entities;

import za.co.entelect.challenge.config.GameConfig;
import za.co.entelect.challenge.entities.BuildingStats;
import za.co.entelect.challenge.enums.BuildingType;
import za.co.entelect.challenge.factories.BuildingFactory;

import java.util.Arrays;
import java.util.HashMap;

public class GameDetails {

private int round;
private int mapWidth;
private int mapHeight;
private HashMap<BuildingType, Integer> buildingPrices;
private int roundIncomeEnergy;

@Deprecated
private HashMap<BuildingType, Integer> buildingPrices = new HashMap<>();

public GameDetails(int round){
private HashMap<BuildingType, BuildingStats> buildingsStats = new HashMap<>();

public GameDetails(int round) {
this.round = round;
this.mapWidth = GameConfig.getMapWidth();
this.mapHeight = GameConfig.getMapHeight();
this.roundIncomeEnergy = GameConfig.getRoundIncomeEnergy();

Arrays.asList(BuildingType.values()).forEach(bt -> buildingPrices.put(bt, BuildingFactory.createBuildingStats(bt).price));

buildingPrices = new HashMap<>();
buildingPrices.put(BuildingType.DEFENSE, GameConfig.getDefensePrice());
buildingPrices.put(BuildingType.ATTACK, GameConfig.getAttackPrice());
buildingPrices.put(BuildingType.ENERGY, GameConfig.getEnergyPrice());
Arrays.stream(BuildingType.values()).forEach(bt -> buildingsStats.put(bt, BuildingFactory.createBuildingStats(bt)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import za.co.entelect.challenge.config.GameConfig;
import za.co.entelect.challenge.core.entities.CellStateContainer;
import za.co.entelect.challenge.entities.Building;
import za.co.entelect.challenge.entities.Missile;
import za.co.entelect.challenge.entities.TowerDefenseGameMap;
import za.co.entelect.challenge.entities.TowerDefensePlayer;
import za.co.entelect.challenge.entities.*;
import za.co.entelect.challenge.enums.BuildingType;
import za.co.entelect.challenge.enums.PlayerType;
import za.co.entelect.challenge.factories.BuildingFactory;
import za.co.entelect.challenge.game.contracts.game.GamePlayer;
import za.co.entelect.challenge.game.contracts.map.GameMap;
import za.co.entelect.challenge.game.contracts.renderer.GameMapRenderer;
Expand All @@ -28,10 +27,11 @@ public String render(GameMap gameMap, GamePlayer gamePlayer) {
stringBuilder.append("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");
stringBuilder.append("\n");

stringBuilder.append("****** BUILDING PRICES ******\n");
stringBuilder.append("ATTACK : " + GameConfig.getAttackPrice() + "\n");
stringBuilder.append("DEFEND : " + GameConfig.getDefensePrice() + "\n");
stringBuilder.append("ENERGY : " + GameConfig.getEnergyPrice() + "\n");
stringBuilder.append("****** BUILDING STATS ******\n");
stringBuilder.append("type;" + BuildingStats.getTextHeader() + "\n");
stringBuilder.append("ATTACK;" + BuildingFactory.createBuildingStats(BuildingType.ATTACK) + "\n");
stringBuilder.append("DEFENSE;" + BuildingFactory.createBuildingStats(BuildingType.DEFENSE) + "\n");
stringBuilder.append("ENERGY;" + BuildingFactory.createBuildingStats(BuildingType.ENERGY) + "\n");
stringBuilder.append("*****************************\n");
stringBuilder.append("\n");

Expand Down Expand Up @@ -159,28 +159,9 @@ private String getRowStringForPlayer(CellStateContainer[] row, int y){
return stringBuilderRow.toString();
}

private String padString(String stringToPad, int targetLength, PaddingDirection paddingDirection){
String newString = stringToPad;
int difference = targetLength - stringToPad.length();

for (int i =0; i< difference; i++){
if (paddingDirection == PaddingDirection.LEFT){
newString = " " + newString;
}else{
newString = newString + " ";
}
}

return newString;
}

@Override
public String commandPrompt(GamePlayer gamePlayer) {
return "";
}

private enum PaddingDirection{
LEFT,
RIGHT
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion game-engine/domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>game-engine</artifactId>
<groupId>za.co.entelect.challenge</groupId>
<version>1.0.1</version>
<version>1.1.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ public class GameConfig {

private static Configuration configuration;

static {
Configurations configurations = new Configurations();
public static void initConfig(String configLocation) {
if (configuration == null) {
Configurations configurations = new Configurations();

try {
configuration = configurations.properties(GameConfig.class.getResource("/game-config.properties"));
try {
configuration = configurations.properties(configLocation);

} catch (ConfigurationException e) {
throw new RuntimeException("Unable to initialise configuration, please have a look at the inner exception.", e);
} catch (ConfigurationException e) {
throw new RuntimeException("Unable to initialise configuration, please have a look at the inner exception.", e);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package za.co.entelect.challenge.entities;

public class BuildingStats {

public int health;
public int constructionTime;
public int price;
public int weaponDamage;
public int weaponSpeed;
public int weaponCooldownPeriod;
public int energyGeneratedPerTurn;
public int destroyMultiplier;
public int constructionScore;

public BuildingStats(Building building) {
this.health = building.getHealth();
this.constructionTime = building.getConstructionTimeLeft();
this.price = building.getPrice();
this.weaponDamage = building.getWeaponDamage();
this.weaponSpeed = building.getWeaponSpeed();
this.weaponCooldownPeriod = building.getWeaponCooldownPeriod();
this.destroyMultiplier = building.getDestroyMultiplier();
this.constructionScore = building.getConstructionScore();
this.energyGeneratedPerTurn = building.getEnergyGeneratedPerTurn();
}

public static String getTextHeader() {
return "health;constructionTime;price;weaponDamage;weaponSpeed;weaponCooldownPeriod;energyGeneratedPerTurn;destroyMultiplier;constructionScore";
}

@Override
public String toString() {
return health + ";" +
constructionTime + ";" +
price + ";" +
weaponDamage + ";" +
weaponSpeed + ";" +
weaponCooldownPeriod + ";" +
energyGeneratedPerTurn + ";" +
destroyMultiplier + ";" +
constructionScore + ";";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import za.co.entelect.challenge.config.GameConfig;
import za.co.entelect.challenge.entities.Building;
import za.co.entelect.challenge.entities.BuildingStats;
import za.co.entelect.challenge.enums.BuildingType;
import za.co.entelect.challenge.enums.PlayerType;

Expand Down Expand Up @@ -55,4 +56,9 @@ public static Building createBuilding(int x, int y, BuildingType buildingType, P
return building;
}

public static BuildingStats createBuildingStats(BuildingType buildingType) {
Building building = createBuilding(0, 0, buildingType, PlayerType.A);
return new BuildingStats(building);
}

}
4 changes: 2 additions & 2 deletions game-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>za.co.entelect.challenge</groupId>
<artifactId>game-engine</artifactId>
<version>1.0.1</version>
<version>1.1.1</version>
<modules>
<module>domain</module>
<module>core</module>
Expand All @@ -16,7 +16,7 @@

<properties>
<java.version>1.8</java.version>
<game.engine.interfaces.version>1.0.0</game.engine.interfaces.version>
<game.engine.interfaces.version>1.0.1</game.engine.interfaces.version>
<junit.version>4.12</junit.version>
<apache.commons.configuration.version>2.2</apache.commons.configuration.version>
<gson.version>2.8.2</gson.version>
Expand Down
2 changes: 1 addition & 1 deletion game-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* As a player, you will always be player A.
* The player can only build buildings in their half of the map.
* The coordinates for a cell on the map takes the form of **'X,Y'** starting from 0, e.g. the coordinates **'0,0'** will be the top left cell.
* The entire map, player information, and building information will be visible to both players, including the opposing player's units.
* The entire map, player information, and building information will be visible to both players, including the opposing player's buildings.

**{X} and {Y} will be variable.**

Expand Down
6 changes: 4 additions & 2 deletions game-runner/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"round-state-output-location": "./tower-defence-matches",
"game-config-file-location": "./game-config.properties",
"verbose-mode": true,
"max-runtime-ms": 2000,
"player-a": "../starter-bots/kotlin",
"player-b": "../starter-bots/python3"
"player-a": "../starter-bots/java",
"player-b": "../reference-bot/java"
}
45 changes: 45 additions & 0 deletions game-runner/game-config.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#Game Config
game.config.map-width = 8
game.config.map-height = 4
game.config.max-rounds = 400
game.config.start-energy = 20
game.config.round-income-energy = 5
game.config.starting-health = 100
game.config.health-score-multiplier = 100
game.config.energy-score-multiplier = 1

#Basic Wall Config
game.config.defense.config.health = 20
game.config.defense.config.construction-time-left = 3
game.config.defense.config.price = 30
game.config.defense.config.weapon-damage = 0
game.config.defense.config.weapon-speed = 0
game.config.defense.config.weapon-cooldown-period = 0
game.config.defense.config.icon = D
game.config.defense.config.destroy-multiplier = 1
game.config.defense.config.construction-score = 1
game.config.defense.config.energy-Produced-per-turn = 0

#Basic Turret Config
game.config.attack.config.health = 5
game.config.attack.config.construction-time-left = 1
game.config.attack.config.price = 30
game.config.attack.config.weapon-damage = 5
game.config.attack.config.weapon-speed = 1
game.config.attack.config.weapon-cooldown-period = 3
game.config.attack.config.icon = A
game.config.attack.config.destroy-multiplier = 1
game.config.attack.config.construction-score = 1
game.config.attack.config.energy-Produced-per-turn = 0

#Basic Energy Generator Config
game.config.energy.config.health = 5
game.config.energy.config.construction-time-left = 1
game.config.energy.config.price = 20
game.config.energy.config.weapon-damage = 0
game.config.energy.config.weapon-speed = 0
game.config.energy.config.weapon-cooldown-period = 0
game.config.energy.config.icon = E
game.config.energy.config.destroy-multiplier = 1
game.config.energy.config.construction-score = 1
game.config.energy.config.energy-Produced-per-turn = 3
Loading

0 comments on commit a4bd822

Please sign in to comment.