Commit 2042e2e1 authored by Louis Cohen's avatar Louis Cohen
Browse files

add boss ia and modification of the current ia functions

parent 29923d5f
......@@ -47,6 +47,10 @@ public class AIControler {
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;
......
......@@ -14,6 +14,7 @@ import java.util.logging.Logger;
import static java.lang.Math.abs;
import static java.lang.Math.random;
import static java.lang.Math.sqrt;
/**
......@@ -75,14 +76,16 @@ public abstract class AbstractEntity extends Thread {
* @return the index of the victim in the EntityList.
*/
public int Choose_victim(){
float dmin =0 ;
float dmax = 100000;
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())*(act_entity.getX() - this.relayer.getCharacter().getX()) + (act_entity.getY() - this.relayer.getCharacter().getY())*(act_entity.getY() - this.relayer.getCharacter().getY());
//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;
......@@ -99,76 +102,21 @@ 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 victim_i the pointer to the victim
*/
public void move_to_entity(Entity victim) {
// X is UP-DOWN
int px = this.relayer.getCharacter().getX();
int py = this.relayer.getCharacter().getY();
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);
if(px == this.relayer.getCharacter().getX()){
double r = random() % 2;
if(r==0){
this.relayer.move(Direction.LEFT);
System.out.println("pas mal");
}
else{
this.relayer.move(Direction.RIGHT);
System.out.println("pas mal");
}
}
}
else {
this.relayer.move(Direction.DOWN);
if(px == this.relayer.getCharacter().getX()){
double r = random() % 2;
if(r==0){
this.relayer.move(Direction.LEFT);
System.out.println("pas mal");
}
else{
this.relayer.move(Direction.RIGHT);
System.out.println("pas mal");
}
}
}
}
else{ // REPAIRE INVERSE !
if (Delta_y>0) {
this.relayer.move(Direction.LEFT);
if(py == this.relayer.getCharacter().getY()){
double r = random() % 2;
if(r==0){
this.relayer.move(Direction.UP);
}
else{
this.relayer.move(Direction.DOWN);
}
}
}
else{
this.relayer.move(Direction.RIGHT);
if(py == this.relayer.getCharacter().getY()){
double r = random() % 2;
if(r==0){
this.relayer.move(Direction.UP);
}
else{
this.relayer.move(Direction.DOWN);
}
}
}
}
}
public void move_to_victim(Entity victim_i){
List<Entity> entityList=gameState.getAllEntities();
......@@ -196,6 +144,33 @@ public abstract class AbstractEntity extends Thread {
}
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){
......@@ -219,10 +194,57 @@ public abstract class AbstractEntity extends Thread {
*
* 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 = 32; // distance of tolerance of alignment
if(abs(Delta_x)<distance_to_shoot){
if(Delta_x<0){
this.relayer.move(Direction.RIGHT);
this.relayer.tryToCastAbility(1);
}
else{
this.relayer.move(Direction.LEFT);
this.relayer.tryToCastAbility(1);
}
}
else if(abs(Delta_y)<distance_to_shoot){
if(Delta_y<0){
this.relayer.move(Direction.DOWN);
this.relayer.tryToCastAbility(1);
}
else{
this.relayer.move(Direction.UP);
this.relayer.tryToCastAbility(1);
}
}
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.
*/
......
package artificial_intelligence.AIEntities;
import artificial_intelligence.AlphaStar.AI;
import core.gamestate.Entity;
import core.gamestate.GameContent;
import core.relayer.Relayer;
import core.zone.Direction;
import logging.Logging;
import java.util.List;
import static java.lang.Math.random;
/**
* Created by Yann RAMUSAT on 30/12/15.
*/
public class BossEntity extends AbstractEntity {
/**
* Instanciate a basic 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.
*/
public BossEntity(GameContent gameContent, Relayer relayer) {
super(gameContent, relayer);
}
/**
* This is the function sequentially called by run.
* The behaviour of the basic AI is implemented here.
*/
@Override
public void act() {
// basic targeting and pathfinding
int victim_i = this.Choose_victim();
if (victim_i!=-1) {
Entity victim = this.gameState.getAllEntities().get(victim_i);
/* d_min minimum distance to not run away
* dmax maximum distance to not get closer*/
double d_min = 32*1; // tiles of length 32 : so 3 and 7 tiles
double d_max = 32*15;
double d = Distance_to_victim(victim);
if(d<d_min){
this.run_from_victim(victim);
}
else {
if (d > d_max) {
this.move_to_victim(victim);
}
else{
move_and_shoot(victim);
}
}
}
else{
Direction dir = this.relayer.getCharacter().getDirection();
double r = random();
if(r<0.8){
for(int i=0; i<1;i++) {
this.relayer.move(Direction.NONE);
}
}
else{this.random_move();}
}
// attack
this.relayer.tryToCastAbility(1);
}
}
......@@ -8,5 +8,6 @@ public enum EnumBehaviourType {
Basic,
Defender,
Follower,
Boss,
Straight;
}
......@@ -41,6 +41,7 @@ public class StraightEntity extends AbstractEntity {
//this.move_to_victim(gameState.getAllEntities().get(this.Choose_victim()));
if (relayer.getCharacter().getCollisionBox().intersect(gameState.getAllEntities().get(this.Choose_victim()).getCollisionBox())) {
this.relayer.move(Direction.NONE);
this.relayer.tryToCastAbility(0); // if we are close enough we fight and don't move
}
else {
this.move_to_victim(gameState.getAllEntities().get(this.Choose_victim()));
......@@ -63,6 +64,5 @@ public class StraightEntity extends AbstractEntity {
}
// attack
this.relayer.tryToCastAbility(0);
}
}
......@@ -41,7 +41,7 @@ public class GameContent implements Serializable{
for(Entity e:map.getEntities()){
gameState.addEntity(e);
Relayer dmr = Relayers.addNewRelayer(e);
AIControler.add(this,dmr, EnumBehaviourType.Straight);
AIControler.add(this,dmr, EnumBehaviourType.Boss);
}
}
int posX=(map.getPositionPlayerStart().getI())*Point.TileScale;
......@@ -138,7 +138,7 @@ public class GameContent implements Serializable{
for(Entity e:map.getEntities()){
gameState.addEntity(e);
Relayer dmr = Relayers.addNewRelayer(e);
AIControler.add(this,dmr, EnumBehaviourType.Basic);
AIControler.add(this,dmr, EnumBehaviourType.Straight);
}
}
int posX=(map.getPositionPlayerStart().getI())*Point.TileScale;
......
Markdown is supported
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