package model; import java.util.Iterator; import java.util.Set; import model.entities.IActive; import model.world.Direction; import model.world.Labyrinth; import model.world.Position; import model.world.graphs.Edge; import model.world.graphs.MappedGraph; import model.world.graphs.MappedGraphBuilder; import model.world.graphs.Vertex; import utils.Utils; public class Model { private Labyrinth labyrinth; /** * @return the model specified * @author halonso * @see model.world.graphs.MappedGraphBuilder * @since 2017-18-11 */ public Model(int sizeX, int sizeY, Position root, int nbNode, int complexityNode) { initialize(sizeX, sizeY, root, nbNode, complexityNode); } /** * @param boundX the bound of the grid's widht * @param boundY the bound of the grid's height * @author halonso * @see model.world.graphs.MappedGraphBuilder * @since 2017-18-11 */ public Model(int boundX, int boundY) { randomInitialize(boundX, boundY); } private void initialize(int sizeX, int sizeY, Position root, int nbNode, int complexityNode) { // graphs = MappedGraphBuilder.temporaryCompleteGraph(sizeX, sizeY); MappedGraph map = MappedGraphBuilder.build(sizeX, sizeY, root, nbNode, complexityNode); labyrinth = new Labyrinth(map); //graphs=MappedGraphBuilder.debugTest(sizeX, sizeY, root, nbNode, complexityNode); } private void randomInitialize(int boundX, int BoundY) { int randomSizeX = Utils.nextInt(boundX); int randomSizeY = Utils.nextInt(BoundY); Position randomRoot = new Position(Utils.nextInt(randomSizeX), Utils.nextInt(randomSizeY)); int randomNbNode = Utils.nextInt(100); int randomComplexity = Utils.nextInt(100); System.out.format("\nLab parameters :\n" + "SizeX: %d \n" + "SizeY: %d \n" + "Root: %s \n" + "NbNode: %d \n" + "Complexity: %d \n", randomSizeX, randomSizeY, randomRoot,randomNbNode, randomComplexity); initialize(randomSizeX, randomSizeY, randomRoot, randomNbNode, randomComplexity); } /** * @return the size of the x axis of the labyrinth */ public int getSizeX() { return labyrinth.getSizeX(); } /** * * @return the size of the y axis of the labyrinth */ public int getSizeY() { return labyrinth.getSizeY(); } public boolean isMoveValid(IActive active, Direction direction) { return labyrinth.isMoveValid(active, direction); } /** * * @return a Set which contains all Edges of the Labyrinth */ public Set getEdgeSet() { return labyrinth.getEdgeSet(); } /** * Ask to the Labyrinth the shortest way between two position * @param pStart Position to start * @param pEnd Position to end * @return an iterator of Vertex which is the shortest path from pStart to pEnd */ public Iterator getShorterPath(Position pStart, Position pEnd){ return labyrinth.getShorterPath(pStart,pEnd); } }