Commit 3a19921168a0c51986a1a8d244e35ae7f0494ffc

  • avatar
  • Oskari Leppaaho <oskari.leppaaho @gm…l.com> (Committer)
  • Fri Jul 11 12:08:28 EEST 2014
  • avatar
  • Oskari Leppaaho <oskari.leppaaho @gm…l.com> (Author)
  • Fri Jul 11 12:08:28 EEST 2014
Botteja voi nyt evaluoida rinnakkain useita. Liikumislogiikkaa muutettu hieman.

-Liikkumislogiikka: liikkumiskomento annetaan 20 pikseliä halutun kohteen eteen.
	-Näin saadaan yksikkö liikkumaan paremmin halutussa kohdassa, kun haluttu
	 kohta on liikkeessä.
-Lisätty evoluutioon satunnaisvakio (Ephemeral Random Constant, ERC) ja jakofuntio
Source/Java/ThesisAIProject/src/test/StandaloneRmiStarter.java
(32 / 0)
  
1package test;
2
3/**
4 * class to do some common things for client & server to get RMI working
5 *
6 * @author srasul
7 *
8 */
9public class StandaloneRmiStarter {
10
11 /**
12 *
13 * @param clazzToAddToServerCodebase
14 * a class that should be in the java.rmi.server.codebase
15 * property.
16 */
17 public StandaloneRmiStarter(Class clazzToAddToServerCodebase) {
18
19 System.setProperty("java.rmi.server.codebase",
20 clazzToAddToServerCodebase.getProtectionDomain()
21 .getCodeSource().getLocation().toString());
22
23 System.setProperty("java.security.policy",
24 PolicyFileLocator.getLocationOfPolicyFile());
25
26 if (System.getSecurityManager() == null) {
27 System.setSecurityManager(new SecurityManager());
28 }
29 }
30
31
32}
Source/Java/ThesisAIProject/src/test/TestPotentialFunctionProviderStarter.java
(26 / 15)
  
33import java.io.BufferedReader;
44import java.io.IOException;
55import java.io.InputStreamReader;
6import java.rmi.RemoteException;
67import java.rmi.registry.LocateRegistry;
78import java.rmi.registry.Registry;
89import java.rmi.server.UnicastRemoteObject;
10import java.util.ArrayList;
911
1012import thesis.bot.RemoteBotInterface;
13import thesis.bot.RemoteBotStarter;
1114import thesis.evolution.PotentialFunctionProvider;
1215
1316public class TestPotentialFunctionProviderStarter extends RmiStarter {
1417
1518 Registry registry;
19 PotentialFunctionProvider provider;
20// ArrayList<RemoteBotInterface> bots;
1621
1722 public TestPotentialFunctionProviderStarter() {
1823 super(PotentialFunctionProvider.class);
2626 @Override
2727 public void doCustomRmiHandling() {
2828 try {
29 PotentialFunctionProvider provider = new TestPotentialFunctionProvider();
29 provider = new TestPotentialFunctionProvider();
3030 PotentialFunctionProvider providerStub = (PotentialFunctionProvider)UnicastRemoteObject.exportObject(provider, 0);
3131
3232 registry = LocateRegistry.getRegistry();
3737 }
3838 }
3939
40 public void connectClient(String name) {
40 public RemoteBotInterface connectClient(String name) {
4141 try {
42 registry.lookup(RemoteBotInterface.SERVICE_NAME + name);
42 return (RemoteBotInterface)registry.lookup(RemoteBotInterface.SERVICE_NAME + name);
4343 } catch (Exception e ) {
4444 // TODO Auto-generated catch block
4545 e.printStackTrace();
4646 }
47 return null;
4748 }
4849
49 public static void main(String[] args) {
50 public static void main(String[] args) throws RemoteException {
5051 TestPotentialFunctionProviderStarter starter = new TestPotentialFunctionProviderStarter();
5152
53 RemoteBotInterface client1;
54 RemoteBotInterface client2;
55
5256 BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
5357
5458 System.out.println("Press enter when ready to initialize next client >");
6464 + "(for stepping).");
6565 e.printStackTrace();
6666 }
67 starter.connectClient("1");
68 System.out.println("Press enter when ready to initialize next client >");
69 try {
70 buffer.readLine();
71 } catch (IOException e) {
72 System.err.println("Something went wrong when waiting for \n"
73 + "the user to press enter on the console\n"
74 + "(for stepping).");
75 e.printStackTrace();
76 }
77 starter.connectClient("2");
67 client1 = starter.connectClient("0");
68// System.out.println("Press enter when ready to initialize next client >");
69// try {
70// buffer.readLine();
71// } catch (IOException e) {
72// System.err.println("Something went wrong when waiting for \n"
73// + "the user to press enter on the console\n"
74// + "(for stepping).");
75// e.printStackTrace();
76// }
77// starter.connectClient("2");
7878
79 System.out.println("Get score from client 1");
80 System.out.println(client1.getRoundScore(starter.provider));
7981 }
8082}
Source/Java/ThesisAIProject/src/test/TestRemoteBotStarter.java
(2 / 2)
  
3131 System.out.println("Bind " + RemoteBotInterface.SERVICE_NAME + currentName);
3232
3333
34 PotentialFunctionProvider provider = (PotentialFunctionProvider)registry.lookup(PotentialFunctionProvider.SERVICE_NAME);
35 System.out.println("Remote bot evaluating using remote potential: " + provider.evaluateFunction(5));
34// PotentialFunctionProvider provider = (PotentialFunctionProvider)registry.lookup(PotentialFunctionProvider.SERVICE_NAME);
35// System.out.println("Remote bot evaluating using remote potential: " + provider.evaluateFunction(5));
3636 }
3737 catch(Exception e) {
3838 e.printStackTrace();
Source/Java/ThesisAIProject/src/thesis/bot/Controller.java
(50 / 27)
  
44import java.util.ArrayList;
55import java.util.List;
66
7import thesis.evolution.RTSSmallScaleCombatProblem;
7import thesis.evolution.PotentialFunctionProvider;
8import thesis.evolution.ThesisProblem;
89import jnibwapi.BWAPIEventListener;
910import jnibwapi.JNIBWAPI;
1011import jnibwapi.Position;
2222 *
2323 * @author Oskari Leppaho
2424 */
25public class Controller implements BWAPIEventListener, Runnable {
25public class Controller implements BWAPIEventListener, Runnable,
26 RemoteBotInterface {
2627 public volatile boolean isRoundResultRetrievable = false;
2728
2829 final static boolean DEBUG_INFO = true;
3131 * The maximum distance of the move command from the unit position.
3232 */
3333 final static int MOVE_DISTANCE = 45;
34 final static int GAME_SPEED = 0;
34 final static int GAME_SPEED = 25;
3535 final static String BOT_NAME = "Thesis bot v4";
3636 final static boolean GUI = true;
3737
6060 int score;
6161 /** Tells if the evolution has started (all threads have been setup */
6262 boolean isStarted = false;
63
63
6464 boolean isMatchStarted = false;
6565
6666 /** reference to JNI-BWAPI */
67 private final JNIBWAPI bwapi;
67 final JNIBWAPI bwapi;
6868
6969 private Visualizer visualizer;
7070 private PotentialCalculator potentialCalculator;
9393 public Controller() {
9494 bwapi = new JNIBWAPI(this, true);
9595 visualizer = new Visualizer(bwapi, this);
96 potentialCalculator = new PotentialCalculator(this);
96 potentialCalculator = new PotentialCalculator(this);
97 WaitForConnection();
9798 }
98
99
99100 public void WaitForConnection() {
100101 if (bwThread == null) {
101102 bwThread = new Thread(this);
104104 }
105105 while (true) {
106106 try {
107 Thread.sleep(100);
107 Thread.sleep(100);
108108 } catch (InterruptedException e) {
109109 System.err.println("Constructor of the controller was "
110110 + "interrupted");
122122 * client if it hasn't been started yet.
123123 *
124124 * @return Score for the round.
125 * @throws InterruptedException
126 * If interrupted.
127125 */
128 public int getRoundScore(RTSSmallScaleCombatProblem problem)
129 throws InterruptedException {
126 public int getRoundScore(PotentialFunctionProvider problem) {
127 System.out.println("Get round score (with potential provider) called");
130128 isStarted = true;
131129 potentialCalculator.setProblem(problem);
132130 while (true) {
133 Thread.sleep(100);
131 try {
132 Thread.sleep(100);
133 } catch (InterruptedException e) {
134 System.err.println("Get round score waiting interrupted:");
135 e.printStackTrace();
136 }
134137 if (isRoundResultRetrievable) {
135138 isRoundResultRetrievable = false;
136139 return score;
213213 */
214214 @Override
215215 public void matchFrame() {
216 while (!isStarted) {
217 try {
218 Thread.sleep(1000);
219 } catch (InterruptedException e) {
220 System.err.println("Match frame interrupted while waiting"
221 + " for start signal");
222 e.printStackTrace();
223 }
224 }
216 // while (!isStarted) {
217 // try {
218 // Thread.sleep(1000);
219 // System.out.println("Waiting for the first score request");
220 // } catch (InterruptedException e) {
221 // System.err.println("Match frame interrupted while waiting"
222 // + " for start signal");
223 // e.printStackTrace();
224 // }
225 // }
226 //--------------debug
227 //System.out.println("Frame " + bwapi.getFrameCount());
228 //-------------enddebug
225229 if (isStepThroughEnabled) {
226230 waitForEnterOnConsole();
227231 }
236236 checkForRoundEnd();
237237 double currentPotential;
238238
239 visualizer.highlightEnemies();
239 visualizer.highlightUnits();
240240
241241 unitloop: for (Unit u : getMyUnitsNoRevealers()) {
242 visualizer.visualizeDestination(u, isAttackOrderGiven
243 || isAttackInProgress);
244
245242 double[] potentials = potentialCalculator.getPotentialsAround(u);
246243 Position moveDirection = potentialCalculator
247244 .getMoveDirection(potentials);
257257 continue unitloop;
258258 }
259259 }
260 Position moveTo = visualizer.moveDestination = potentialCalculator
260 Position moveTo = potentialCalculator
261261 .getHighestPotentialPositionInDirection(u.getPosition(),
262262 moveDirection, MOVE_DISTANCE);
263
264// double overMove = u.getType().getTopSpeed();
265 double overMove = 20;
266
267 if ((moveDirection.getPX() * moveDirection.getPX() + moveDirection
268 .getPY() * moveDirection.getPY()) == 2) {
269 overMove = (int) (overMove / Math.sqrt(2.0));
270 }
271 Position overMoveVector = new Position(
272 (int) Math.round((moveDirection.getPX() * overMove)),
273 (int) Math.round((moveDirection.getPY() * overMove)));
274
275 moveTo = moveTo.plus(overMoveVector);
263276 u.move(moveTo, false);
277
278 visualizer.visualizeDestination(u, moveTo, isAttackOrderGiven
279 || isAttackInProgress);
264280 } // end unitloop
265281 }
266282
Source/Java/ThesisAIProject/src/thesis/bot/PotentialCalculator.java
(45 / 8)
  
11package thesis.bot;
22
3import thesis.evolution.RTSSmallScaleCombatProblem;
3import java.rmi.RemoteException;
4
5import thesis.evolution.PotentialFunctionProvider;
46import jnibwapi.Position;
57import jnibwapi.Unit;
68
1717public class PotentialCalculator {
1818
1919 Controller bot;
20 RTSSmallScaleCombatProblem problem; // The ECJ evolution problem
20 PotentialFunctionProvider problem; // The ECJ evolution problem
2121
2222 public PotentialCalculator(Controller bot) {
2323 this.bot = bot;
2424 }
2525
26 public void setProblem(RTSSmallScaleCombatProblem problem) {
27 this.problem = problem;
26 public void setProblem(PotentialFunctionProvider problem2) {
27 this.problem = problem2;
2828 }
2929
3030 /**
5454 private double getPotential(double x, double y) {
5555 double potential = 0;
5656
57 Position mapSize = bot.bwapi.getMap().getSize();
58 double distMapBottom = mapSize.getPY() - y;
59 double distMapTop = y;
60 double distMapLeft = x;
61 double distMapRight = mapSize.getPX() - x;
62
5763 for (Unit u : bot.getEnemyUnitsNoRevealers()) {
5864 Position enemyPos = u.getPosition();
5965 double xlen = enemyPos.getPX() - x;
6066 double ylen = enemyPos.getPY() - y;
6167 double enemyDistance = Math.sqrt(xlen * xlen + ylen * ylen);
62 if (problem == null)
63 potential += -(0.05 * enemyDistance - 5)
64 * (0.05 * enemyDistance - 5);
68 if (problem == null)
69 {
70// potential += -(0.05 * enemyDistance - 5) original
71// * (0.05 * enemyDistance - 5);
72// potential += 3 * (enemyDistance * enemyDistance); first evolution run
73// potential += -(enemyDistance - 120) * (enemyDistance - 136);
74// potential -= 1.0 / (0.0001 * distMapBottom);
75// potential -= 1.0 / (0.0001 * distMapTop);
76// potential -= 1.0 / (0.0001 * distMapLeft);
77// potential -= 1.0 / (0.0001 * distMapRight);
78 potential += ((enemyDistance - 96.4901227341802) / (enemyDistance * 191.22811092392067));
79 }
6580 else {
66 potential += problem.evaluateFunction(enemyDistance);
81 try {
82 potential += problem.evaluateFunction(enemyDistance);
83 } catch (RemoteException e) {
84 System.err.println("Remote potential evaluation failed: ");
85 e.printStackTrace();
86 }
6787 }
6888 }
6989 return potential;
180180 if ((dir.getPX() * dir.getPX() + dir.getPY() * dir.getPY()) == 2) {
181181 distance = (int) (distance / Math.sqrt(2.0));
182182 }
183
184 //-------------debug
185// Position enemyPos = new Position(0,0);
186// for (Unit u : bot.getEnemyUnitsNoRevealers()) {
187// enemyPos = u.getPosition();
188// }
189//
190 //-------------enddebug
191
183192 for (int i = 0; i <= distance; i++) {
184193
185194 Position offset = dir.multiply(i);
186195
187196 double currentPotential = getPotential(from.plus(offset));
197
198 //-------------debug
199//
200// System.out.println("Distance: " + enemyPos.getPDistance(from.plus(offset)) + " potential: " + currentPotential);
201 //-------------enddebug
202
188203 if (currentPotential > highestPotential) {
189204 highestPosition = from.plus(offset);
190205 highestPotential = currentPotential;
Source/Java/ThesisAIProject/src/thesis/bot/RemoteBotStarter.java
(40 / 0)
  
1package thesis.bot;
2
3import java.rmi.registry.LocateRegistry;
4import java.rmi.registry.Registry;
5import java.rmi.server.UnicastRemoteObject;
6
7import test.RmiStarter;
8import test.TestRemoteBot;
9import thesis.evolution.PotentialFunctionProvider;
10
11public class RemoteBotStarter extends RmiStarter {
12
13 static String currentName;
14
15 public RemoteBotStarter() {
16 super(RemoteBotInterface.class);
17 }
18
19 public static void main(String[] args) {
20 currentName = args[0];
21 new RemoteBotStarter();
22 }
23
24 @Override
25 public void doCustomRmiHandling() {
26 try {
27 Registry registry = LocateRegistry.getRegistry();
28 RemoteBotInterface remoteBot = new Controller();
29 RemoteBotInterface remoteBotStub = (RemoteBotInterface)UnicastRemoteObject.exportObject(remoteBot, 0);
30
31 registry.rebind(RemoteBotInterface.SERVICE_NAME + currentName, remoteBotStub);
32 System.out.println("Bind " + RemoteBotInterface.SERVICE_NAME + currentName);
33 }
34 catch(Exception e) {
35 e.printStackTrace();
36 }
37
38 }
39
40}
Source/Java/ThesisAIProject/src/thesis/bot/Visualizer.java
(23 / 8)
  
1616 final JNIBWAPI bwapi;
1717 final Controller bot;
1818
19 /** For debugging. */
20 Position moveDestination;
21 /** For debugging. */
2219 Unit attackTarget;
2320
2421 public Visualizer(JNIBWAPI bwapi, Controller bot) {
2626 /**
2727 * Draw an orange circle around the enemy units to highlight them.
2828 */
29 void highlightEnemies() {
29 void highlightUnits() {
30// Position enemyPosition = null;
31// Position myPosition = null;
3032 for (Unit u : bot.getEnemyUnitsNoRevealers()) {
31 bwapi.drawCircle(u.getPosition(), 5, BWColor.Orange, false, false);
33 bwapi.drawCircle(u.getPosition(), 128, BWColor.Orange, false, false);
34// bwapi.drawCircle(u.getPosition(), 120, BWColor.Orange, false, false);
35// bwapi.drawCircle(u.getPosition(), 136, BWColor.Orange, false, false);
36// System.out.println("Enemy position: " + u.getPosition());
37// enemyPosition = u.getPosition();
3238 }
39 for (Unit u : bot.getMyUnitsNoRevealers()) {
40 bwapi.drawCircle(u.getPosition(), 2, BWColor.Blue, false, false);
41 //bwapi.drawCircle(u.getPosition(), 136, BWColor.Orange, false, false);
42// System.out.println("Enemy position: " + u.getPosition());
43// myPosition = u.getPosition();
44 }
45
46// System.out.println("Distance between units: " + enemyPosition.getPDistance(myPosition));
3347 }
3448
3549 /**
5353 *
5454 * @param u
5555 * The unit to visualize.
56 * @param moveTo
5657 */
57 void visualizeDestination(Unit u, boolean isAttacking) {
58 if (moveDestination != null) {
58 void visualizeDestination(Unit u, Position moveTo, boolean isAttacking) {
59 if (moveTo != null) {
5960 // if (isAttackOrderGiven || isAttackInProgress)
6061 if (isAttacking)
6162 bwapi.drawLine(u.getPosition(), attackTarget.getPosition(),
6263 BWColor.Red, false);
6364 else
64 bwapi.drawLine(u.getPosition(), moveDestination, BWColor.Green,
65 {
66 bwapi.drawLine(u.getPosition(), moveTo, BWColor.Green,
6567 false);
68// System.out.println("Move destination: " + moveDestination);
69 }
6670 }
6771 }
6872
Source/Java/ThesisAIProject/src/thesis/evolution/Div.java
(55 / 0)
  
1/*
2 Copyright 2006 by Sean Luke
3 Licensed under the Academic Free License version 3.0
4 See the file "LICENSE" for more information
5*/
6
7
8package thesis.evolution;
9import ec.*;
10import ec.gp.*;
11
12public class Div extends GPNode
13 {
14 /**
15 *
16 */
17 private static final long serialVersionUID = 1L;
18
19 public String toString() { return "/"; }
20
21/*
22 public void checkConstraints(final EvolutionState state,
23 final int tree,
24 final GPIndividual typicalIndividual,
25 final Parameter individualBase)
26 {
27 super.checkConstraints(state,tree,typicalIndividual,individualBase);
28 if (children.length!=2)
29 state.output.error("Incorrect number of children for node " +
30 toStringForError() + " at " +
31 individualBase);
32 }
33*/
34 public int expectedChildren() { return 2; }
35
36 public void eval(final EvolutionState state,
37 final int thread,
38 final GPData input,
39 final ADFStack stack,
40 final GPIndividual individual,
41 final Problem problem)
42 {
43 double result;
44 DoubleData rd = ((DoubleData)(input));
45
46 children[0].eval(state,thread,input,stack,individual,problem);
47 result = rd.x;
48
49 children[1].eval(state,thread,input,stack,individual,problem);
50 if (-0.001 < rd.x && rd.x < 0.001)
51 rd.x = 1.0;
52 else
53 rd.x = result / rd.x;
54 }
55 }
Source/Java/ThesisAIProject/src/thesis/evolution/Evolve.java
(2 / 2)
  
243243 }
244244
245245 // search for a resource class (we may or may not use this)
246 Class cls = null;
246 Class<?> cls = null;
247247 for(int x=0;x<args.length-1;x++)
248248 if (args[x].equals(A_AT))
249249 try
418418 int[] seeds;
419419 int breedthreads = 1;
420420 int evalthreads = 1;
421 boolean store;
421 //boolean store; Own modification: was not used
422422 int x;
423423
424424 // Should we muzzle stdout and stderr?
Source/Java/ThesisAIProject/src/thesis/evolution/FloatERC.java
(80 / 0)
  
1package thesis.evolution;
2
3import java.io.DataInput;
4import java.io.DataOutput;
5import java.io.IOException;
6
7import ec.EvolutionState;
8import ec.Problem;
9import ec.gp.*;
10import ec.util.Code;
11import ec.util.DecodeReturn;
12
13public class FloatERC extends ERC {
14 /**
15 *
16 */
17 private static final long serialVersionUID = -8817361358581903506L;
18 public double value;
19
20 public String toStringForHumans() {
21 return "" + value;
22 }
23
24 public String encode() {
25 return Code.encode(value);
26 }
27
28 public boolean decode(DecodeReturn ret) {
29 int pos = ret.pos;
30 String data = ret.data;
31 Code.decode(ret);
32 if (ret.type != DecodeReturn.T_DOUBLE) // uh oh! Restore and signal
33 // error.
34 {
35 ret.data = data;
36 ret.pos = pos;
37 return false;
38 }
39 value = ret.d;
40 return true;
41 }
42
43 public boolean nodeEquals(GPNode node) {
44 return (node.getClass() == this.getClass() && ((FloatERC) node).value == value);
45 }
46
47 // public int nodeHashCode();
48 public void readNode(EvolutionState state, DataInput input)
49 throws IOException {
50 value = input.readDouble();
51 }
52
53 public void writeNode(EvolutionState state, DataOutput output)
54 throws IOException {
55 output.writeDouble(value);
56 }
57
58 public void resetNode(EvolutionState state, int thread) {
59 value = state.random[thread].nextDouble() * 1000.0 - 500.0;
60 }
61
62 public void mutateNode(EvolutionState state, int thread) {
63 double v;
64 do
65 v = value + state.random[thread].nextGaussian() * 10.0;
66 while (v < 0.0 || v >= 1.0);
67 value = v;
68 }
69
70 public void eval(EvolutionState state, int thread, GPData input,
71 ADFStack stack, GPIndividual individual, Problem Problem) {
72 ((DoubleData) input).x = value;
73 }
74
75 @Override
76 public int expectedChildren() {
77 return 0;
78 }
79
80}
Source/Java/ThesisAIProject/src/thesis/evolution/Mul.java
(6 / 2)
  
88package thesis.evolution;
99import ec.*;
1010import ec.gp.*;
11import ec.util.*;
1211
1312public class Mul extends GPNode
1413 {
15 public String toString() { return "*"; }
14 /**
15 *
16 */
17 private static final long serialVersionUID = -1888535852505086679L;
18
19 public String toString() { return "*"; }
1620
1721/*
1822 public void checkConstraints(final EvolutionState state,
Source/Java/ThesisAIProject/src/thesis/evolution/Sub.java
(6 / 2)
  
88package thesis.evolution;
99import ec.*;
1010import ec.gp.*;
11import ec.util.*;
1211
1312public class Sub extends GPNode
1413 {
15 public String toString() { return "-"; }
14 /**
15 *
16 */
17 private static final long serialVersionUID = -2988439490577338390L;
18
19 public String toString() { return "-"; }
1620
1721/*
1822 public void checkConstraints(final EvolutionState state,
Source/Java/ThesisAIProject/src/thesis/evolution/ThesisProblem.java
(23 / 19)
  
66
77package thesis.evolution;
88
9import java.io.IOException;
9import java.io.BufferedReader;
10import java.io.InputStreamReader;
11import java.rmi.RemoteException;
1012import java.util.ArrayList;
1113
1214import ec.util.*;
1616import ec.gp.*;
1717import ec.gp.koza.*;
1818import ec.simple.*;
19import thesis.bot.Controller;
19import test.TestPotentialFunctionProviderStarter;
20import thesis.bot.RemoteBotInterface;
2021
21public class RTSSmallScaleCombatProblem extends GPProblem implements
22 SimpleProblemForm {
22public class ThesisProblem extends GPProblem implements
23 SimpleProblemForm, PotentialFunctionProvider {
2324 private static final long serialVersionUID = 1;
2425
2526 public double currentX;
2627
27 ArrayList<Controller> bwClients;
28 ArrayList<RemoteBotInterface> bwClients;
2829 EvolutionState state;
2930 int threadnum;
3031 Individual ind;
3939 if (!(input instanceof DoubleData))
4040 state.output.fatal("GPData class must subclass from "
4141 + DoubleData.class, base.push(P_DATA), null);
42 bwClients = new ArrayList<Controller>();
42 bwClients = new ArrayList<RemoteBotInterface>();
4343 System.out.println(state.evalthreads + " evalthreads");
44
45 TestPotentialFunctionProviderStarter starter = new TestPotentialFunctionProviderStarter();
46
47 BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
4448 for(int i = 0; i < state.evalthreads; i++) {
45 System.out.println("Starting client " + i);
46 Controller newClient = new Controller();
47 bwClients.add(newClient);
48 newClient.WaitForConnection();
49 System.out.println("Press enter when ready to initialize next client >");
49 System.out.println("Start client " + i);
50 System.out.println("Press enter when the client has been started >");
5051 try {
51 System.in.read();
52 } catch (IOException e) {
52 buffer.readLine();
53 bwClients.add(starter.connectClient(i + ""));
54 System.out.println("Connected to remote bot " + i);
55 } catch (Exception e) {
5356 System.err.println("Something went wrong when waiting for \n"
54 + "the user to press enter on the console\n"
57 + "the user to start the client\n"
5558 + "(for stepping).");
5659 e.printStackTrace();
5760 }
7777
7878 try {
7979 fitness = bwClients.get(threadnum).getRoundScore(this);
80 } catch (InterruptedException e) {
81 System.err
82 .println("InterruptedException in "
83 + "RTSSmallScaleProblem when trying to"
84 + " get the round score");
80 } catch (RemoteException e) {
81 System.err.println("A remote exception while evaluating: ");
8582 e.printStackTrace();
83 throw new Error();
8684 }
8785 fitness -= 180;
8886 fitness *= -1;
Source/Java/ThesisAIProject/src/thesis/evolution/X.java
(7 / 3)
  
88package thesis.evolution;
99import ec.*;
1010import ec.gp.*;
11import ec.util.*;
1211
1312public class X extends GPNode
1413 {
15 public String toString() { return "x"; }
14 /**
15 *
16 */
17 private static final long serialVersionUID = -8420047312101119082L;
1618
19 public String toString() { return "x"; }
20
1721/*
1822 public void checkConstraints(final EvolutionState state,
1923 final int tree,
4141 final Problem problem)
4242 {
4343 DoubleData rd = ((DoubleData)(input));
44 rd.x = ((RTSSmallScaleCombatProblem)problem).currentX;
44 rd.x = ((ThesisProblem)problem).currentX;
4545 }
4646 }
Source/Java/ThesisAIProject/src/thesis/evolution/Y.java
(7 / 3)
  
88package thesis.evolution;
99import ec.*;
1010import ec.gp.*;
11import ec.util.*;
1211
1312public class Y extends GPNode
1413 {
15 public String toString() { return "y"; }
14 /**
15 *
16 */
17 private static final long serialVersionUID = 6977648219687177838L;
1618
19 public String toString() { return "y"; }
20
1721/*
1822 public void checkConstraints(final EvolutionState state,
1923 final int tree,
4141 final Problem problem)
4242 {
4343 DoubleData rd = ((DoubleData)(input));
44 //rd.x = ((RTSSmallScaleCombatProblem)problem).currentY;
44 // rd.x = ((ThesisProblem)problem).currentY;
4545 }
4646 }
Source/Java/ThesisAIProject/src/thesis/evolution/tutorial4.params
(15 / 5)
  
1414gp.fs.0.name = f0
1515
1616# We have five functions in the function set. They are:
17gp.fs.0.size = 4
17gp.fs.0.size = 6
1818gp.fs.0.func.0 = thesis.evolution.X
1919gp.fs.0.func.0.nc = nc0
2020gp.fs.0.func.1 = thesis.evolution.Add
2323gp.fs.0.func.2.nc = nc2
2424gp.fs.0.func.3 = thesis.evolution.Mul
2525gp.fs.0.func.3.nc = nc2
26gp.fs.0.func.4 = thesis.evolution.Div
27gp.fs.0.func.4.nc = nc2
28gp.fs.0.func.5 = thesis.evolution.FloatERC
29gp.fs.0.func.5.nc = nc0
2630
27eval.problem = thesis.evolution.RTSSmallScaleCombatProblem
31eval.problem = thesis.evolution.ThesisProblem
2832eval.problem.data = thesis.evolution.DoubleData
2933
3034# omat lisykset
31pop.subpop.0.size = 512
35pop.subpop.0.size = 32
3236generations = 26
3337print-params = true
3438
35evalthreads = 2
36seed.1 = time
39evalthreads = 1
3740seed.0 = time
41seed.1 = time
42seed.2 = time
43seed.3 = time
44seed.4 = time
45seed.5 = time
46seed.6 = time
47seed.7 = time