Commit 0310db95 authored by Remy Garnier's avatar Remy Garnier

Merge branch 'master' of gitlab.crans.org:genie_logiciel_2015/the_dungeon_project

Conflicts:
	src/artificial_intelligence/AlphaStar/AI.java
parents f76d6c0d 8c3451a5
......@@ -17,6 +17,12 @@ build
org.scala-ide.sdt.core/META-INF/MANIFEST.MF
org.scala-ide.sdt.update-site/site.xml
# Fichiers générés par JavaCC
src/ingame_programming/ParseException.java
src/ingame_programming/Token*
src/ingame_programming/Script*.java
src/ingame_programming/SimpleCharStream.java
### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
......
Ce dossier contient les scripts pour une intégration continue à la main.
=== INSTALLATION ===
* mettre en place un cron qui pull le projet à interval régulier.
* mettre en place le serveur http a contacter (server.py)
* Copier post-merge dans .git/hooks.
* Modifier mailci.py pour utiliser un serveur smpt correct.
......@@ -7,6 +7,8 @@ PACKAGEDIRS = ${shell find . -iname '*.java' | sed 's/\.\/\|[^/]*.java//g' | sor
#TESTCLASS = ${shell find . -name *Test.java | sed 's/.\/src\/\|.java//g' | sed 's/\//./g'}
PARSER = src/ingame_programming/Script.jj
# Java compiler
JAVAC = javac
JVM = 1.8
......@@ -47,9 +49,9 @@ IMAGEFILES = $(wildcard $(SRC)$(IMG)*.png $(SRC)$(IMG)*.gif $(SRC)$(IMG)*.txt)
# The first target is the one that is executed when you invoke
# "make".
.PHONY: all clean cleandoc hack
.PHONY: all clean cleandoc hack genpars
all : hack $(addprefix $(BIN), $(CLASS_FILES))
all : hack genpars $(addprefix $(BIN), $(CLASS_FILES))
@cp -r $(addprefix $(SRC)$(IMG), $(IMAGEDIRS)) $(IMAGEFILES) $(BIN)$(IMG)
@cp -r $(LIB) $(BIN)
......@@ -66,6 +68,10 @@ hack :
buildplay: all
cd bin/; java -cp $(LIB)*:. graphics.guiSkeleton.Igniter_Main
# Generate parser
genpars: $(PARSER)
@cd `dirname $<` ;find . -name *.jj | while read i; do java -cp lib/javacc-6.1.2.jar javacc $$i; done
clean :
rm -rf $(BIN)
......
################### THIS FILE IS USED TO HAVE PERSISTENT COMMANDS IN THE GAME ###################
#################################################################################################
###################
MOVE UP:
Left arrow
###################
MOVE DOWN:
Down arrow
###################
MOVE RIGHT:
Right arrow
###################
MOVE LEFT:
Left arrow
###################
ATTACK:
a
###################
ABILITY 1:
z
###################
ABILITY 2:
e
###################
ABILITY 3:
r
###################
BACK TO MAIN:
Escape
###################
###################
###################
###################
###################
###################
###################
###################
#/bin/sh
git config --bool hooks.allownonascii "false"
exit 0
......@@ -18,6 +18,8 @@ def main():
else:
print("Invalid arguments. Usage: python fix_whitespace.py foo.py")
sys.exit(1)
if ".java" not in sys.argv[1]:
return 0
fix_whitespace(fname)
......
......@@ -2,12 +2,14 @@ package artificial_intelligence;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Logger;
import artificial_intelligence.AIEntities.*;
import core.gamestate.GameContent;
import core.relayer.Relayer;
import logging.Logging;
import ingame_programming.IGPEntity;
/**
* @author Guerquin Arnaud && Ramusat Yann
......@@ -19,7 +21,7 @@ import logging.Logging;
public class AIControler {
private static ArrayList<AbstractEntity> list=new ArrayList<>();
private static HashMap<Integer,AbstractEntity> hashMap = new HashMap<>();
static Logger LOGGER = new Logging().getLogger();
static Logger LOGGER = Logging.getInstance().getLogger();
/**
* Create a new AI of indicated type given as context a gameContent and a relayer to contact.
......@@ -30,18 +32,28 @@ public class AIControler {
public static void add(GameContent gameContent, Relayer dmr, EnumBehaviourType type) {
AbstractEntity ai = null;
switch(type) {
case Agressive:
ai = new AgressiveEntity(gameContent,dmr);
break;
case Basic:
ai = new BasicEntity(gameContent,dmr);
break;
case Defender:
ai = new DefenderEntity(gameContent,dmr);
break;
default:
LOGGER.severe("Trying to instanciate unrecognized type of AI.");
break;
case Agressive:
ai = new AgressiveEntity(gameContent,dmr);
break;
case Basic:
ai = new BasicEntity(gameContent,dmr);
break;
case Defender:
ai = new DefenderEntity(gameContent,dmr);
break;
case Follower:
ai = new IGPEntity(gameContent,dmr);
break;
case Straight:
ai = new StraightEntity(gameContent,dmr);
break;
case Boss:
ai = new BossEntity(gameContent,dmr);
break;
default:
LOGGER.severe("Trying to instanciate unrecognized type of AI.");
break;
}
list.add(ai);
hashMap.put(dmr.getCharacter().getID(),ai);
......@@ -69,7 +81,7 @@ public class AIControler {
*/
public static void killAll(){
for(AbstractEntity ai :list){
ai.setEndThread(false);
ai.setEndThread(true);
}
list.clear();
hashMap.clear();
......@@ -82,7 +94,7 @@ public class AIControler {
public static boolean killOne(int entityID){
AbstractEntity ai = hashMap.get(entityID);
if (ai!=null) {
ai.setEndThread(false);
ai.setEndThread(true);
list.remove(ai);
hashMap.remove(entityID);
return true;
......@@ -91,6 +103,23 @@ public class AIControler {
}
}
public static void killAllBut(List<Integer> idList){
for(AbstractEntity entity:list){
int id = entity.GetRelay().getCharacter().getID();
if(!idList.contains(id)){
entity.setEndThread(true);
}
}
list.clear();
HashMap<Integer,AbstractEntity> aux = new HashMap<>();
for(int id : idList){
AbstractEntity entity = hashMap.get(id);
list.add(entity);
aux.put(id, entity);
}
hashMap = aux;
}
/**
* To start all the AIs at the begining of the map and after init complete inialization.
*/
......
package artificial_intelligence.AIEntities;
import artificial_intelligence.GameOpt;
import core.gamestate.Entity;
import core.gamestate.GameContent;
import core.gamestate.GameState;
import core.relayer.Relayer;
import core.zone.Direction;
import gameloop.ServerLoop;
import logging.Logging;
import map_generation.map.Map;
import java.util.List;
import java.util.logging.Logger;
import static java.lang.Math.abs;
import static java.lang.Math.random;
import static java.lang.Math.sqrt;
/**
* Created by Yann RAMUSAT on 17/11/15.
......@@ -28,9 +32,8 @@ public abstract class AbstractEntity extends Thread {
// to have direct access to the map
protected Map map;
protected Relayer relayer;
/* Intern information */
protected boolean endThread;
protected boolean endThread = false;
public Map GetMap()
{
......@@ -42,13 +45,15 @@ public abstract class AbstractEntity extends Thread {
return relayer;
}
private Logger LOGGER = Logging.getInstance().getLogger();
/**
* Instanciate by default an autonomous AI given as context a GameContent and a Relayer to contact.
*
* This use the classes used by the network.
*
* @param GameContent the actual content of the game. Map + Entities.
* @param Relayer the relayer to contact.
* @param gameContent the actual content of the game. Map + Entities.
* @param relayer the relayer to contact.
*/
public AbstractEntity(GameContent gameContent, Relayer relayer) {
if(gameContent != null) {
......@@ -58,6 +63,7 @@ public abstract class AbstractEntity extends Thread {
this.relayer = relayer;
}
/**
* Default constructor.
*/
......@@ -70,20 +76,25 @@ public abstract class AbstractEntity extends Thread {
* @return the index of the victim in the EntityList.
*/
public int Choose_victim(){
float dmin =0 ;
double dmin =0 ;
double dmax = 32*15; // tiles of length 32 : so 15 tiles
int victim = -1;
List<Entity> entityList=gameState.getAllEntities();
for (int i=0;i<entityList.size();i++) {
Entity act_entity = entityList.get(i);
if (act_entity.getFaction() == 1) { // if act_entity is a player
float d = (act_entity.getX() - this.relayer.getCharacter().getX()) ^ 2 + (act_entity.getY() - this.relayer.getCharacter().getY()) ^ 2;
if (dmin == 0) {
dmin = d;
victim = i;
} else {
if (d != 0 && dmin < d) {
//euclidian distance and distance of manathan
//double d = sqrt((act_entity.getX() - this.relayer.getCharacter().getX())*(act_entity.getX() - this.relayer.getCharacter().getX()) + (act_entity.getY() - this.relayer.getCharacter().getY())*(act_entity.getY() - this.relayer.getCharacter().getY()));
double d = abs( (act_entity.getX() - this.relayer.getCharacter().getX()) )+abs(act_entity.getY() - this.relayer.getCharacter().getY());
if (d<dmax) {
if (dmin == 0) {
dmin = d;
victim = i;
} else {
if (d != 0 && dmin < d) {
dmin = d;
victim = i;
}
}
}
}
......@@ -91,73 +102,195 @@ public abstract class AbstractEntity extends Thread {
return(victim);
}
public double Distance_to_victim(Entity victim){
//euclidian distance and distance of manathan
//double d = sqrt((victim.getX() - this.relayer.getCharacter().getX())*(victim.getX() - this.relayer.getCharacter().getX()) + (victim.getY() - this.relayer.getCharacter().getY())*(victim.getY() - this.relayer.getCharacter().getY()));
double d = abs( (victim.getX() - this.relayer.getCharacter().getX()) )+abs(victim.getY() - this.relayer.getCharacter().getY());
return(d);
}
/**
* Given a target return the next move to do.
*
* @param int the index of the entity to move to.
* @param victim_i the pointer to the victim
*/
public void move_to_victim(int victim_i){
public void move_to_victim(Entity victim_i){
List<Entity> entityList=gameState.getAllEntities();
if(victim_i!=-1){
Entity victim= entityList.get(victim_i);
// X is UP-DOWN
int Delta_x = this.relayer.getCharacter().getX()-victim.getX();
// Y is LEFT-RIGHT
int Delta_y = this.relayer.getCharacter().getY()-victim.getY();
if(abs(Delta_x)>abs(Delta_y)){
if(Delta_x>0) {
this.relayer.move(Direction.UP);
}
else {
this.relayer.move(Direction.DOWN);
}
Entity victim= (victim_i);
// X is UP-DOWN
int Delta_x = this.relayer.getCharacter().getX()-victim.getX();
// Y is LEFT-RIGHT
int Delta_y = this.relayer.getCharacter().getY()-victim.getY();
if(abs(Delta_x)>abs(Delta_y)){
if(Delta_x>0) {
this.relayer.move(Direction.UP);
}
else {
this.relayer.move(Direction.DOWN);
}
else{ // REPAIRE INVERSE !
if (Delta_y>0) {
}
else{ // REPAIRE INVERSE !
if (Delta_y>0) {
this.relayer.move(Direction.LEFT);
}
else{
this.relayer.move(Direction.RIGHT);
}
}
}
public void run_from_victim(Entity victim_i){ //same then move_to_victim we just inverted the directions
List<Entity> entityList=gameState.getAllEntities();
Entity victim= (victim_i);
// X is UP-DOWN
int Delta_x = this.relayer.getCharacter().getX()-victim.getX();
// Y is LEFT-RIGHT
int Delta_y = this.relayer.getCharacter().getY()-victim.getY();
if(abs(Delta_x)>abs(Delta_y)){
if(Delta_x>0) {
this.relayer.move(Direction.DOWN);
}
else {
this.relayer.move(Direction.UP);
}
}
else{ // REPAIRE INVERSE !
if (Delta_y>0) {
this.relayer.move(Direction.RIGHT);
}
else{
this.relayer.move(Direction.LEFT);
}
}
}
public void random_move(){
double r = random();
if(r<0.25){
this.relayer.move(Direction.RIGHT);
}
else {
if (r < 0.5) {
this.relayer.move(Direction.UP);
} else {
if (r < 0.75) {
this.relayer.move(Direction.DOWN);
} else {
this.relayer.move(Direction.LEFT);
}
else{
this.relayer.move(Direction.RIGHT);
}
}
}
}
/**
* This is the function sequentially called by run.
* The behaviour of the AI is implemented here.
*
* This is the only function that have to be overriden by specifics AIs.
*/
public void act() {
public void move_and_shoot(Entity victim){
// X is UP-DOWN
int Delta_x = this.relayer.getCharacter().getX()-victim.getX();
// Y is LEFT-RIGHT
int Delta_y = this.relayer.getCharacter().getY()-victim.getY();
int distance_to_shoot = 24; // distance of tolerance of alignment
if(abs(Delta_x)<distance_to_shoot){ //we are well enough aligned to shoot
if(Delta_y<0){ // choose side to shoot
if(relayer.getCharacter().getDirection()==Direction.RIGHT){ //right side, we shoot
this.relayer.move(Direction.NONE);
this.relayer.tryToCastAbility(1);
}
else{
this.relayer.move(Direction.RIGHT); //wrong side, we turn
}
}
else{
if(relayer.getCharacter().getDirection()==Direction.LEFT){
this.relayer.move(Direction.NONE);
this.relayer.tryToCastAbility(1);
}
else{
this.relayer.move(Direction.LEFT);
}
}
}
else if(abs(Delta_y)<distance_to_shoot){
if(Delta_x<0){
if(relayer.getCharacter().getDirection()==Direction.DOWN){
this.relayer.move(Direction.NONE);
this.relayer.tryToCastAbility(1);
}
else{
this.relayer.move(Direction.DOWN);
}
}
else{
if(relayer.getCharacter().getDirection()==Direction.UP){
this.relayer.move(Direction.NONE);
this.relayer.tryToCastAbility(1);
}
else{
this.relayer.move(Direction.UP);
}
}
}
else{ // we have to move to be align
if(abs(Delta_x)<abs(Delta_y)){
if(Delta_x<0){
this.relayer.move(Direction.DOWN);
}
else{
this.relayer.move(Direction.UP);
}
}
else{
if(Delta_y<0){
this.relayer.move(Direction.RIGHT);
}
else{
this.relayer.move(Direction.LEFT);
}
}
}
}
public void act() {
}
/**
* Function called by the core/game_loop (call the function start() not run() because run is sequential) to launch the effective AI.
*/
@Override
public void run() {
System.out.println("AI launched.");
LOGGER.info("AI launched.");
/* Running opt 1 */
while(!relayer.getCharacter().isDead() && !endThread) {
/*while(!relayer.getCharacter().isDead() && !endThread) {
act();
try {
sleep(GameOpt.getInstance().getSpeedMs());
} catch (InterruptedException e) {
System.out.println("sleep()");
LOGGER.info("sleep()");
}
}
Relayers.killOne(relayer.getID());*/
/* Running opt 2 */
long ltime = System.currentTimeMillis();
while(true){
while(!relayer.getCharacter().isDead() && !endThread){
long ctime = System.currentTimeMillis();
while(ctime - ltime > ServerLoop.frame){
this.move_to_victim(this.Choose_victim());
while(ctime - ltime > ServerLoop.frame) {
ltime += ServerLoop.frame;
ctime= System.currentTimeMillis();
act();
}
act();
try{
Thread.sleep(ServerLoop.frame - (ctime - ltime));
}catch(InterruptedException e){
......@@ -169,9 +302,9 @@ public abstract class AbstractEntity extends Thread {
/**
* Enable or disable the AI.
*
* @param boolean endThread enable or not.
* @param endThread enable or not.
*/
public synchronized void setEndThread(boolean endThread) {
this.endThread = endThread;
}
}
\ No newline at end of file
}
......@@ -12,8 +12,8 @@ public class AgressiveEntity extends AbstractEntity {
*
* This use the classes used by the network.
*
* @param GameContent the actual content of the game. Map + Entities.
* @param Relayer the relayer to contact.
* @param gameContent the actual content of the game. Map + Entities.
* @param relayer the relayer to contact.
*/
public AgressiveEntity(GameContent gameContent, Relayer relayer) {
super(gameContent, relayer);
......
......@@ -5,9 +5,13 @@ import core.gamestate.Entity;
import core.gamestate.GameContent;
import core.relayer.Relayer;
import core.zone.Direction;
import core.zone.ZoneUnion;
import logging.Logging;
import java.util.List;
import static java.lang.Math.random;
/**