Commit ed5b2ea2 authored by Remy Garnier's avatar Remy Garnier
Browse files

Add a simple method for movment in in the Same AITile

parent 9d4f9ffe
......@@ -32,6 +32,16 @@ public abstract class AbstractEntity extends Thread {
/* Intern information */
protected boolean endThread;
public Map GetMap()
{
return map;
}
public Relayer GetRelay()
{
return relayer;
}
/**
* Instanciate by default an autonomous AI given as context a GameContent and a Relayer to contact.
*
......
package artificial_intelligence.AlphaStar;
import java.util.PriorityQueue;
import artificial_intelligence.GameOpt;
import core.zone.Direction;
import java.lang.Math;
/**
* @author Remy GARNIER && Yann RAMUSAT
......@@ -14,14 +14,12 @@ import core.zone.Direction;
public class AI {
/* Some example of general options for the AI */
private GameOpt opt;
/**
* Constructor
*/
public AI(GameOpt opt) {
this.opt = opt;
}
/**
*
* @return the Game Options of the game
......@@ -29,7 +27,6 @@ public class AI {
public GameOpt getOpt() {
return opt;
}
/**
* Set a game opt.
* @param Game Options
......@@ -37,6 +34,34 @@ public class AI {
public void setOpt(GameOpt opt) {
this.opt = opt;
}
/**
* Simple algorithm to get the direction when the both object
* */
public static Direction DirectPath(int obj_x, int obj_y, int source_x, int source_y)
{
int disx=(obj_x-source_x);
int disy=(obj_y-source_y);
//In the case where the object are in the same AITile
if (java.lang.Math.abs(disy)>java.lang.Math.abs(disx))
{
if (disy>0) {
return Direction.UP;
}
else
{
return Direction.DOWN;
}
}
else {
if (disx<0) {
return Direction.RIGHT;
}
else
{
return Direction.LEFT;
}
}
}
/**
* Implementation of the A* algorithm.
......@@ -49,17 +74,19 @@ public class AI {
* @param height
* @return the direction to go
*/
public static Direction alpha_star(int obj_x, int obj_y, int source_x, int source_y,int width,int height) {
public static Direction alpha_star( int obj_x, int obj_y, int source_x, int source_y, int width, int height) {
AITile obj = new AITile(obj_x, obj_y);
AITile begin = new AITile(source_x, source_y);
//On inversera l'objectif et le départ, il est plus simple de partir de l'arrivée
int disx=(obj_x-source_x);
int disy=(obj_y-source_y);
//In the case where the object are in the same AITile
if (java.lang.Math.abs(disx)<32 && java.lang.Math.abs(disy)<32)
{
return DirectPath(obj_x,obj_y,source_x,source_y);
}
AITileComparator comparator = new AITileComparator(begin);
//PriorityQueue<Case> PriorQueue.java = new PriorityQueue<Case>(11, comparator);
//PriorQueue.java.add(begin);
//Les valeurs des objets de la table
//Les valeurs de 4000 doivent être corrigées pour éviter des problèmes.
Direction[][] direction = new Direction[width][height];
int[][] value=new int[width][height];
value[obj_x/32][obj_y/32]=0;
......
package artificial_intelligence.AlphaStar;
import artificial_intelligence.AIEntities.AbstractEntity;
import core.relayer.Relayer;
import core.zone.Direction;
import map_generation.map.Map;
import map_generation.tiles.Tile;
/**
* @author Remy GARNIER && Yann RAMUSAT
......@@ -31,7 +35,13 @@ public class AITile {
this.y = y;
}
public boolean isObstacle(){return false;}
public boolean isObstacle(){
/*Map map=AbstractEntity.GetMap();
Relayer relayer=AbstractEntity.GetRelay();
Tile tile=map.getTileAt(x,y);
*/
return false;}
/**
* Return information about the closest tiles.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment