Skip to content

Commit

Permalink
playtesting
Browse files Browse the repository at this point in the history
  • Loading branch information
tukkek committed Oct 9, 2017
1 parent a4b3901 commit d23c5c1
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 54 deletions.
3 changes: 1 addition & 2 deletions javelin/JavelinApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ void loop() {
EndBattle.end();
Javelin.app.fight = null;
}
// }
}
}

Expand Down Expand Up @@ -315,7 +314,7 @@ void preparedebug() {
m.xp = new BigDecimal(Preferences.DEBUGSXP / 100f);
}
}
if (Preferences.DEBUGRUBIES != null) {
if (Preferences.DEBUGRUBIES != null && Haxor.singleton != null) {
Haxor.singleton.rubies = Preferences.DEBUGRUBIES;
}
}
Expand Down
15 changes: 13 additions & 2 deletions javelin/controller/ai/AiThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class AiThread extends Thread {
public int depth;
List<ChanceNode> result;
final Random random;
BattleAi ai;

public AiThread(BattleState state, long randomseed) {
super(group, (Runnable) null);
Expand All @@ -47,7 +48,8 @@ public static ThreadGroup regroup() {
@Override
public void run() {
try {
result = new BattleAi(depth).alphaBetaSearch(state);
ai = new BattleAi(depth);
result = ai.alphaBetaSearch(state);
onend();
} catch (StopThinking e) {
// abort
Expand All @@ -71,12 +73,21 @@ synchronized private void onend() {
}
AiThread.FINISHED.put(depth, result);
if (!ThreadManager.interrupting && ThreadManager.working
&& depthincremeneter <= ThreadManager.MAXIMUMDEPTH) {
&& !terminate()) {
setdepth();
run();
}
}

private boolean terminate() {
for (ChanceNode c : result) {
if (!ai.terminalTest(c.n)) {
return false;
}
}
return true;
}

static public void checkinterrupted() {
if (Thread.interrupted() || !ThreadManager.working
|| ThreadManager.interrupting) {
Expand Down
2 changes: 1 addition & 1 deletion javelin/controller/ai/BattleAi.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static float measuredistances(List<Combatant> us, List<Combatant> them) {
@Override
public boolean terminalTest(final Node node) {
final BattleState state = (BattleState) node;
return state.getredTeam().isEmpty() || state.getblueTeam().isEmpty();
return state.redTeam.isEmpty() || state.blueTeam.isEmpty();
}

@Override
Expand Down
15 changes: 2 additions & 13 deletions javelin/controller/ai/ThreadManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import javax.swing.JOptionPane;

import javelin.Javelin;
import javelin.controller.action.ai.Flee;
import javelin.controller.action.world.ShowOptions;
import javelin.controller.ai.cache.AiCache;
import javelin.controller.db.Preferences;
Expand All @@ -24,13 +23,6 @@
* @author alex
*/
public class ThreadManager {
static final boolean SINGLETHREAD = false;
/**
* This is requried so some actions don't cause the game to consume too much
* memory (such as {@link Flee}, which "resolves" the battle. A value 10
* times the target depth should be more than enough.
*/
static final int MAXIMUMDEPTH = 5 * 10;
static final Thread MAIN = Thread.currentThread();
static final ArrayList<Integer> BATTLERECORD = new ArrayList<Integer>();

Expand Down Expand Up @@ -76,8 +68,7 @@ public static List<ChanceNode> think(BattleState state) {
AiCache.clear();
AiThread.depthincremeneter = 1;
AiThread.reset();
int nthreads = Javelin.DEBUG && SINGLETHREAD ? 1
: Preferences.MAXTHREADS;
int nthreads = Preferences.MAXTHREADS;
long seed = RPG.rand.nextLong();
for (int i = 0; i < nthreads; i++) {
AiThread.STARTED.add(new AiThread(state, seed));
Expand All @@ -101,9 +92,7 @@ static void analyze(final long start, int depth) {
float miliseconds = (now() - start);
checkperformance(miliseconds);
final float elapsed = miliseconds / 1000f;
String hitmax = depth == MAXIMUMDEPTH ? " (max)" : "";
System.out.println(
elapsed + " seconds elapsed. Depth: " + depth + hitmax);
System.out.println(elapsed + " seconds elapsed. Depth: " + depth);
BATTLERECORD.add(depth);
}

Expand Down
17 changes: 7 additions & 10 deletions javelin/controller/ai/valueselector/ValueSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,28 +94,25 @@ public Entry getValue(final Entry previous,
Entry chosen = previous;
float a = alpha;
float b = beta;
Iterable<List<ChanceNode>> sucessors =
AiCache.getcache(previous.node, index);
Iterable<List<ChanceNode>> sucessors = AiCache.getcache(previous.node,
index);
int i = -1;
for (final List<ChanceNode> cns : sucessors) {
i += 1;
ArrayList<Integer> newindex = (ArrayList<Integer>) index.clone();
newindex.add(i);
// final Float utility = AiCache.getutility(newindex, ai, cns);
for (final ChanceNode cn : cns) {
final BattleState state = (BattleState) cn.n;
final ValueSelector selector = ai.getplayer(state);
Entry outcomeState = selector.getValue(
new Entry(state, selector.failure, cns), ai, depth, a,
b, newindex);
if (ValueSelector.DEBUGLOG) {
ValueSelector.LOG
.append("\n" + ident
+ (selector == ai.maxValueSelector ? "MAX"
: "MIN")
+ (outcomeState.value >= 0 ? "+" : "")
+ outcomeState.value + "|"
+ cn.action.replaceAll("\n", ","));
ValueSelector.LOG.append("\n" + ident
+ (selector == ai.maxValueSelector ? "MAX" : "MIN")
+ (outcomeState.value >= 0 ? "+" : "")
+ outcomeState.value + "|"
+ cn.action.replaceAll("\n", ","));
}
outcomeState = outcomeState.value == chosen.value ? chosen
: returnBest(chosen, outcomeState);
Expand Down
10 changes: 5 additions & 5 deletions javelin/controller/challenge/RewardCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static double getcharacterxp(int eldifference, final int nsurvivors) {

static double getpartyxp(final int eldifference, final int nsurvivors) {
return nsurvivors * .8 * getcharacterxp(eldifference, nsurvivors)
* World.scenario.speed / 1000.0;
* World.scenario.rewardbonus / 1000.0;
}

/**
Expand All @@ -137,7 +137,7 @@ public static int getgold(final float cr) {
if (cr <= 0) {
return 0;
}
return Math.round(cr * cr * cr * 7.5f * World.scenario.speed);
return Math.round(cr * cr * cr * 7.5f * World.scenario.rewardbonus);
}

/**
Expand Down Expand Up @@ -194,9 +194,9 @@ public static String rewardxp(List<Combatant> originalblue,
int eldifference = Math.round(elred - elblue);
double partycr = getpartyxp(eldifference, originalblue.size()) * bonus;
distributexp(originalblue, partycr);
return "Party wins "
+ new BigDecimal(100 * partycr).setScale(0, RoundingMode.UP)
+ "XP!";
BigDecimal xp = new BigDecimal(100 * partycr).setScale(0,
RoundingMode.UP);
return "Party wins " + xp + "XP!";
}

/**
Expand Down
5 changes: 2 additions & 3 deletions javelin/controller/exception/battle/EndBattle.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ static void updateoriginal(List<Combatant> originalteam) {
for (final Combatant inbattle : update) {
int originali = originalteam.indexOf(inbattle);
if (originali >= 0) {
Combatant original = originalteam.get(originali);
update(inbattle, original);
inbattle.transferconditions(original);
update(inbattle, originalteam.get(originali));
}
}
}
Expand All @@ -132,6 +130,7 @@ static void update(final Combatant from, final Combatant to) {
to.hp = 1;
}
copyspells(from, to);
from.transferconditions(to);
}

static void copyspells(final Combatant from, final Combatant to) {
Expand Down
2 changes: 1 addition & 1 deletion javelin/controller/scenario/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ record = true;
dominationwin = false;
startingfeatures = size * size / 5;
simpletroves = false;
speed = 1;
rewardbonus = 1;
}

@Override
Expand Down
12 changes: 9 additions & 3 deletions javelin/controller/scenario/Scenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javelin.Javelin;
import javelin.controller.action.world.Guide;
import javelin.controller.action.world.WorldMove;
import javelin.controller.challenge.RewardCalculator;
import javelin.controller.db.StateManager;
import javelin.controller.fight.RandomEncounter;
import javelin.controller.fight.minigame.Minigame;
Expand All @@ -32,8 +33,10 @@
import javelin.model.world.location.dungeon.Chest;
import javelin.model.world.location.fortification.Fortification;
import javelin.model.world.location.fortification.Trove;
import javelin.model.world.location.order.Order;
import javelin.model.world.location.town.Town;
import javelin.model.world.location.town.labor.Deck;
import javelin.model.world.location.town.labor.Labor;
import javelin.model.world.location.town.labor.military.RealmAcademy;
import javelin.model.world.location.town.labor.productive.Shop;
import javelin.model.world.location.unique.Haxor;
Expand Down Expand Up @@ -148,10 +151,13 @@ public boolean record = false;
*/
public boolean randomrealms = true;
/**
* Overall speed at which the strategic context should progress. Also
* affects rewards.
* Affect labor and training speeds and amounts for XP and gold rewards.
*
* @see Labor#work(float)
* @see RewardCalculator
* @see Order
*/
public int speed = 2;
public int rewardbonus = 3;

/**
* @return Starting encounter level for each hostile town in
Expand Down
10 changes: 3 additions & 7 deletions javelin/model/state/BattleState.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import javelin.Javelin;
import javelin.controller.Point;
import javelin.controller.action.ai.Flee;
import javelin.controller.ai.ActionProvider;
import javelin.controller.ai.ChanceNode;
import javelin.controller.ai.Node;
Expand Down Expand Up @@ -47,10 +46,7 @@ public enum Vision {
public ArrayList<Combatant> blueTeam;
/** Computer units. */
public ArrayList<Combatant> redTeam;
/**
* Units that ran away from the fight. Computer units that {@link Flee} are
* not stored here.
*/
/** Units that ran away from the fight. */
public ArrayList<Combatant> fleeing;
/** Dead and unconscious units. */
public ArrayList<Combatant> dead;
Expand Down Expand Up @@ -223,11 +219,11 @@ public Combatant getcombatant(final int x, final int y) {
* Removes this unit from battle.
*/
public void remove(Combatant c) {
c = clone(c);
// c = clone(c);
if (!blueTeam.remove(c)) {
redTeam.remove(c);
}
if (c == next) {
if (c.equals(next)) {
next();
}
}
Expand Down
2 changes: 1 addition & 1 deletion javelin/model/world/location/order/CraftingOrder.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public CraftingOrder(Item i, OrderQueue queue) {
item = i.clone();
if (queue != null && !queue.queue.isEmpty()) {
long hours = queue.last().completionat - Squad.active.hourselapsed;
completionat += hours / World.scenario.speed;
completionat += hours / World.scenario.rewardbonus;
}
}
}
2 changes: 1 addition & 1 deletion javelin/model/world/location/order/TrainingOrder.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class TrainingOrder extends Order {
/** Constructor. See {@link Order#Order(long, String)}. */
public TrainingOrder(Combatant trained, ArrayList<Item> equipment,
String namep, float xpcostp, Combatant original) {
super(Math.round(xpcostp * 24 * UPGRADETIME / World.scenario.speed),
super(Math.round(xpcostp * 24 * UPGRADETIME / World.scenario.rewardbonus),
namep);
this.trained = trained;
this.equipment = equipment;
Expand Down
2 changes: 1 addition & 1 deletion javelin/model/world/location/town/Town.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void host() {
@Override
public void turn(long time, WorldScreen screen) {
final float labor = (population + RPG.randomize(population) / 10f)
* World.scenario.speed;
* World.scenario.rewardbonus;
governor.work(labor * DAILYLABOR, getdistrict());
}

Expand Down
2 changes: 2 additions & 0 deletions javelin/view/screen/InfoScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ static public Character feedback() {
return feedback();
case KeyEvent.VK_ESCAPE:
return ESCAPE;
case KeyEvent.VK_TAB:
return '\t';
}
return Character.valueOf(input.getKeyChar());
}
Expand Down
14 changes: 14 additions & 0 deletions javelin/view/screen/SquadScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;

import javelin.Javelin;
import javelin.controller.challenge.RewardCalculator;
import javelin.controller.comparator.MonsterNameComparator;
import javelin.model.unit.Monster;
import javelin.model.unit.Squad;
Expand Down Expand Up @@ -47,9 +48,22 @@ public class SquadScreen extends InfoScreen {
ArrayList<Combatant> select() {
page(0);
World.scenario.upgradesquad(squad);
Squad.active.gold = getstartinggold();
return squad;
}

public int getstartinggold() {
int gold = 0;
for (Combatant c : squad) {
float level = c.source.challengerating - 1;
if (level >= 1) {
gold += RewardCalculator
.calculatepcequipment(Math.round(level));
}
}
return gold;
}

private void page(int index) {
text = "Available monsters:\n";
int next = index + MONSTERPERPAGE;
Expand Down
11 changes: 7 additions & 4 deletions javelin/view/screen/town/SelectScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,17 @@ protected List<Option> getfixedoptions() {
public abstract List<Option> getoptions();

/**
* @param feedback
* @param c
* Given the user-input key
* @return the index of that key in {@link #KEYS}.
*/
public static int convertkeytoindex(char feedback) {
public static int convertkeytoindex(char c) {
if (c == '\t') {
return 0;
}
for (int i = 0; i < KEYS.length; i++) {
char c = KEYS[i];
if (c == feedback) {
char key = KEYS[i];
if (key == c) {
return i;
}
}
Expand Down

0 comments on commit d23c5c1

Please sign in to comment.