class PlayerAI {
  constructor() {
    this.have_ball = false
    this.toball_cnt = 0
    this.agressive_cnt = 0
    this.tofront_cnt = 0
    this.togoal_cnt = 0
    this.managed = []
    for (var p in this.players) {
      if (p.ball) this.have_ball = true
    }
  }


    step(dt) {

    }

  manage(player , dt) {
    if (this.managed[player] == null) {
      this.managed[player] = {
        "mode" : "toball",
        "lastmode_ts" : 0,
      }
    }
    var infos = this.managed[player]
    var goals = [
      [106,-101,-114], // goal area on left side
      [283,-101,-114], // goal area on right side
    ]

    // set  ai behaviour
    if (player.ball) {
      if (player.body.GetPosition().get_x() < (goals[0][0] + 40) // when near the goal and have ball
       && player.body.GetPosition().get_y() < goals[0][1]
       && player.body.GetPosition().get_y() > goals[0][2]) {
         infos.mode = "togoal"
         this.togoal_cnt = this.togoal_cnt + 1
      }
    } else {
      infos.mode = 'tofrontgoal'
      this.tofront_cnt = managed.tofront_cnt + 1      
    }


    }

    clear() {

    }
}

@@ -486,16 +486,42 @@
 player%5D%0A
+    var mode_duration = 3%0A
     var 
@@ -530,16 +530,16 @@
 als = %5B%0A
-
       %5B1
@@ -686,24 +686,26 @@
 ll) %7B%0A      
+  
 if (player.b
@@ -787,16 +787,18 @@
 ve ball%0A
+  
        &
@@ -850,24 +850,26 @@
 %5D%5B1%5D%0A       
+  
 && player.bo
@@ -915,24 +915,26 @@
  %7B%0A         
+ 
+ 
 infos.mode =
@@ -943,16 +943,18 @@
 togoal%22%0A
+  
         
@@ -992,28 +992,24 @@
 cnt + 1%0A    
-  %7D%0A
     %7D else %7B
@@ -1011,24 +1011,28 @@
 lse %7B%0A      
+    
 infos.mode =
@@ -1046,16 +1046,20 @@
 ntgoal'%0A
+    
       th
@@ -1102,15 +1102,827 @@
  + 1
+%0A  
       
-%0A
+%7D%0A      %7D else %7B%0A        if (this.have_ball) %7B // an another ennemy player have the ball%0A          infos.mode = 'agressive'%0A          this.agressive_cnt = managed.agressive_cnt + 1%0A        %7D else if (infos.lastmode == null %7C%7C infos.lastmode_ts  %3E mode_duration then) %7B%0A          infos.lastmode_ts = 0%0A          if (this.toball_cnt %3E 0 && (Math.random() %3C 0.5 or this.toball_cnt == 0)) %7B%0A            infos.mode = 'agressive' -- make one agressive, then random%0A            this.agressive_cnt = this.agressive_cnt + 1%0A          %7D else %7B%0A            infos.mode = 'toball' -- if one agressive then one here, then random%0A            this.toball_cnt = this.toball_cnt + 1%0A          %7D%0A%0A        %7D else %7B%0A          infos.lastmode_ts = infos.lastmode_ts + dt%0A          infos.mode = infos.lastmode          %0A        %7D%0A%0A%0A  
     

set ai enemy behaviour for player in team