Commit 9dc619cc35b6834718322f2ed848ca7f5fd70dda

  • avatar
  • Oskari Leppaaho <oskari.leppaaho @gm…l.com> (Committer)
  • Tue Sep 09 12:54:04 EEST 2014
  • avatar
  • Oskari Leppaaho <oskari.leppaaho @gm…l.com> (Author)
  • Tue Sep 09 12:54:04 EEST 2014
Botti: Täydennyksiä JavaDoc-kommentteihin.
Source/Java/ThesisAIProject/src/overview.html
(7 / 0)
  
1<body>
2The documentation for the programming part of Oskari Leppäaho's master's thesis
3"<i>An AI Approach for SSC Scenarios in RTS Games Using Potential Fields Formed
4with Genetic Programming</i>".
5<p>
6
7</body>
Source/Java/ThesisAIProject/src/thesis/bot/Controller.java
(16 / 11)
  
44import java.util.ArrayList;
55import java.util.List;
66
7import thesis.evolution.PotentialFunctionProvider;
7import thesis.rmi.PotentialFunctionProvider;
8import thesis.rmi.RemoteBotInterface;
89import bwapi.*;
910
1011// TODO: Add more objects that generate potential fields.
156156 }
157157
158158 /**
159 * TODO: A mechanism that gives the score only after the first full round.
160 * Currently the bot will run using the default potential function until
161 * this version of the getRoundScore is called after which it will return
162 * the end score of that round event though for the beginning of the round
163 * the default potential function was used.
164 */
165
166 /**
159167 * Returns when a single round of fighting has finished. <strike>Also starts
160168 * the client if it hasn't been started yet.</strike>
161169 *
171171 * The object that will provide the potential function for this
172172 * round.
173173 * @return Score for the round.
174 */
175 /**
176 * TODO: A mechanism that gives the score only after the first full round.
177 * Currently the bot will run using the default potential function until
178 * this version of the getRoundScore is called after which it will return
179 * the end score of that round event though for the beginning of the round
180 * the default potential function was used.
181 */
174 */
182175 public int getRoundScore(PotentialFunctionProvider potentialProvider) {
183176 System.out.println("Get round score (with potential provider) called");
184177 hasEvolutionStarted = true;
240240 game = mirror.getGame();
241241 visualizer = new Visualizer(game, this);
242242
243 //game.enableFlag(1); // Enables user input
244 game.enableFlag(0); // Enables perfect information
243 final int ENABLECODE_PERFECT_INFORMATION = 0;
244// final int ENABLECODE_USER_INPUT = 1;
245
246 //game.enableFlag(ENABLECODE_USER_INPUT);
247 game.enableFlag(ENABLECODE_PERFECT_INFORMATION);
245248 game.setLocalSpeed(GAME_SPEED);
246249
247250 if (!GUI_ON)
Source/Java/ThesisAIProject/src/thesis/bot/PosUtils.java
(27 / 2)
  
11package thesis.bot;
2
23import bwapi.Position;
34
5/**
6 * Provides some vector math operations on bwapi Positions.
7 *
8 * @author Oskari Leppäaho
9 *
10 */
411public class PosUtils {
512
13 /**
14 * Multiplies a bwapi position by an int.
15 *
16 * @param pos
17 * The position to multiply.
18 * @param x
19 * The multiplier.
20 * @return The product.
21 */
622 public static Position multiply(Position pos, int x) {
723 return new Position(pos.getX() * x, pos.getY() * x);
824 }
9
25
26 /**
27 * Adds two bwapi positions.
28 *
29 * @param x
30 * The position to add.
31 * @param y
32 * Another position to add.
33 * @return The sum.
34 */
1035 public static Position add(Position x, Position y) {
1136 return new Position(x.getX() + y.getX(), x.getY() + y.getY());
12
37
1338 }
1439}
Source/Java/ThesisAIProject/src/thesis/bot/PotentialCalculator.java
(23 / 10)
  
22
33import java.rmi.RemoteException;
44
5import thesis.evolution.PotentialFunctionProvider;
65import thesis.bot.PosUtils;
6import thesis.rmi.PotentialFunctionProvider;
77import bwapi.*;
88
99/**
1919public class PotentialCalculator {
2020
2121 Controller bot;
22 PotentialFunctionProvider potentialProvider; // the component that will provide
22 PotentialFunctionProvider potentialProvider; // the component that will
23 // provide
2324 // the potential function
2425
26 /**
27 * Creates the PotentialCalculator.
28 *
29 * @param bot
30 * A reference to the bot controller.
31 */
2532 public PotentialCalculator(Controller bot) {
2633 this.bot = bot;
2734 }
2835
36 /**
37 * Sets the potential provider.
38 *
39 * @param potentialProvider
40 * The new potential provider.
41 */
2942 public void setPotentialProvider(PotentialFunctionProvider potentialProvider) {
3043 this.potentialProvider = potentialProvider;
3144 }
5656 }
5757
5858 /**
59 * Get the potential for coordinates. <strike>The potential is calculated by adding
60 * -(0.05 * enemyDistance - 5)^2 for each enemy unit. This potential tries
61 * to keep a single unit at it's maximum attacking range from a single
59 * Get the potential for coordinates. <strike>The potential is calculated by
60 * adding -(0.05 * enemyDistance - 5)^2 for each enemy unit. This potential
61 * tries to keep a single unit at it's maximum attacking range from a single
6262 * enemy.</strike>
6363 *
6464 * Uses the potentialProvider if it was set. Otherwise uses the potential
7373 private double getPotential(double x, double y) {
7474 double potential = 0;
7575
76 //Position mapSize = bot.game.getMap().getSize();
76 // Position mapSize = bot.game.getMap().getSize();
7777 double distMapBottom = bot.game.mapHeight() - y;
7878 double distMapTop = y;
7979 double distMapLeft = x;
165165 Position getMoveDirection(double[] potentials) {
166166 int highestIndex = Controller.findHighestDefaultTo4(potentials);
167167 // Indices:
168 // 0 1 2 -1,-1 0,-1 1,-1
169 // 3 4 5 -1, 0 0, 0 1 ,0
170 // 6 7 8 -1, 1 0, 1 1, 1
168 // 0 1 2 -1,-1 0,-1 1,-1
169 // 3 4 5 -1, 0 0, 0 1 ,0
170 // 6 7 8 -1, 1 0, 1 1, 1
171171 int x = highestIndex % 3 - 1;
172172 int y = ((highestIndex) / 3 - 1);
173173 return new Position(x, y);
212212 // -------------enddebug
213213
214214 for (int i = 0; i <= distance; i++) {
215
215
216216 Position offset = PosUtils.multiply(dir, i);
217217
218218 double currentPotential = getPotential(PosUtils.add(from, offset));
Source/Java/ThesisAIProject/src/thesis/bot/package-info.java
(1 / 1)
  
11/**
2 * The package contains the classes for the actual bot. Uses JNIBWAPI
2 * Contains the classes for the actual bot. Uses JNIBWAPI
33 * to communicate with the StarCraft BroodWar game.
44 */
55package thesis.bot;
Source/Java/ThesisAIProject/src/thesis/evolution/Add.java
(37 / 34)
  
22 Copyright 2006 by Sean Luke
33 Licensed under the Academic Free License version 3.0
44 See the file "LICENSE" for more information
5*/
5 */
66
7
87package thesis.evolution;
8
99import ec.*;
1010import ec.gp.*;
1111import ec.util.*;
1212
13public class Add extends GPNode
14 {
15 public String toString() { return "+"; }
13/**
14 * A node representing addition in a program tree generated by genetic
15 * programming.
16 *
17 * @author Sean Luke
18 *
19 */
20public class Add extends GPNode {
21 private static final long serialVersionUID = -5961111950202864849L;
1622
17/*
18 public void checkConstraints(final EvolutionState state,
19 final int tree,
20 final GPIndividual typicalIndividual,
21 final Parameter individualBase)
22 {
23 super.checkConstraints(state,tree,typicalIndividual,individualBase);
24 if (children.length!=2)
25 state.output.error("Incorrect number of children for node " +
26 toStringForError() + " at " +
27 individualBase);
28 }
29*/
30 public int expectedChildren() { return 2; }
23 public String toString() {
24 return "+";
25 }
3126
32 public void eval(final EvolutionState state,
33 final int thread,
34 final GPData input,
35 final ADFStack stack,
36 final GPIndividual individual,
37 final Problem problem)
38 {
39 double result;
40 DoubleData rd = ((DoubleData)(input));
27 /*
28 * public void checkConstraints(final EvolutionState state, final int tree,
29 * final GPIndividual typicalIndividual, final Parameter individualBase) {
30 * super.checkConstraints(state,tree,typicalIndividual,individualBase); if
31 * (children.length!=2)
32 * state.output.error("Incorrect number of children for node " +
33 * toStringForError() + " at " + individualBase); }
34 */
35 public int expectedChildren() {
36 return 2;
37 }
4138
42 children[0].eval(state,thread,input,stack,individual,problem);
43 result = rd.x;
39 public void eval(final EvolutionState state, final int thread,
40 final GPData input, final ADFStack stack,
41 final GPIndividual individual, final Problem problem) {
42 double result;
43 DoubleData rd = ((DoubleData) (input));
4444
45 children[1].eval(state,thread,input,stack,individual,problem);
46 rd.x = result + rd.x;
47 }
48 }
45 children[0].eval(state, thread, input, stack, individual, problem);
46 result = rd.x;
47
48 children[1].eval(state, thread, input, stack, individual, problem);
49 rd.x = result + rd.x;
50 }
51}
Source/Java/ThesisAIProject/src/thesis/evolution/Div.java
(9 / 4)
  
99import ec.*;
1010import ec.gp.*;
1111
12/**
13 * A node representing division in a program tree generated by genetic
14 * programming.
15 *
16 * @author Sean Luke
17 *
18 */
1219public class Div extends GPNode
1320 {
14 /**
15 *
16 */
17 private static final long serialVersionUID = 1L;
21
22 private static final long serialVersionUID = 8528119815001531877L;
1823
1924 public String toString() { return "/"; }
2025
Source/Java/ThesisAIProject/src/thesis/evolution/DoubleData.java
(15 / 8)
  
22 Copyright 2006 by Sean Luke
33 Licensed under the Academic Free License version 3.0
44 See the file "LICENSE" for more information
5*/
5 */
66
7
87package thesis.evolution;
8
99import ec.gp.*;
1010
11public class DoubleData extends GPData
12 {
13 public double x; // return value
11/**
12 * GPData representing a double precision floating point number.
13 *
14 * @author Sean Luke
15 *
16 */
17public class DoubleData extends GPData {
18 public double x; // return value
1419
15 public void copyTo(final GPData gpd) // copy my stuff to another DoubleData
16 { ((DoubleData)gpd).x = x; }
17 }
20 public void copyTo(final GPData gpd) // copy my stuff to another DoubleData
21 {
22 ((DoubleData) gpd).x = x;
23 }
24}
Source/Java/ThesisAIProject/src/thesis/evolution/FloatERC.java
(4 / 2)
  
1111import ec.util.DecodeReturn;
1212
1313/**
14 * An ephemeral random constant for GP.
15 * @author Oskari Leppäaho
14 * A node representing an ephemeral random constant in a program tree generated by genetic
15 * programming.
16 *
17 * @author Sean Luke
1618 *
1719 */
1820public class FloatERC extends ERC {
Source/Java/ThesisAIProject/src/thesis/evolution/Mul.java
(36 / 37)
  
22 Copyright 2006 by Sean Luke
33 Licensed under the Academic Free License version 3.0
44 See the file "LICENSE" for more information
5*/
5 */
66
7
87package thesis.evolution;
8
99import ec.*;
1010import ec.gp.*;
1111
12public class Mul extends GPNode
13 {
14 /**
15 *
16 */
12/**
13 * A node representing multiplication in a program tree generated by genetic
14 * programming.
15 *
16 * @author Sean Luke
17 *
18 */
19public class Mul extends GPNode {
20
1721 private static final long serialVersionUID = -1888535852505086679L;
1822
19 public String toString() { return "*"; }
23 public String toString() {
24 return "*";
25 }
2026
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; }
27 /*
28 * public void checkConstraints(final EvolutionState state, final int tree,
29 * final GPIndividual typicalIndividual, final Parameter individualBase) {
30 * super.checkConstraints(state,tree,typicalIndividual,individualBase); if
31 * (children.length!=2)
32 * state.output.error("Incorrect number of children for node " +
33 * toStringForError() + " at " + individualBase); }
34 */
35 public int expectedChildren() {
36 return 2;
37 }
3538
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));
39 public void eval(final EvolutionState state, final int thread,
40 final GPData input, final ADFStack stack,
41 final GPIndividual individual, final Problem problem) {
42 double result;
43 DoubleData rd = ((DoubleData) (input));
4544
46 children[0].eval(state,thread,input,stack,individual,problem);
47 result = rd.x;
45 children[0].eval(state, thread, input, stack, individual, problem);
46 result = rd.x;
4847
49 children[1].eval(state,thread,input,stack,individual,problem);
50 rd.x = result * rd.x;
51 }
52 }
48 children[1].eval(state, thread, input, stack, individual, problem);
49 rd.x = result * rd.x;
50 }
51}
Source/Java/ThesisAIProject/src/thesis/evolution/Sub.java
(7 / 3)
  
99import ec.*;
1010import ec.gp.*;
1111
12/**
13 * A node representing addition in a program tree generated by genetic
14 * programming.
15 *
16 * @author Sean Luke
17 *
18 */
1219public class Sub extends GPNode
1320 {
14 /**
15 *
16 */
1721 private static final long serialVersionUID = -2988439490577338390L;
1822
1923 public String toString() { return "-"; }
Source/Java/ThesisAIProject/src/thesis/evolution/X.java
(31 / 33)
  
22 Copyright 2006 by Sean Luke
33 Licensed under the Academic Free License version 3.0
44 See the file "LICENSE" for more information
5*/
5 */
66
7
87package thesis.evolution;
8
99import ec.*;
1010import ec.gp.*;
1111
12public class X extends GPNode
13 {
14 /**
15 *
16 */
12/**
13 * A node representing an input parameter in a program tree generated by genetic
14 * programming.
15 *
16 * @author Sean Luke
17 *
18 */
19public class X extends GPNode {
1720 private static final long serialVersionUID = -8420047312101119082L;
1821
19 public String toString() { return "x"; }
22 public String toString() {
23 return "x";
24 }
2025
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!=0)
29 state.output.error("Incorrect number of children for node " +
30 toStringForError() + " at " +
31 individualBase);
32 }
33*/
34 public int expectedChildren() { return 0; }
26 /*
27 * public void checkConstraints(final EvolutionState state, final int tree,
28 * final GPIndividual typicalIndividual, final Parameter individualBase) {
29 * super.checkConstraints(state,tree,typicalIndividual,individualBase); if
30 * (children.length!=0)
31 * state.output.error("Incorrect number of children for node " +
32 * toStringForError() + " at " + individualBase); }
33 */
34 public int expectedChildren() {
35 return 0;
36 }
3537
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 DoubleData rd = ((DoubleData)(input));
44 rd.x = ((ThesisProblem)problem).currentX;
45 }
46 }
38 public void eval(final EvolutionState state, final int thread,
39 final GPData input, final ADFStack stack,
40 final GPIndividual individual, final Problem problem) {
41 DoubleData rd = ((DoubleData) (input));
42 rd.x = ((ThesisProblem) problem).currentX;
43 }
44}
Source/Java/ThesisAIProject/src/thesis/evolution/Y.java
(8 / 4)
  
99import ec.*;
1010import ec.gp.*;
1111
12/**
13 * A node representing an input parameter in a program tree generated by genetic
14 * programming.
15 *
16 * @author Sean Luke
17 *
18 */
1219public class Y extends GPNode
13 {
14 /**
15 *
16 */
20 {
1721 private static final long serialVersionUID = 6977648219687177838L;
1822
1923 public String toString() { return "y"; }
Source/Java/ThesisAIProject/src/thesis/evolution/package-info.java
(1 / 1)
  
11/**
2 * The package contains the classes for the potential field function evolution.
2 * Contains the classes for the potential field function evolution.
33 * Uses ECJ evolution library to evolve a population of potential field functions.
44 * Uses the classes in the {@link thesis.bot} package to evaluate the individuals.
55 */