Commit 2d2abbd0 authored by erreiip's avatar erreiip
Browse files

[BOT] Refacto strategy

parent b93c41f1
Loading
Loading
Loading
Loading
+1 −1
Changes for jeuAssemblage/src/bot/interfaces/IStrategyBot.java: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ package bot.interfaces;

import java.util.List;

import bot.Move;
import bot.utils.Move;

public interface IStrategyBot extends ITickable{

+45 −0
Changes for jeuAssemblage/src/bot/strategy/AbstractStrategy.java: 45 added lines, 0 removed lines.
Original line number Diff line number Diff line
package bot.strategy;


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

import java.awt.Point;

import bot.interfaces.IStrategyBot;
import bot.utils.Move;
import model.PlayBoard;
import piece.Piece;

public abstract class AbstractStrategy implements IStrategyBot {

    protected PlayBoard model;
    protected PlayBoard bestSolution;
    
    protected AbstractStrategy(PlayBoard model) {
        this.model = model;
        this.bestSolution = model;
    }

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

        ArrayList<Piece> pieceAl = new ArrayList<Piece>();

        for (int i = 0; i < bestSolution.getBoardHeight(); i++) {
            for (int j = 0; j < bestSolution.getBoardWidth(); j++) {
                int pieceId = bestSolution.getPieceIdAt(j, i);
                if (pieceId != 0) {
                    Piece p = bestSolution.getPieceById(pieceId);
                    if (!pieceAl.contains(p)) {
                        Point upperLeftCorner = bestSolution.getUpperLeftPieceCornerById(pieceId);
                        ret.add(new Move(pieceId, upperLeftCorner.x, upperLeftCorner.y));
                        pieceAl.add(p);
                    }
                }
            }
        }

        return ret;
    }
}
+9 −29
Changes for jeuAssemblage/src/bot/strategy/AgStrategy.java: 9 added lines, 29 removed lines.
Original line number Diff line number Diff line
@@ -9,13 +9,13 @@ import java.util.Collections;

import java.awt.Point;

import bot.Move;
import bot.interfaces.IStrategyBot;
import bot.utils.Move;
import model.PlayBoard;
import model.SeedUtils;
import piece.Piece;

public class AgStrategy implements IStrategyBot {
public class AgStrategy extends AbstractStrategy {

    public static final int EASY = 1;
    public static final int MEDIUM = 2; 
    public static final int HARD = 5; 
@@ -23,7 +23,6 @@ public class AgStrategy implements IStrategyBot {
    private static final int POP_SIZE = 100;

    protected List<PlayBoard> pop;
    protected PlayBoard model;
    protected long seed;
    protected int testSize;
    private Random rand;
@@ -37,16 +36,18 @@ public class AgStrategy implements IStrategyBot {
    }

    protected AgStrategy(PlayBoard model, long seed, int testSize) {
        System.out.println(model);
        System.out.println(model.getArea());

        this.model = model;
        super(model);

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

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

        System.out.println(model);
        System.out.println(model.getArea());
    }
    
    @Override
@@ -55,29 +56,8 @@ public class AgStrategy implements IStrategyBot {
        for (int i = 0; i < testSize; i++) {
            pop = mutation(pop, 1d);
        }
    }

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

        PlayBoard bestSolution = pop.get(0);
        ArrayList<Piece> pieceAl = new ArrayList<Piece>();

        for (int i = 0; i < bestSolution.getBoardHeight(); i++) {
            for (int j = 0; j < bestSolution.getBoardWidth(); j++) {
                int pieceId = bestSolution.getPieceIdAt(j, i);
                if (pieceId != 0) {
                    Piece p = bestSolution.getPieceById(pieceId);
                    if (!pieceAl.contains(p)) {
                        Point upperLeftCorner = bestSolution.getUpperLeftPieceCornerById(pieceId);
                        ret.add(new Move(pieceId, upperLeftCorner.x, upperLeftCorner.y));
                        pieceAl.add(p);
                    }
                }
            }
        }

        return ret;
        this.bestSolution = pop.get(0);
    }
    

+3 −11
Changes for jeuAssemblage/src/bot/strategy/NoobStrategy.java: 3 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -2,22 +2,14 @@ package bot.strategy;

import java.util.List;

import bot.interfaces.IStrategyBot;
import bot.Move;
import model.PlayBoard;

public class AbstractStrategyMemo implements IStrategyBot{
    protected int deep;
    protected PlayBoard model;
public class NoobStrategy extends AbstractStrategy {
    
    public AbstractStrategyMemo(PlayBoard model) {
        this.deep = -1;
        this.model = model;
    public NoobStrategy(PlayBoard model) {
        super(model);
    }
    
    public List<Move> getMoves() {
        return null;
    }

    @Override
    public void tick() {
+1 −1
Changes for jeuAssemblage/src/bot/utils/Move.java: 1 added line, 1 removed line.
Original line number Diff line number Diff line
package bot;
package bot.utils;

import piece.Piece;

Loading