Loading jeuAssemblage/src/bot/BotThread.java +16 −17 Changes for jeuAssemblage/src/bot/BotThread.java: 16 added lines, 17 removed lines. Original line number Diff line number Diff line Loading @@ -3,35 +3,34 @@ package bot; import java.util.ArrayList; import bot.interfaces.IBot; import bot.view.interfaces.IMovesView; public class BotThread implements Runnable { private final static int DEFAULT_SLEEP = 1000; private ArrayList<IBot> bots; private ArrayList<IBot> bot; private int sleepTime; private boolean stop; public BotThread() { private IMovesView movesView; this(new ArrayList<IBot>()); } private boolean stop; public BotThread(ArrayList<IBot> bots) { public BotThread(ArrayList<IBot> bot, IMovesView movesView) { this(bots, DEFAULT_SLEEP); this(bot, DEFAULT_SLEEP, movesView); } public BotThread(ArrayList<IBot> bots, int sleepTime) { public BotThread(ArrayList<IBot> bot, int sleepTime, IMovesView movesView) { this.bots = bots; this.bot = bot; this.sleepTime = sleepTime; this.movesView = movesView; this.stop = false; } public ArrayList<IBot> getBots() { return this.bots; return this.bot; } public void stop() { Loading @@ -45,15 +44,15 @@ public class BotThread implements Runnable { @Override public void run() { while (!this.stop) { for (IBot bot : bots) { bot.tick(); } while (!this.stop && bot.tick()) { try { Thread.sleep(sleepTime); } catch(Exception e ) { e.printStackTrace(); } } this.movesView.setMoves(this.bot.getMoves()); this.movesView.start(); this.stop(); } } jeuAssemblage/src/bot/difficulty/Bot.java +10 −2 Changes for jeuAssemblage/src/bot/difficulty/Bot.java: 10 added lines, 2 removed lines. Original line number Diff line number Diff line package bot.difficulty; import java.util.List; import bot.interfaces.IBot; import bot.interfaces.IStrategyBot; import bot.strategy.AgStrategy; import bot.strategy.NoobStrategy; import bot.utils.Move; import model.PlayBoard; public abstract class Bot implements IBot { Loading Loading @@ -44,7 +47,12 @@ public abstract class Bot implements IBot { } @Override public void tick() { this.strategyBot.tick(); public boolean tick() { return this.strategyBot.tick(); } @Override public List<Move> getMoves() { return this.strategyBot.getMoves(); } } jeuAssemblage/src/bot/interfaces/IBot.java +1 −1 Changes for jeuAssemblage/src/bot/interfaces/IBot.java: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -2,7 +2,7 @@ package bot.interfaces; import model.PlayBoard; public interface IBot extends ITickable { public interface IBot extends IStrategyBot { public abstract PlayBoard getModel(); public abstract void setStrategy(int strategy); Loading jeuAssemblage/src/bot/interfaces/ITickable.java +1 −1 Changes for jeuAssemblage/src/bot/interfaces/ITickable.java: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -2,5 +2,5 @@ package bot.interfaces; public interface ITickable { public abstract void tick(); public abstract boolean tick(); } jeuAssemblage/src/bot/strategy/AgStrategy.java +15 −5 Changes for jeuAssemblage/src/bot/strategy/AgStrategy.java: 15 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -16,15 +16,16 @@ import utils.SeedUtils; public class AgStrategy extends AbstractStrategy { public static final int EASY = 1; public static final int MEDIUM = 2; public static final int HARD = 5; public static final int EASY = 100; public static final int MEDIUM = 200; public static final int HARD = 500; private static final int POP_SIZE = 100; protected List<PlayBoard> pop; protected long seed; protected int testSize; protected int testedSize; private Random rand; public AgStrategy(PlayBoard model) { Loading @@ -41,6 +42,7 @@ public class AgStrategy extends AbstractStrategy { this.seed = seed; this.testSize = testSize; this.testedSize = 0; this.rand = new Random(this.seed); this.pop = createPopulation(this.model, POP_SIZE, this.rand); Loading @@ -51,13 +53,21 @@ public class AgStrategy extends AbstractStrategy { } @Override public void tick() { public boolean tick() { for (int i = 0; i < testSize; i++) { if (this.testedSize >= this.testSize) { return false; } int toTest = this.rand.nextInt(0, (this.testSize/3)); for (int i = 0; i < toTest; i++) { pop = mutation(pop, 1d); } this.bestSolution = pop.get(0); this.testedSize += toTest; return true; } Loading Loading
jeuAssemblage/src/bot/BotThread.java +16 −17 Changes for jeuAssemblage/src/bot/BotThread.java: 16 added lines, 17 removed lines. Original line number Diff line number Diff line Loading @@ -3,35 +3,34 @@ package bot; import java.util.ArrayList; import bot.interfaces.IBot; import bot.view.interfaces.IMovesView; public class BotThread implements Runnable { private final static int DEFAULT_SLEEP = 1000; private ArrayList<IBot> bots; private ArrayList<IBot> bot; private int sleepTime; private boolean stop; public BotThread() { private IMovesView movesView; this(new ArrayList<IBot>()); } private boolean stop; public BotThread(ArrayList<IBot> bots) { public BotThread(ArrayList<IBot> bot, IMovesView movesView) { this(bots, DEFAULT_SLEEP); this(bot, DEFAULT_SLEEP, movesView); } public BotThread(ArrayList<IBot> bots, int sleepTime) { public BotThread(ArrayList<IBot> bot, int sleepTime, IMovesView movesView) { this.bots = bots; this.bot = bot; this.sleepTime = sleepTime; this.movesView = movesView; this.stop = false; } public ArrayList<IBot> getBots() { return this.bots; return this.bot; } public void stop() { Loading @@ -45,15 +44,15 @@ public class BotThread implements Runnable { @Override public void run() { while (!this.stop) { for (IBot bot : bots) { bot.tick(); } while (!this.stop && bot.tick()) { try { Thread.sleep(sleepTime); } catch(Exception e ) { e.printStackTrace(); } } this.movesView.setMoves(this.bot.getMoves()); this.movesView.start(); this.stop(); } }
jeuAssemblage/src/bot/difficulty/Bot.java +10 −2 Changes for jeuAssemblage/src/bot/difficulty/Bot.java: 10 added lines, 2 removed lines. Original line number Diff line number Diff line package bot.difficulty; import java.util.List; import bot.interfaces.IBot; import bot.interfaces.IStrategyBot; import bot.strategy.AgStrategy; import bot.strategy.NoobStrategy; import bot.utils.Move; import model.PlayBoard; public abstract class Bot implements IBot { Loading Loading @@ -44,7 +47,12 @@ public abstract class Bot implements IBot { } @Override public void tick() { this.strategyBot.tick(); public boolean tick() { return this.strategyBot.tick(); } @Override public List<Move> getMoves() { return this.strategyBot.getMoves(); } }
jeuAssemblage/src/bot/interfaces/IBot.java +1 −1 Changes for jeuAssemblage/src/bot/interfaces/IBot.java: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -2,7 +2,7 @@ package bot.interfaces; import model.PlayBoard; public interface IBot extends ITickable { public interface IBot extends IStrategyBot { public abstract PlayBoard getModel(); public abstract void setStrategy(int strategy); Loading
jeuAssemblage/src/bot/interfaces/ITickable.java +1 −1 Changes for jeuAssemblage/src/bot/interfaces/ITickable.java: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -2,5 +2,5 @@ package bot.interfaces; public interface ITickable { public abstract void tick(); public abstract boolean tick(); }
jeuAssemblage/src/bot/strategy/AgStrategy.java +15 −5 Changes for jeuAssemblage/src/bot/strategy/AgStrategy.java: 15 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -16,15 +16,16 @@ import utils.SeedUtils; public class AgStrategy extends AbstractStrategy { public static final int EASY = 1; public static final int MEDIUM = 2; public static final int HARD = 5; public static final int EASY = 100; public static final int MEDIUM = 200; public static final int HARD = 500; private static final int POP_SIZE = 100; protected List<PlayBoard> pop; protected long seed; protected int testSize; protected int testedSize; private Random rand; public AgStrategy(PlayBoard model) { Loading @@ -41,6 +42,7 @@ public class AgStrategy extends AbstractStrategy { this.seed = seed; this.testSize = testSize; this.testedSize = 0; this.rand = new Random(this.seed); this.pop = createPopulation(this.model, POP_SIZE, this.rand); Loading @@ -51,13 +53,21 @@ public class AgStrategy extends AbstractStrategy { } @Override public void tick() { public boolean tick() { for (int i = 0; i < testSize; i++) { if (this.testedSize >= this.testSize) { return false; } int toTest = this.rand.nextInt(0, (this.testSize/3)); for (int i = 0; i < toTest; i++) { pop = mutation(pop, 1d); } this.bestSolution = pop.get(0); this.testedSize += toTest; return true; } Loading