Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
genie_logiciel_2015
the_dungeon_project
Commits
ed5b2ea2
Commit
ed5b2ea2
authored
Jan 04, 2016
by
Remy Garnier
Browse files
Add a simple method for movment in in the Same AITile
parent
9d4f9ffe
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/artificial_intelligence/AIEntities/AbstractEntity.java
View file @
ed5b2ea2
...
...
@@ -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.
*
...
...
src/artificial_intelligence/AlphaStar/AI.java
View file @
ed5b2ea2
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
;
...
...
src/artificial_intelligence/AlphaStar/AITile.java
View file @
ed5b2ea2
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.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment