Commit 9b882bdf authored by erreiip's avatar erreiip
Browse files

[BOT/VIEW] Bot that can work in every situation about now and veiw fixed

parent a807b6e6
Loading
Loading
Loading
Loading
−295 B (219 B)
Loading image diff...
+5 −3
Changes for jeuAssemblage/src/bot/difficulty/Bot.java: 5 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -11,8 +11,10 @@ import model.PlayBoard;

public abstract class Bot implements IBot {

    public static String[] strategies = { "AI", "Noob" };

    public static final int AI_STRATEGY = 0;
    public static final int MEMO_STRATEGY = 1;
    public static final int NOOB_STRATEGY = 1;

    protected IStrategyBot strategyBot;
    protected PlayBoard model;
@@ -37,8 +39,8 @@ public abstract class Bot implements IBot {
            case AI_STRATEGY -> {
                this.strategyBot = new AgStrategy(this.model, AIdifficulty);
            }
            case MEMO_STRATEGY -> {
                this.strategyBot = new NoobStrategy(this.model);
            case NOOB_STRATEGY -> {
                this.strategyBot = new NoobStrategy(this.model, AIdifficulty);
            }
            default -> {
                throw new IllegalStateException("Strategy " + strategy + " doesn't exist");
+39 −2
Changes for jeuAssemblage/src/bot/strategy/AbstractStrategy.java: 39 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ package bot.strategy;

import java.util.ArrayList;
import java.util.List;

import java.util.Random;
import java.awt.Point;

import bot.interfaces.IStrategyBot;
@@ -16,11 +16,48 @@ public abstract class AbstractStrategy implements IStrategyBot {
    protected PlayBoard model;
    protected PlayBoard bestSolution;

    protected AbstractStrategy(PlayBoard model) {
    protected long seed;
    protected int testSize;
    protected int testedSize;
    protected Random rand;

    protected List<PlayBoard> pop;
    
    protected AbstractStrategy(PlayBoard model, long seed, int testSize) {
        this.model = model;
        this.bestSolution = model;

        this.seed = seed;
        this.testSize = testSize;
        this.testedSize = 0;
        this.rand = new Random(this.seed);

        this.pop = new ArrayList<PlayBoard>();
    }

    @Override
    public boolean tick() {

        if (this.testedSize >= this.testSize) {
            return false;
        }

        int toTest = Math.min(this.testSize - this.testedSize,
                this.rand.nextInt(1, (int) Math.ceil(this.testSize / 25) + 1));
        for (int i = 0; i < toTest; i++) {
            this.tickMethod();
        }

        this.setBestSolution();
        this.testedSize += toTest;

        return true;
    }
    
    protected abstract void tickMethod();

    protected abstract void setBestSolution();

    public List<Move> getMoves() {
        List<Move> ret = new ArrayList<Move>();

+8 −27
Changes for jeuAssemblage/src/bot/strategy/AgStrategy.java: 8 added lines, 27 removed lines.
Original line number Diff line number Diff line
@@ -16,18 +16,12 @@ import utils.SeedUtils;

public class AgStrategy extends AbstractStrategy {

    public static final int EASY = 100;
    public static final int MEDIUM = 200; 
    public static final int HARD = 500; 
    public static final int EASY = 50;
    public static final int MEDIUM = 100; 
    public static final int HARD = 200; 
    
    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) {
        this(model, SeedUtils.generateRandomSeed(), AgStrategy.EASY);
    }
@@ -38,37 +32,24 @@ public class AgStrategy extends AbstractStrategy {

    protected AgStrategy(PlayBoard model, long seed, int testSize) {

        super(model);

        this.seed = seed;
        this.testSize = testSize;
        this.testedSize = 0;
        this.rand = new Random(this.seed);
        super(model, seed, testSize);

        this.pop = createPopulation(this.model, POP_SIZE, this.rand);
        this.pop.add(model);
    }

    @Override
    public boolean tick() {

        if (this.testedSize >= this.testSize) {
            System.out.println(bestSolution.getArea());
            return false;
        }
    public void tickMethod() {

        int toTest = Math.min(this.testSize - this.testedSize, this.rand.nextInt(1, (int) Math.ceil(this.testSize / 30)));
        for (int i = 0; i < toTest; i++) {
        pop = mutation(pop, 1d);
    }

        this.bestSolution = pop.get(0);
        this.testedSize += toTest;
    @Override
    protected void setBestSolution() {
        
        return true;
        this.bestSolution = pop.get(0);
    }


    // ******************
    // Privates methods
    // ******************
+20 −4
Changes for jeuAssemblage/src/bot/strategy/NoobStrategy.java: 20 added lines, 4 removed lines.
Original line number Diff line number Diff line
package bot.strategy;

import java.util.List;
import java.util.Collection;
import java.util.Collections;

import model.PlayBoard;
import utils.SeedUtils;

public class NoobStrategy extends AbstractStrategy {
    

    public NoobStrategy(PlayBoard model) {
        super(model);
        this(model, SeedUtils.generateRandomSeed(), AgStrategy.EASY);
    }

    public NoobStrategy(PlayBoard model, int testSize) {
        this(model, SeedUtils.generateRandomSeed(), testSize);
    }

    public NoobStrategy(PlayBoard model, long seed, int testSize) {
        super(model, seed, testSize);
    }
    
    @Override
    public boolean tick() {
    public void tickMethod() {

        throw new UnsupportedOperationException("Unimplemented method 'tick'");
        pop.add(PlayBoard.constructPlayBoardWithPlacementSeed(model, SeedUtils.generateRandomSeed()));
    }

    @Override
    protected void setBestSolution() {
        Collections.sort(pop);
        this.bestSolution = pop.get(0);
    }
    
}
Loading