Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#2126 Le 08/01/2012, à 20:23

Elzen

Re : /* Topic des codeurs [6] */

Bon, quelques nouvelles de cette histoire de périphériques : en fait, maintenant, /etc/mtab n'est apparemment plus qu'un lien symbolique vers /proc/mounts…

Côté utilisation normale, j'ai toujours ma racine qui est indiquée dedans par UUID, je n'sais pas pourquoi, et ça rend juste super moche quand je lance une commande genre df, donc si quelqu'un a des infos là-dessus, j'veux bien, mais ç'n'est pas super urgent.

Côté Touhy, j'ai refait un peu plus proprement mon gestionnaire de point de montages, qui est maintenant entièrement basé sur dbus pour l'écoute des événements sur les disques physiques, et qui gère enfin les lecteurs CDs (avec quelques trucs funs du genre quand tu demandes à monter un lecteur dans lequel il n'y a pas de CD, il s'ouvre). Donc pour tout ce qui est disques physiques, ça roule sans problème.

La difficulté, c'est pour les disques virtuels (isos, sshfs…) : comme /etc/mtab est un lien symbolique, il n'est plus modifié, donc je ne peux plus relancer une vérif à chaque fois qu'il est modifié (et /proc n'est pas un vrai système de fichiers, la date de dernière modif des fichiers qu'il y a dedans correspond toujours au timestamp actuel, donc je n'peux pas lancer une vraie écoute de modifs dessus).

Du coup, je peux savoir si un répertoire contient ou non un disque virtuel à un moment donné, mais je n'arrive plus à être prévenu automatiquement des événements de montage/démontage dessus. Faire une boucle qui aille périodiquement relire le contenu de /proc/mounts pour savoir si quelque chose à changé serait juste super moche…

J'ai un peu cherché, notamment du côté de python-fuse, mais je n'ai rien trouvé qui permette de savoir ça.

Donc voilà, p'tite annonce du jour : si quelqu'un connaissait un moyen d'être informé à chaque fois qu'on utilise fuse pour monter/démonter un support virtuel, j'veux bien des infos wink

Hors ligne

#2127 Le 09/01/2012, à 15:25

The Uploader

Re : /* Topic des codeurs [6] */

diff --git a/src/com/Antubis/AntubisAgentType.as b/src/com/Antubis/AntubisAgentType.as
new file mode 100644
index 0000000..f863571
--- /dev/null
+++ b/src/com/Antubis/AntubisAgentType.as
@@ -0,0 +1,29 @@
+package com.Antubis 
+{
+    import com.novabox.MASwithTwoNests.AgentType;
+    /**
+     * Cognitive Multi-Agent System Example
+     * Part 2 : Two distinct termite nests
+     * (Termites collecting wood)
+     * 
+     * @author Maximilien Noal & Antubis Team
+     * @version 1.0
+     */
+    
+    //*****************************************************************
+    // TODO : Register here all new agent types (Bot and Messages)
+    //*****************************************************************
+     
+    public class AntubisAgentType {
+        public static const ANTUBIS_BOT:AgentType = new AgentType(    AntubisBot,
+                                                                    0.625
+                                                                    );
+        public static const PHERO_BOT:AgentType = new AgentType(     PheroBot,
+                                                                    0.375
+                                                                    );
+        public static const PHERO:AgentType = new AgentType(        Phero,
+                                                                    0
+                                                                    );
+    }
+
+}
\ No newline at end of file
diff --git a/src/com/Antubis/AntubisBot.as b/src/com/Antubis/AntubisBot.as
index 58ab5d0..cf08507 100644
--- a/src/com/Antubis/AntubisBot.as
+++ b/src/com/Antubis/AntubisBot.as
@@ -1,5 +1,6 @@
 package com.Antubis 
 {
+    import com.novabox.MASwithTwoNests.World;
     import com.novabox.MASwithTwoNests.AgentCollideEvent;
     import com.novabox.MASwithTwoNests.AgentType;
     import com.novabox.MASwithTwoNests.Bot;
@@ -9,7 +10,6 @@
     import com.novabox.MASwithTwoNests.TimeManager;
     import com.novabox.MASwithTwoNests.Agent;
     import com.novabox.MASwithTwoNests.Main;
-    import com.novabox.MASwithTwoNests.World;
     import com.novabox.MASwithTwoNests.Resource;
     import com.novabox.expertSystem.Fact;
     import com.novabox.expertSystem.Rule;
@@ -34,13 +34,9 @@
 
     public class AntubisBot extends Bot {
         
-        private static const EDGE_LIMIT:Number             = 6;
-        public static const MAX_LIVING_PHEROS:Number     = 80; //Ideally, the number of bots in the team * 2
-        public static var livingPheros:Number             = 0;
-        public  var lastSeenResource:Point;
-        private var lastSeenPhero:Phero;
-        private var lastDropedPhero:Phero;
-        private var seenPhero:Phero;
+        protected static const EDGE_LIMIT:Number = 6;
+        protected var seenPhero:Phero;
+        protected var lastSeenResource:Point;
         
         public override function AntubisBot(_type:AgentType) {
             super(_type);
@@ -50,7 +46,8 @@
             CorrectLastSeenResource();
             super.Update();
             seenPhero = null;
-            lastDropedPhero = null;
+            seenResource = null;
+            lastSeenResource = null;
         }
         
         protected override function InitExpertSystem() : void {
@@ -68,12 +65,7 @@
                                                                                     AgentFacts.BIGGER_RESOURCE)));
                                                                                     
             expertSystem.AddRule(new Rule(CustomBotFacts.GO_TO_PHERO,    new Array(     CustomBotFacts.SEEN_PHERO,
-                                                                                    AgentFacts.NO_RESOURCE,
-                                                                                    CustomBotFacts.NO_RESOURCE_SEEN)));
-                                                                                    
-            expertSystem.AddRule(new Rule(CustomBotFacts.DROP_PHERO,    new Array(    CustomBotFacts.NO_PHERO_SEEN,
-                                                                                    CustomBotFacts.DROP_ALLOWED,
-                                                                                    CustomBotFacts.SEEN_RESOURCE)));
+                                                                                    AgentFacts.NO_RESOURCE)));
                                                                                     
             expertSystem.AddRule(new Rule(AgentFacts.TAKE_RESOURCE,     new Array(    AgentFacts.NO_RESOURCE,
                                                                                     AgentFacts.REACHED_RESOURCE)));
@@ -88,16 +80,10 @@
         }
         
         protected override function UpdateFacts() : void {
-            if (!seenPhero) {
-                expertSystem.SetFactValue(CustomBotFacts.NO_PHERO_SEEN, true);
-            } else if (seenPhero != lastDropedPhero && seenPhero != lastSeenPhero) {
+            if (seenPhero) {
                 expertSystem.SetFactValue(CustomBotFacts.SEEN_PHERO, true);
             }
             
-            if (livingPheros < MAX_LIVING_PHEROS) {
-                expertSystem.SetFactValue(CustomBotFacts.DROP_ALLOWED, true);    
-            }
-            
             if (IsNearEdges()) {
                 expertSystem.SetFactValue(CustomBotFacts.NEAR_EDGES, true);
             }
@@ -123,6 +109,8 @@
                 if (takenResource && seenResource.GetLife() > takenResource.GetLife()) {
                     expertSystem.SetFactValue(AgentFacts.BIGGER_RESOURCE, true);                            
                 }
+            } else {
+                expertSystem.SetFactValue(CustomBotFacts.SEE_NO_RESOURCE, true);
             }
             
             if (reachedResource) {
@@ -142,31 +130,16 @@
             }
         }
         
-        public override function GoToResource() : void {
-            GoToPoint(lastSeenResource);
-            lastSeenResource = null;
-            seenResource = null;
-            takenResource = null;
-            lastReachedResource = null;
-        }
-        
-        public function GoToPhero() : void {
-            GoToPoint(seenPhero.GetCurrentPoint());
-            seenPhero = null;
-            lastSeenPhero = null;
-        }
-        
         public override function onAgentCollide(_event:AgentCollideEvent) : void  {
             var collidedAgent:Agent = _event.GetAgent();
             super.onAgentCollide(_event);
             
             if (collidedAgent as Resource) {
-                lastSeenResource = GetCurrentOrTargetPoint(collidedAgent as Resource);
+                lastSeenResource = (collidedAgent as Resource).GetCurrentPoint();
             }
             
-            if (collidedAgent as Phero) {
+            if (collidedAgent as Phero && !(collidedAgent as Phero).IsDead()) {
                 seenPhero = (collidedAgent as Phero);
-                lastSeenPhero = seenPhero;
             }
             
             if (collidedAgent as Bot) {
@@ -178,32 +151,36 @@
             }
         }
         
+        protected function Chat(_seenBot:AntubisBot) : void {
+            CorrectLastSeenResource();
+            if (!lastSeenResource) {
+                lastSeenResource = _seenBot.GetLastSeenResource();
+            }
+            if (!homePosition) {
+                homePosition = _seenBot.GetHomePosition();
+            }
+        }
+        
         protected override function Act() : void {
             for (var i:int = 0; i < expertSystem.GetInferedFacts().length; i++) {
-                switch(expertSystem.GetInferedFacts()[i] as Fact) {    
-                    case CustomBotFacts.DROP_PHERO:
-                    DropPhero();
-                    break;
-                    
-                    case CustomBotFacts.GO_TO_PHERO:
+                if ((expertSystem.GetInferedFacts()[i] as Fact) == CustomBotFacts.GO_TO_PHERO) {
                     GoToPhero();
-                    break;
                 }
             }
             super.Act();
         }
         
-        protected function Chat(seenBot:AntubisBot) : void {
-            if (!lastSeenResource) {
-                lastSeenResource = seenBot.lastSeenResource;
-            }
-            if (!homePosition) {
-                homePosition = seenBot.GetHomePosition();
-            }
+        protected function GetLastSeenResource() : Point {
+            CorrectLastSeenResource();
+            return lastSeenResource;
         }
         
-        protected function DropPhero() : void {
-            Drop(lastDropedPhero = new Phero(CustomAgentType.PHERO));
+        protected function CorrectLastSeenResource() : void {
+            if (lastSeenResource) {
+                if (Point.distance(lastSeenResource, new Point(x, y)) <= perceptionRadius && !seenResource) {
+                    lastSeenResource = null;
+                }
+            }
         }
         
         protected function GoToPoint(_direction:Point) : void {
@@ -211,6 +188,21 @@
             direction.normalize(1);
         }
         
+        public override function GoToResource() : void {
+            GoToPoint(lastSeenResource);
+            lastSeenResource = null;
+            seenResource = null;
+            takenResource = null;
+            lastReachedResource = null;
+        }
+        
+        public function GoToPhero() : void {
+            if (seenPhero) {
+                GoToPoint(seenPhero.GetCurrentPoint());
+                seenPhero = null;
+            }
+        }
+        
         protected function IsAtHome() : Boolean {
             if (home) {
                 return (IsCollided(home));
@@ -226,23 +218,7 @@
         
         protected function IsCloser(_agent:Agent) : Boolean {
             return (Point.distance(new Point(_agent.x, _agent.y), new Point(x, y)) > 
-                    Point.distance(new Point(direction.x, direction.y), new Point(x, y)));
-        }
-        
-        protected function GetCurrentOrTargetPoint(_agent:Agent):Point {
-            if (Main.world.IsOut(_agent.GetTargetPoint())) {
-                return _agent.GetCurrentPoint();
-            } else {
-                return _agent.GetTargetPoint();
-            }
+                    Point.distance(direction, new Point(x, y)));
         }
-        
-        protected function CorrectLastSeenResource() : void {
-            if(lastSeenResource) {
-                if (Point.distance(new Point(lastSeenResource.x, lastSeenResource.y), new Point(x, y)) <= perceptionRadius && !seenResource) {
-                    lastSeenResource = null;
-                }
-            }
-        }        
     }
 }
\ No newline at end of file
diff --git a/src/com/Antubis/CustomAgentType.as b/src/com/Antubis/CustomAgentType.as
deleted file mode 100644
index 2690f5e..0000000
--- a/src/com/Antubis/CustomAgentType.as
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.Antubis 
-{
-    import com.novabox.MASwithTwoNests.AgentType;
-    /**
-     * Cognitive Multi-Agent System Example
-     * Part 2 : Two distinct termite nests
-     * (Termites collecting wood)
-     * 
-     * @author Maximilien Noal & Antubis Team
-     * @version 1.0
-     */
-    
-    //*****************************************************************
-    // TODO : Register here all new agent types (Bot and Messages)
-    //*****************************************************************
-     
-    public class CustomAgentType {
-        public static const ANTUBIS_BOT:AgentType = new AgentType(    AntubisBot,    // Bot Class
-                                                                    1            // Bot ratio in team
-                                                                    );
-        public static const PHERO:AgentType = new AgentType(        Phero,
-                                                                    1
-                                                                    );
-    }
-
-}
\ No newline at end of file
diff --git a/src/com/Antubis/CustomBotFacts.as b/src/com/Antubis/CustomBotFacts.as
index bae7bb9..ae7f181 100644
--- a/src/com/Antubis/CustomBotFacts.as
+++ b/src/com/Antubis/CustomBotFacts.as
@@ -16,23 +16,25 @@
 
     public class CustomBotFacts {
         
-        public static const SEEN_RESOURCE:Fact        = new Fact("Seen a resource.");
+        public static const SEE_NO_RESOURCE:Fact                = new Fact("No Resource is perceived.");
         
-        public static const NO_RESOURCE_SEEN:Fact    = new Fact("No resource seen.");
+        public static const SEEN_RESOURCE:Fact                    = new Fact("Seen a Resource.");
         
-        public static const NEAR_EDGES:Fact            = new Fact("Near one of the world's edges");
+        public static const NO_RESOURCE_SEEN:Fact                = new Fact("No Resource seen.");
         
-        public static const CLOSER_RESOURCE:Fact    = new Fact("Another resource is closer.");
+        public static const NEAR_EDGES:Fact                        = new Fact("Near one of the World's edges");
         
-        public static const SEEN_PHERO:Fact            = new Fact("Seen a phero.");
+        public static const CLOSER_RESOURCE:Fact                = new Fact("Another Resource is closer.");
         
-        public static const NO_PHERO_SEEN:Fact        = new Fact("Can see no phero.");
+        public static const SEEN_PHERO:Fact                        = new Fact("Seen a Phero.");
         
-        public static const DROP_PHERO:Fact            = new Fact("Will drop a phero.");
+        public static const LAST_DROPED_PHERO_IS_TOO_FAR:Fact    = new Fact("Last droped Phero is at midway of the perceptionRadius.");
         
-        public static const GO_TO_PHERO:Fact        = new Fact("Go to Phero action.");
+        public static const NO_PHERO_BOT_ON_THIS_RESOURCE:Fact    = new Fact("Didn't see another PheroBot on this Resource.");
         
-        public static const DROP_ALLOWED:Fact        = new Fact("Can drop a phero.");
+        public static const DROP_PHERO:Fact                        = new Fact("Drop Phero action.");
+        
+        public static const GO_TO_PHERO:Fact                    = new Fact("Go to Phero action.");
     }
 
 }
\ No newline at end of file
diff --git a/src/com/Antubis/Phero.as b/src/com/Antubis/Phero.as
index 21b40e9..4c62d06 100644
--- a/src/com/Antubis/Phero.as
+++ b/src/com/Antubis/Phero.as
@@ -1,11 +1,14 @@
 package com.Antubis 
 {
     import com.novabox.MASwithTwoNests.Agent;
-    import com.Antubis.AntubisBot;
+    import com.Antubis.PheroBot;
     import com.novabox.MASwithTwoNests.AgentType;
     import com.novabox.MASwithTwoNests.Resource;
     import com.novabox.MASwithTwoNests.TimeManager;
+    import com.novabox.MASwithTwoNests.AgentCollideEvent;
     import flash.geom.Point;
+    import flash.events.Event;
+    import flash.ui.MouseCursor;
     
     /**
      * ...
@@ -15,28 +18,40 @@ package com.Antubis
     {
         protected var color:int;
         protected var lifetime:Number;
-        public static const MAX_LIFETIME:Number = 9000;
+        protected var start_lifetime:Number;
+        protected var passes:Number                        = 0;
+        protected static const MAX_LIVING_PHEROS:Number    = 200;
+        public static const BASE_LIFETIME:Number        = 9000;
+        public const        MAX_PASSES:Number             = 50;
         
-        public function Phero(_type:AgentType) {
+        public function Phero(_type:AgentType, _lifetime:Number) {
             super(_type);
-            AntubisBot.livingPheros++;
-            if (AntubisBot.livingPheros > AntubisBot.MAX_LIVING_PHEROS) {
-                dead = true;
-            }
+            PheroBot.livingPheros++;
+            addEventListener(AgentCollideEvent.AGENT_COLLIDE, onAgentCollide);
             color = 0X6F2020;
-            lifetime = MAX_LIFETIME;
+            lifetime = _lifetime;
+            start_lifetime = _lifetime;
             graphics.beginFill(0XAAAAAA, 0);
             graphics.endFill();
         }
         
+        public function onAgentCollide(_event:AgentCollideEvent) : void {
+            var collidedAntubisBot:AntubisBot = _event.GetAgent() as AntubisBot;
+            if(collidedAntubisBot) {
+                if (!(collidedAntubisBot as PheroBot)) {
+                    passes++;
+                }
+            }
+        }
+        
         public override function Update() : void {
-            lifetime += TimeManager.timeManager.GetFrameDeltaTime();
-            if (lifetime <= 0) {
-                AntubisBot.livingPheros--;
+            lifetime -= TimeManager.timeManager.GetFrameDeltaTime();
+            if (lifetime <= 0 || passes >= MAX_PASSES || PheroBot.livingPheros > MAX_LIVING_PHEROS) {
+                PheroBot.livingPheros--;
                 dead = true;
             }
             graphics.clear();
-            graphics.beginFill(color, lifetime/MAX_LIFETIME);
+            graphics.beginFill(color, lifetime/start_lifetime);
             graphics.drawCircle(0, 0, 2);
             graphics.endFill();
         }
diff --git a/src/com/Antubis/PheroBot.as b/src/com/Antubis/PheroBot.as
new file mode 100644
index 0000000..216ce0a
--- /dev/null
+++ b/src/com/Antubis/PheroBot.as
@@ -0,0 +1,129 @@
+package com.Antubis 
+{
+    import com.novabox.expertSystem.Rule;
+    import com.novabox.expertSystem.Fact;
+    import com.novabox.MASwithTwoNests.AgentType;
+    import com.novabox.MASwithTwoNests.AgentFacts;
+    import com.novabox.MASwithTwoNests.AgentCollideEvent;
+    import com.novabox.MASwithTwoNests.Bot;
+    import com.novabox.MASwithTwoNests.BotHome;
+    import com.novabox.MASwithTwoNests.Agent;
+    import com.novabox.MASwithTwoNests.Resource;
+    import com.novabox.expertSystem.ExpertSystem;
+    import flash.display.ShaderJob;
+    import flash.geom.Point;
+    
+    /**
+     * ...
+     * @author Maximiliien Noal & Antubis-Team
+     */
+    public class PheroBot extends AntubisBot {
+        private var lastDropedPhero:Phero;
+        public static var livingPheros:Number;
+        private var seenPheroBot:PheroBot;
+        
+        public function PheroBot(_type:AgentType) {
+            super(_type);
+            color = 0x00FF00;
+            livingPheros = 0;
+        }
+        
+        public override function Update() : void {
+            super.Update();
+            seenPheroBot = null;
+        }
+        
+        protected override function InitExpertSystem() : void {
+            expertSystem = new ExpertSystem();
+            
+            expertSystem.AddRule(new Rule(AgentFacts.GO_TO_RESOURCE,    new Array(     AgentFacts.SEE_RESOURCE,
+                                                                                    CustomBotFacts.NO_PHERO_BOT_ON_THIS_RESOURCE)));
+            
+            expertSystem.AddRule(new Rule(CustomBotFacts.DROP_PHERO,     new Array(    CustomBotFacts.LAST_DROPED_PHERO_IS_TOO_FAR,
+                                                                                    AgentFacts.SEE_RESOURCE)));
+                                                                                    
+            expertSystem.AddRule(new Rule(AgentFacts.PUT_DOWN_RESOURCE,    new Array(    AgentFacts.AT_HOME,
+                                                                                    AgentFacts.GOT_RESOURCE)));
+                                                                                    
+            expertSystem.AddRule(new Rule(AgentFacts.TAKE_RESOURCE,     new Array(    AgentFacts.NO_RESOURCE,
+                                                                                    AgentFacts.AT_HOME,
+                                                                                    AgentFacts.REACHED_RESOURCE)));
+                                                                                
+            expertSystem.AddRule(new Rule(AgentFacts.CHANGE_DIRECTION,     new Array(    CustomBotFacts.NEAR_EDGES)));
+        }
+        
+        protected override function UpdateFacts() : void {
+            var lastSeenPhero:Phero = lastDropedPhero != null ? lastDropedPhero : seenPhero;
+            if (lastSeenPhero) {
+                if(Point.distance(new Point(lastSeenPhero.x, lastSeenPhero.y), new Point(x, y)) >= perceptionRadius/2) {
+                    expertSystem.SetFactValue(CustomBotFacts.LAST_DROPED_PHERO_IS_TOO_FAR, true);
+                }
+            } else {
+                expertSystem.SetFactValue(CustomBotFacts.LAST_DROPED_PHERO_IS_TOO_FAR, true);
+            }
+            
+            if (seenResource) {
+                expertSystem.SetFactValue(AgentFacts.SEE_RESOURCE, true);
+                if (seenPheroBot) {
+                    if(seenPheroBot.seenResource != seenResource && !Point.distance(seenResource.GetCurrentPoint(), seenPheroBot.GetCurrentPoint()) <= perceptionRadius/2) {
+                        expertSystem.SetFactValue(CustomBotFacts.NO_PHERO_BOT_ON_THIS_RESOURCE, true);
+                    }
+                }
+            }
+            
+            super.UpdateFacts();
+        }
+        
+        public override function onAgentCollide(_event:AgentCollideEvent) : void  {
+            var collidedAgent:Agent = _event.GetAgent();
+            
+            if (collidedAgent as Resource) {
+                seenResource = collidedAgent as Resource;
+                lastSeenResource = seenResource.GetCurrentPoint();
+                if (IsCollided(collidedAgent)) {
+                    reachedResource = (collidedAgent as Resource);
+                }
+            }
+            
+            if (collidedAgent as PheroBot) {
+                seenPheroBot = collidedAgent as PheroBot;
+            }
+            
+            if (collidedAgent as Bot) {
+                if ((collidedAgent  as Bot).GetTeamId() == teamId) {
+                    Chat(collidedAgent as AntubisBot);
+                }
+            }
+            
+            if (collidedAgent as Phero) {
+                seenPhero = collidedAgent as Phero;
+            }
+            
+            if (collidedAgent.GetType() == AgentType.AGENT_BOT_HOME) {
+                if ((collidedAgent as BotHome).GetTeamId() == teamId) {
+                    home = collidedAgent as BotHome;
+                    homePosition = new Point(home.GetTargetPoint().x, home.GetTargetPoint().y);
+                }
+            }
+        }
+        
+        protected override function Act() : void {
+            var inferedFacts:Array = expertSystem.GetInferedFacts();
+            
+            for (var i:int = 0; i < inferedFacts.length; i++) {
+                var fact:Fact = (inferedFacts[i] as Fact);
+                switch (fact) {
+                    case CustomBotFacts.DROP_PHERO:
+                    DropPhero();
+                    break;
+                }
+            }
+            super.Act();
+        }
+        
+        protected function DropPhero() : void {
+            Drop(lastDropedPhero = new Phero(AntubisAgentType.PHERO, Phero.BASE_LIFETIME*seenResource.GetLife()));
+        }
+    }
+
+}
\ No newline at end of file

http://www.youtube.com/watch?v=zzVXxnhufRA (Flash)
neutral


- Oldies PC : Intel Pentium 3 @ 800 Mhz sur CM ASUS P2B-F, GeForce 4 Ti4800 SE, Disque Dur Hitachi 160 Go, 512 Mo de RAM, 3DFX Voodoo 2, Sound Blaster 16 ISA PnP, Windows 98 SE / XP)
- Desktop : Intel Core i7 6700K @ 4 GHz sur CM ASUS Z170-P, GeForce GTX 1070, SSD Samsung 850 EVO 1 To, 16 Go de RAM, Disque Dur Seagate Barracuda 3 To, Windows 10

Hors ligne

#2129 Le 09/01/2012, à 18:42

The Uploader

Re : /* Topic des codeurs [6] */

Ah merde. >_< C'est bon j'ai changé en 'unlisted'. smile

diff --git a/src/com/Antubis/AntubisAgentType.as b/src/com/Antubis/AntubisAgentType.as
index f863571..ac9c40d 100644
--- a/src/com/Antubis/AntubisAgentType.as
+++ b/src/com/Antubis/AntubisAgentType.as
@@ -16,10 +16,10 @@
      
     public class AntubisAgentType {
         public static const ANTUBIS_BOT:AgentType = new AgentType(    AntubisBot,
-                                                                    0.625
+                                                                    0.7
                                                                     );
         public static const PHERO_BOT:AgentType = new AgentType(     PheroBot,
-                                                                    0.375
+                                                                    0.3
                                                                     );
         public static const PHERO:AgentType = new AgentType(        Phero,
                                                                     0
diff --git a/src/com/Antubis/AntubisBot.as b/src/com/Antubis/AntubisBot.as
index cf08507..9ea178b 100644
--- a/src/com/Antubis/AntubisBot.as
+++ b/src/com/Antubis/AntubisBot.as
@@ -36,7 +36,10 @@
         
         protected static const EDGE_LIMIT:Number = 6;
         protected var seenPhero:Phero;
+        protected var seenEnemyBot:Point;
+        protected var seenTeamBot:AntubisBot;
         protected var lastSeenResource:Point;
+        protected var stolen:Boolean             = false;
         
         public override function AntubisBot(_type:AgentType) {
             super(_type);
@@ -48,6 +51,9 @@
             seenPhero = null;
             seenResource = null;
             lastSeenResource = null;
+            seenEnemyBot = null;
+            seenTeamBot = null;
+            stolen = false;
         }
         
         protected override function InitExpertSystem() : void {
@@ -67,6 +73,12 @@
             expertSystem.AddRule(new Rule(CustomBotFacts.GO_TO_PHERO,    new Array(     CustomBotFacts.SEEN_PHERO,
                                                                                     AgentFacts.NO_RESOURCE)));
                                                                                     
+            expertSystem.AddRule(new Rule(CustomBotFacts.GO_TO_ENEMY_BOT, new Array(CustomBotFacts.SEEN_ENEMY_BOT,
+                                                                                    CustomBotFacts.NO_TEAM_BOT_SEEN,    
+                                                                                    AgentFacts.NO_RESOURCE,
+                                                                                    CustomBotFacts.NO_RESOURCE_SEEN,
+                                                                                    CustomBotFacts.SEE_NO_RESOURCE)));
+                                                                                    
             expertSystem.AddRule(new Rule(AgentFacts.TAKE_RESOURCE,     new Array(    AgentFacts.NO_RESOURCE,
                                                                                     AgentFacts.REACHED_RESOURCE)));
                                                                                     
@@ -84,6 +96,14 @@
                 expertSystem.SetFactValue(CustomBotFacts.SEEN_PHERO, true);
             }
             
+            if (seenEnemyBot) {
+                expertSystem.SetFactValue(CustomBotFacts.SEEN_ENEMY_BOT, true);
+            }
+            
+            if (!seenTeamBot) {
+                expertSystem.SetFactValue(CustomBotFacts.NO_TEAM_BOT_SEEN, true);
+            }
+            
             if (IsNearEdges()) {
                 expertSystem.SetFactValue(CustomBotFacts.NEAR_EDGES, true);
             }
@@ -144,9 +164,14 @@
             
             if (collidedAgent as Bot) {
                 if ((collidedAgent  as Bot).GetTeamId() == teamId) {
-                    Chat(collidedAgent as AntubisBot);
-                } else if ((collidedAgent as Bot).HasResource() && !hasResource) {
-                    StealResource(collidedAgent as Bot);
+                    seenTeamBot = collidedAgent as AntubisBot;
+                    Chat(seenTeamBot);
+                } else if (IsCollided(collidedAgent)) {
+                    seenEnemyBot = (collidedAgent as Bot).GetCurrentPoint();
+                    if ((collidedAgent as Bot).HasResource() && !hasResource && !stolen) {
+                        StealResource(collidedAgent as Bot);
+                        stolen = true;
+                    }
                 }
             }
         }
@@ -163,8 +188,15 @@
         
         protected override function Act() : void {
             for (var i:int = 0; i < expertSystem.GetInferedFacts().length; i++) {
-                if ((expertSystem.GetInferedFacts()[i] as Fact) == CustomBotFacts.GO_TO_PHERO) {
+                var fact:Fact = expertSystem.GetInferedFacts()[i] as Fact;
+                switch (fact) {
+                    case CustomBotFacts.GO_TO_PHERO:
                     GoToPhero();
+                    break;
+                    
+                    case CustomBotFacts.GO_TO_ENEMY_BOT:
+                    GoToEnemyBot();
+                    break;
                 }
             }
             super.Act();
@@ -188,6 +220,11 @@
             direction.normalize(1);
         }
         
+        protected function GoToEnemyBot() : void {
+            GoToPoint(seenEnemyBot);
+            seenEnemyBot = null;
+        }
+        
         public override function GoToResource() : void {
             GoToPoint(lastSeenResource);
             lastSeenResource = null;
diff --git a/src/com/Antubis/CustomBotFacts.as b/src/com/Antubis/CustomBotFacts.as
index ae7f181..5556750 100644
--- a/src/com/Antubis/CustomBotFacts.as
+++ b/src/com/Antubis/CustomBotFacts.as
@@ -26,6 +26,10 @@
         
         public static const CLOSER_RESOURCE:Fact                = new Fact("Another Resource is closer.");
         
+        public static const SEEN_ENEMY_BOT:Fact                    = new Fact("Seen an enemy Bot.");
+        
+        public static const NO_TEAM_BOT_SEEN:Fact                = new Fact("Seen no team Bot.");
+        
         public static const SEEN_PHERO:Fact                        = new Fact("Seen a Phero.");
         
         public static const LAST_DROPED_PHERO_IS_TOO_FAR:Fact    = new Fact("Last droped Phero is at midway of the perceptionRadius.");
@@ -35,6 +39,8 @@
         public static const DROP_PHERO:Fact                        = new Fact("Drop Phero action.");
         
         public static const GO_TO_PHERO:Fact                    = new Fact("Go to Phero action.");
+        
+        public static const GO_TO_ENEMY_BOT:Fact                = new Fact("Go to enemy bot action.");
     }
 
 }
\ No newline at end of file
diff --git a/src/com/Antubis/PheroBot.as b/src/com/Antubis/PheroBot.as
index 45e1e38..dc9abaa 100644
--- a/src/com/Antubis/PheroBot.as
+++ b/src/com/Antubis/PheroBot.as
@@ -10,7 +10,7 @@ package com.Antubis
     import com.novabox.MASwithTwoNests.Agent;
     import com.novabox.MASwithTwoNests.Resource;
     import com.novabox.expertSystem.ExpertSystem;
-    import flash.display.ShaderJob;
+    import com.novabox.MASwithTwoNests.World;
     import flash.geom.Point;
     
     /**
@@ -21,6 +21,8 @@ package com.Antubis
         private var lastDropedPhero:Phero;
         public static var livingPheros:Number;
         private var seenPheroBot:PheroBot;
+        private var onceReachedResource:Resource;
+        private var changed:Boolean;
         
         public function PheroBot(_type:AgentType) {
             super(_type);
@@ -28,6 +30,13 @@ package com.Antubis
         }
         
         public override function Update() : void {
+            if(onceReachedResource) {
+                ChangeIntoAntubisBotIfDead();
+            }
+            if (reachedResource) {
+                onceReachedResource = reachedResource;
+            }
+            
             super.Update();
             seenPheroBot = null;
         }
@@ -37,6 +46,12 @@ package com.Antubis
             
             expertSystem.AddRule(new Rule(AgentFacts.GO_TO_RESOURCE,    new Array(     AgentFacts.SEE_RESOURCE,
                                                                                     CustomBotFacts.NO_PHERO_BOT_ON_THIS_RESOURCE)));
+                                                                                    
+            expertSystem.AddRule(new Rule(CustomBotFacts.GO_TO_ENEMY_BOT,new Array(    CustomBotFacts.SEEN_ENEMY_BOT,
+                                                                                    CustomBotFacts.NO_RESOURCE_SEEN,
+                                                                                    CustomBotFacts.SEE_NO_RESOURCE,
+                                                                                    CustomBotFacts.NO_TEAM_BOT_SEEN,
+                                                                                    AgentFacts.NO_RESOURCE)));
             
             expertSystem.AddRule(new Rule(CustomBotFacts.DROP_PHERO,     new Array(    CustomBotFacts.LAST_DROPED_PHERO_IS_TOO_FAR,
                                                                                     AgentFacts.SEE_RESOURCE)));
@@ -64,7 +79,7 @@ package com.Antubis
             if (seenResource) {
                 expertSystem.SetFactValue(AgentFacts.SEE_RESOURCE, true);
                 if (seenPheroBot) {
-                    if(seenPheroBot.seenResource != seenResource && !Point.distance(seenResource.GetCurrentPoint(), seenPheroBot.GetCurrentPoint()) <= perceptionRadius/2) {
+                    if(seenPheroBot.seenResource != seenResource && !seenPheroBot.IsCollided(seenResource)) {
                         expertSystem.SetFactValue(CustomBotFacts.NO_PHERO_BOT_ON_THIS_RESOURCE, true);
                     }
                 }
@@ -75,35 +90,11 @@ package com.Antubis
         
         public override function onAgentCollide(_event:AgentCollideEvent) : void  {
             var collidedAgent:Agent = _event.GetAgent();
-            
-            if (collidedAgent as Resource) {
-                seenResource = collidedAgent as Resource;
-                lastSeenResource = seenResource.GetCurrentPoint();
-                if (IsCollided(collidedAgent)) {
-                    reachedResource = (collidedAgent as Resource);
-                }
-            }
+            super.onAgentCollide(_event);
             
             if (collidedAgent as PheroBot) {
                 seenPheroBot = collidedAgent as PheroBot;
             }
-            
-            if (collidedAgent as Bot) {
-                if ((collidedAgent  as Bot).GetTeamId() == teamId) {
-                    Chat(collidedAgent as AntubisBot);
-                }
-            }
-            
-            if (collidedAgent as Phero) {
-                seenPhero = collidedAgent as Phero;
-            }
-            
-            if (collidedAgent.GetType() == AgentType.AGENT_BOT_HOME) {
-                if ((collidedAgent as BotHome).GetTeamId() == teamId) {
-                    home = collidedAgent as BotHome;
-                    homePosition = new Point(home.GetTargetPoint().x, home.GetTargetPoint().y);
-                }
-            }
         }
         
         protected override function Act() : void {
@@ -123,6 +114,12 @@ package com.Antubis
         protected function DropPhero() : void {
             Drop(lastDropedPhero = new Phero(AntubisAgentType.PHERO, Phero.BASE_LIFETIME*seenResource.GetLife()));
         }
+        
+        protected function ChangeIntoAntubisBotIfDead() : void {
+            if(onceReachedResource.GetLife() <= 0 && !changed) { 
+                changed = true;
+                super.InitExpertSystem();
+            }
+        }
     }
-
 }
\ No newline at end of file
commit 4d877614c32d99b96ef76131160c5a1a45af126c
Author: Maximilien Noal <mnoal@epsi.fr>
Date:   Mon Jan 9 18:34:50 2012 +0100

    PheroBot becomes AntubisBot if onceReachedResource is dead

commit 34c0cc26f8313305facd5b2cfffcbb416d3a6231
Author: Maximilien Noal <mnoal@epsi.fr>
Date:   Mon Jan 9 18:03:39 2012 +0100

    GoToEnemyBot AntubisBot/PheroBot rule sync

commit a10a44788275a268f5de20da9086f64958393f9b
Author: Maximilien Noal <mnoal@epsi.fr>
Date:   Mon Jan 9 17:35:06 2012 +0100

    can steal only if collided (much less weird)

commit 9899f83da315037030ad14b3b512178926d5223a
Author: Maximilien Noal <mnoal@epsi.fr>
Date:   Mon Jan 9 17:32:49 2012 +0100

    Can steal only once per update (less weird)

commit 5237efe6a69ed547639d34e88e43aa9bb6160c30
Author: Maximilien Noal <mnoal@epsi.fr>
Date:   Mon Jan 9 17:17:25 2012 +0100

    PheroBot clean up & both Bots follow enemyBot if ALL alone

commit 6d8a47536cba20a7b1cb13a56514c4330a412f38
Author: Maximilien Noal <mnoal@epsi.fr>
Date:   Mon Jan 9 15:32:08 2012 +0100

    removed src/com/novabox from git (oops)

commit 81780535a2683ad49e5490ca302c7621aee1d45d
Author: Maximilien Noal <mnoal@epsi.fr>
Date:   Mon Jan 9 15:29:48 2012 +0100

    minor commit : removed set of color in PheroBot's constructor

commit ab6878fa2011751d8362ee635915550bd7fd82c9
Author: Maximilien Noal <mnoal@epsi.fr>
Date:   Mon Jan 9 14:45:38 2012 +0100

    removed PheroBot's AntubisMode

commit 6d6c172c1c7ec7872e0d85fbcc0b37c089729c2c
Author: Maximilien Noal <mnoal@epsi.fr>
Date:   Mon Jan 9 14:01:18 2012 +0100

    Enhanced PheroBot, Phero pop cap reintroduced

neutral

(bon j'pourrais faire une nouvelle vidéo, mais ça change pas tellement)

Dernière modification par The Uploader (Le 09/01/2012, à 18:53)


- Oldies PC : Intel Pentium 3 @ 800 Mhz sur CM ASUS P2B-F, GeForce 4 Ti4800 SE, Disque Dur Hitachi 160 Go, 512 Mo de RAM, 3DFX Voodoo 2, Sound Blaster 16 ISA PnP, Windows 98 SE / XP)
- Desktop : Intel Core i7 6700K @ 4 GHz sur CM ASUS Z170-P, GeForce GTX 1070, SSD Samsung 850 EVO 1 To, 16 Go de RAM, Disque Dur Seagate Barracuda 3 To, Windows 10

Hors ligne

#2130 Le 09/01/2012, à 19:32

Pylades

Re : /* Topic des codeurs [6] */

Hum, tu laisses ton adresse en clair ? hmm

#!/usr/bin/python
#coding=utf-8

import os
from os.path import basename, join
from urllib2 import urlopen
from urllib import urlretrieve
from BeautifulSoup import BeautifulSoup as Soup

url = 'http://apod.nasa.gov/apod/'
rep = '/home/paul/Documents/Images/apod/'

page = urlopen(url)
soup = Soup(page)
page.close()
image = soup.find('img')['src']
soup.close()
imageurl = join(url, image)
target = join(rep, basename(image))

urlretrieve(imageurl, target)

os.system('hsetroot -full %s' % target)

“Any if-statement is a goto. As are all structured loops.
“And sometimes structure is good. When it’s good, you should use it.
“And sometimes structure is _bad_, and gets into the way, and using a goto is just much clearer.”
                Linus Torvalds – 12 janvier 2003

Hors ligne

#2131 Le 09/01/2012, à 19:35

The Uploader

Re : /* Topic des codeurs [6] */

M'en fous, c'est l'adresse donnée par l'école. Et puis, les filtres de Thunderbird sont efficaces.


- Oldies PC : Intel Pentium 3 @ 800 Mhz sur CM ASUS P2B-F, GeForce 4 Ti4800 SE, Disque Dur Hitachi 160 Go, 512 Mo de RAM, 3DFX Voodoo 2, Sound Blaster 16 ISA PnP, Windows 98 SE / XP)
- Desktop : Intel Core i7 6700K @ 4 GHz sur CM ASUS Z170-P, GeForce GTX 1070, SSD Samsung 850 EVO 1 To, 16 Go de RAM, Disque Dur Seagate Barracuda 3 To, Windows 10

Hors ligne

#2132 Le 09/01/2012, à 19:46

grim7reaper

Re : /* Topic des codeurs [6] */

Bon, puisque tout le monde poste du code tongue
Récemment, je me suis repenché sur mon implémentation des divers calendriers. J’ai ajouté une propriété dans mes tests QuickCheck sur le calendrier égyptien et arménien.
Égyptien :

prop_nextDay :: Property
prop_nextDay = forAll generateFixed $ \ t ->
  let nextFixed = t + 1
      date = fromFixed t
      nextDate = fromFixed nextFixed
  in -- Stay in same month.
     (year nextDate  == year date  &&
      month nextDate == month date &&
      day nextDate   == day date + 1)
     || -- Pass to next month.
     (year nextDate  == year date         &&
      month nextDate == succ (month date) &&
      day nextDate   == 1)
     || -- Pass to next year.
     (year nextDate  == year date + 1 &&
      month nextDate == Thoth         &&
      day nextDate   == 1)

Arménien :

prop_nextDay = forAll generateFixed $ \ t ->
  let nextFixed = t + 1
      date = fromFixed t
      nextDate = fromFixed nextFixed
  in -- Stay in same month.
     (year nextDate  == year date  &&
      month nextDate == month date &&
      day nextDate   == case day date of
                             Normal n     -> Normal     $ succ n
                             Epagomenal e -> Epagomenal $ succ e)
     || -- Pass to next month.
     (year nextDate  == year date         &&
      month nextDate == succ (month date) &&
      day nextDate   == case month date of
                             Hroditz -> Epagomenal $ enumFromIntegral 1
                             _       -> Normal     $ enumFromIntegral 1)
     || -- Pass to next year.
     (year nextDate  == year date + 1 &&
      month nextDate == Navasart      &&
      day nextDate   == (Normal $ enumFromIntegral 1))

Et j’ai enfin commencé (mais juste commencé) l’implémentation du calendrier grégorien.

Hors ligne

#2133 Le 09/01/2012, à 22:59

grim7reaper

Re : /* Topic des codeurs [6] */

Et hop, j’ai fini ma fonction pour convertir une date grégorienne en Rata Die.

  toFixed date =
    let y  = year                       date
        m  = (integralFromEnum . month) date
        d  = (fromIntegral     . day)   date
        normalDays = 365 * (y - 1)
        leapDays   = floor ((fromIntegral y - 1) / 4)   -
                     floor ((fromIntegral y - 1) / 100) +
                     floor ((fromIntegral y - 1) / 400)
        -- The following formula assumes that February has 30 days.
        previousDays     = floor $ (367 * (fromIntegral m) - 362) / 12
        correction -- Correction for the previous formula.
          | m <= 2       = 0  -- We are before February, no correction needed.
          | isLeapYear y = -1 -- Leap year   => February has 29 days - 30 = -1.
          | otherwise    = -2 -- Normal year => February has 28 days - 30 = -2.
    in epoch - 1    + -- Start from 0 (because Epoch is Monday, January 1, 1).
       normalDays   + -- Number of days in previous years.
       leapDays     + -- Number of leap days in previous years.
       previousDays + -- Number of days in previous months of the current year.
       correction   + -- Correction of the previous approximation.
       d              -- Number of days in the current month.

Donc, si je me suis pas planté dans mon code (je n’ai pas encore réalisé énormément de tests, faut que je fasse la fonction fromFixed d’abord), aujourd’hui on est le 734 511 R.D

Pour ceux qui ne savent pas lire l’Haskell : la formule commence après le in, avant je ne fais que déclarer des variables ou réaliser des calculs intermédiaires.

Dernière modification par grim7reaper (Le 09/01/2012, à 23:01)

Hors ligne

#2134 Le 09/01/2012, à 23:26

The Uploader

Re : /* Topic des codeurs [6] */

J'connaissai même pas le Rata Die ! yikes

La seule fois où on a fait une sorte de gestion de calendriers ("on" : dans ma classe) c'était en pseudo langage procédural.............  *beurk* Et encore, que le Grégorien.

Inutile de dire que dans le cas présent ça a l'air plus propre. ^^


- Oldies PC : Intel Pentium 3 @ 800 Mhz sur CM ASUS P2B-F, GeForce 4 Ti4800 SE, Disque Dur Hitachi 160 Go, 512 Mo de RAM, 3DFX Voodoo 2, Sound Blaster 16 ISA PnP, Windows 98 SE / XP)
- Desktop : Intel Core i7 6700K @ 4 GHz sur CM ASUS Z170-P, GeForce GTX 1070, SSD Samsung 850 EVO 1 To, 16 Go de RAM, Disque Dur Seagate Barracuda 3 To, Windows 10

Hors ligne

#2135 Le 09/01/2012, à 23:51

grim7reaper

Re : /* Topic des codeurs [6] */

Le gros avantage (il y en a d’autres, mais je ne vais pas répéter Wikipédia) du Rata Die, c’est que c’est indépendant de tout calendrier ce qui en fait une unité pivot idéale pour les conversions.
En fait, chaque calendrier que je vais implémenter sera une instance de la typeclass (pour te faire un parallèle, c’est un peu comme une interface en orienté objet) Convertible (truc que j’ai défini moi-même).

class Convertible a where
  toFixed   :: a -> Fixed
  fromFixed :: Fixed -> a

Ainsi, je n’ai pas besoin de définir N * (N - 1) fonctions de conversion, une suffit pour convertir une date de n’importe quel calendrier vers un autre calendrier. Ma fonction convert a cette tête-là :

convert :: (Convertible a, Convertible b) => a -> b
convert = fromFixed . toFixed

Dernière modification par grim7reaper (Le 09/01/2012, à 23:59)

Hors ligne

#2136 Le 09/01/2012, à 23:58

The Uploader

Re : /* Topic des codeurs [6] */

Euuuhhhh, c'est tout ce qu'elle fait ta fonction convert ? (elle fait quoi d'ailleurs cette ligne ?) et ça fonctionne ? yikes

C'est du Haskell ?

Tellement puissant que j'ai pas compris grand chose. big_smile

grim' a écrit :

Ainsi, je n’ai pas besoin de définir N * (N - 1) fonctions de conversion

C'est vrai qu'en POO ce serait un peu plus difficile à éviter, mais possible, non ? Enfin dans le cas présent j'vois pas trop, mais j'ai bouffé de l'action script tout la journée, faut dire... ça grille les neurones.

Dernière modification par The Uploader (Le 10/01/2012, à 00:02)


- Oldies PC : Intel Pentium 3 @ 800 Mhz sur CM ASUS P2B-F, GeForce 4 Ti4800 SE, Disque Dur Hitachi 160 Go, 512 Mo de RAM, 3DFX Voodoo 2, Sound Blaster 16 ISA PnP, Windows 98 SE / XP)
- Desktop : Intel Core i7 6700K @ 4 GHz sur CM ASUS Z170-P, GeForce GTX 1070, SSD Samsung 850 EVO 1 To, 16 Go de RAM, Disque Dur Seagate Barracuda 3 To, Windows 10

Hors ligne

#2137 Le 10/01/2012, à 00:27

grim7reaper

Re : /* Topic des codeurs [6] */

The Uploader a écrit :

Euuuhhhh, c'est tout ce qu'elle fait ta fonction convert ?

Oui, et c’est ça toute la puissance de l’astuce smile

The Uploader a écrit :

(elle fait quoi d'ailleurs cette ligne ?)

Commençons pas le commencement : le prototype.

convert :: (Convertible a, Convertible b) => a -> b

En entrée je prend une date de type a (exprimé dans le calendrier a si tu préfères) et je produit une date de type b.
Ma fonction est générique mais impose que les types soient une instance de Convertible (pour être sûr de pour appliquer les fonctions toFixed et fromFixed).
Pour la petite histoire, le C++ voulait ajouter ça (la contrainte sur les types template, parce que c’est super pratique (genre tu définis une table de hachage avec des clefs de type K et des valeurs de type V, V peut être de n’importe quel type par contre K doit être un type où tu peux tester l’égalité)) pour le C++11 sous le nom de « concept » mais ça ne s’est pas fait (« In July 2009, the C++11 committee decided to remove concepts from the draft standard, as they are considered "not ready" for C++11 »).
Par exemple, si on veut convertir une date égyptienne en date grégorienne on pourrait réécrire le prototype comme ça :

convert :: Egyptian -> Gregorian

Ensuite, le code.

convert = fromFixed . toFixed

Ici je compose (au sens mathématique du terme) mes deux fonctions. Écrit de manière impérative ça donnerait :

fromFixed(toFixed(date))

Dans mon code on ne voit pas le paramètre date parce que ma fonction est curryfié (utilisation de la curryfication)
Donc au finale, je prend une date de type "a", je lui applique toFixed (j’obtiens donc une date R.D) et je converti cette date R.D en date de type "b" en utilisant fromFixed. Sachant que j’appelle la fonction toFixed de l’instance Convertible a (donc prototype a -> Fixed) et la fonction fromFixed de l’instance Convertible b (donc prototype Fixed -> b).
Je ne sais pas si je suis très clair hmm

The Uploader a écrit :

et ça fonctionne ? yikes

Farpaitement.

The Uploader a écrit :

C'est du Haskell ?

Yep.

The Uploader a écrit :

Tellement puissant que j'ai pas compris grand chose. big_smile

Un des trucs qui me séduit dans Haskell : puissant, concis et très lisible (bon, quand on s’est habitué à la programmation fonctionnelle et la syntaxe d’Haskell évidemment).
Un autre exemple que j’ai vu récemment.

The Uploader a écrit :
grim' a écrit :

Ainsi, je n’ai pas besoin de définir N * (N - 1) fonctions de conversion

C'est vrai qu'en POO ce serait un peu difficile à éviter, à moins d'être un pro du polymorphisme.

Je pense que c’est faisable, après je ne sais pas si ça nécessite d’être un « pro » car je t’avouerai que je ne me suis pas penché sur la question de comment le faire.

The Uploader a écrit :

Enfin dans le cas présent j'vois pas trop, mais j'ai bouffé de l'action script tout la journée, faut dire... ça grille les neurones.

Condoléances. T’en a encore pour longtemps de ce cours ?

Hors ligne

#2138 Le 10/01/2012, à 01:27

Pylades

Re : /* Topic des codeurs [6] */

Je viens de me confronter à la sagesse d’utiliser un système de gestion de versions pour ses fichiers de conf… -_-"


Sinon, c’est quoi l’avantage du Rata Die par rapport à simplement parler en temps Unix ?


“Any if-statement is a goto. As are all structured loops.
“And sometimes structure is good. When it’s good, you should use it.
“And sometimes structure is _bad_, and gets into the way, and using a goto is just much clearer.”
                Linus Torvalds – 12 janvier 2003

Hors ligne

#2139 Le 10/01/2012, à 01:31

The Uploader

Re : /* Topic des codeurs [6] */

Nan, la semaine prochaine on rend le projet, et c'est aussi la dernière semaine de cours. smile

En tout cas maintenant je sais quoi faire pour l'IA des unités de Gauge : un système expert. Et je saurai le faire. ^^

Enfin c'est loin j'en suis pas là encore. J'me demande si j'aurais le temps de m'y remettre un jour : pendant le prochain stage de 6 mois j'aurais un mémoire à gérer en même temps + d'autres trucs. Grrrrrrr.

Je ferai MON clone de Dune 2 A MOI. Je le ferai, j'ai dit ! C't'un défi. *cri de guerre*

Hum *s'éclaircit la gorge*

Sinon, pour Haskell j'ai à peu près tout compris. smile

En gros la curryfication :

 p = Proc.new { |a,b| a+b } => #<Proc:0x00000000ff5208> 
 
  #Appel classique
  p.call(3) => "TypeError: nil can't be coerced into Fixnum"
  p.call(3,4) => 7
 
  #Utilisation de la méthode curry
  p.curry[3][4] => 7
  #renvoie un Fixnum, car il y a eu le bon nombre d'arguments fournis.
 
  a = p.curry[3] => #<Proc:0x00000000f9b0c8>
  a.call(5) => 8
  a.call(10) => 13

Tu rends les appels "morcelés". Tu donnes les paramètres quand tu veux, quoi. (impossible de faire, en prenant le dernier exemple :

p.call(3)
p.call(5)

si on veut que ça donne 8).

grim' a écrit :

Un des trucs qui me séduit dans Haskell : puissant, concis et très lisible (bon, quand on s’est habitué à la programmation fonctionnelle et la syntaxe d’Haskell évidemment).

Pareil pour Ruby, mais en remplaçant programmation fonctionnelle par programmation entièrement orientée objet et la syntaxe. ^^

Tiens d'ailleurs : Ruby 2.0 : The End of Monkey Patching

grim' a écrit :

Je pense que c’est faisable, après je ne sais pas si ça nécessite d’être un « pro » car je t’avouerai que je ne me suis pas penché sur la question de comment le faire.

J'pense que c'est possible, mais que ça demanderait plus d'efforts, ou du moins de lignes de code.


- Oldies PC : Intel Pentium 3 @ 800 Mhz sur CM ASUS P2B-F, GeForce 4 Ti4800 SE, Disque Dur Hitachi 160 Go, 512 Mo de RAM, 3DFX Voodoo 2, Sound Blaster 16 ISA PnP, Windows 98 SE / XP)
- Desktop : Intel Core i7 6700K @ 4 GHz sur CM ASUS Z170-P, GeForce GTX 1070, SSD Samsung 850 EVO 1 To, 16 Go de RAM, Disque Dur Seagate Barracuda 3 To, Windows 10

Hors ligne

#2140 Le 10/01/2012, à 10:16

grim7reaper

Re : /* Topic des codeurs [6] */

Hello World!



Πυλάδης a écrit :

Sinon, c’est quoi l’avantage du Rata Die par rapport à simplement parler en temps Unix ?

Les deux unités sont très différentes, difficile de comparer…
L’une ne remplace pas l’autre car l’UT (le temps UNIX c’est de l’UTC qui est lui-même un UT) est utilisé pour certains calculs calendaires mettant en jeux les calendriers astromoniques.



The Uploader a écrit :

Tu rends les appels "morcelés". Tu donnes les paramètres quand tu veux, quoi.

Peut-être, je ne sais pas trop ce que tu veux dire par là…
Peut-être que l’article anglais est plus clair (j’avais d’abord donné l’article français car il y avait un exemple en Ruby dedans).
Et il faut faire attention à ne pas confondre l’application partielle et la curryfication.



Ha, et sinon :

Πυλάδης a écrit :
#!/usr/bin/python
#coding=utf-8

import os
from os.path import basename, join
from urllib2 import urlopen
from urllib import urlretrieve
from BeautifulSoup import BeautifulSoup as Soup

url = 'http://apod.nasa.gov/apod/'
rep = '/home/paul/Documents/Images/apod/'

page = urlopen(url)
soup = Soup(page)
page.close()
image = soup.find('img')['src']
soup.close()
imageurl = join(url, image)
target = join(rep, basename(image))

urlretrieve(imageurl, target)

os.system('hsetroot -full %s' % target)

Franchement, sortir Python pour ça tongue
En 3 lignes de shell c’est fait (Cf. ǤƦƯƝƬ');DROP TABLE users;, il reste juste à ajouter le hsetroot).

Dernière modification par grim7reaper (Le 10/01/2012, à 10:47)

Hors ligne

#2141 Le 10/01/2012, à 11:17

HP

Re : /* Topic des codeurs [6] */

git config --global alias.discard "checkout --"
git config --global alias.unstage "reset HEAD"

Voila qui me simplifiera un peu la vie smile.


cat /dev/urandom >/dev/null 2>&1 #github

Hors ligne

#2142 Le 10/01/2012, à 11:48

Pylades

Re : /* Topic des codeurs [6] */

@ grim7reaper : c’est plus propre avec BeautifulSoup. tongue
Pis on peut aussi faire ça en deux lignes en Python, une fois que l’on a fait les import, c’est juste moins lisible (et les méthodes close c’est bien de les appeler)…


“Any if-statement is a goto. As are all structured loops.
“And sometimes structure is good. When it’s good, you should use it.
“And sometimes structure is _bad_, and gets into the way, and using a goto is just much clearer.”
                Linus Torvalds – 12 janvier 2003

Hors ligne

#2143 Le 10/01/2012, à 12:53

The Uploader

Re : /* Topic des codeurs [6] */

grim' a écrit :

En 3 lignes de shell c’est fait (Cf. ǤƦƯƝƬ');DROP TABLE users;, il reste juste à ajouter le hsetroot).

Bash c'est le Malin. Your argument is invalid. tongue


- Oldies PC : Intel Pentium 3 @ 800 Mhz sur CM ASUS P2B-F, GeForce 4 Ti4800 SE, Disque Dur Hitachi 160 Go, 512 Mo de RAM, 3DFX Voodoo 2, Sound Blaster 16 ISA PnP, Windows 98 SE / XP)
- Desktop : Intel Core i7 6700K @ 4 GHz sur CM ASUS Z170-P, GeForce GTX 1070, SSD Samsung 850 EVO 1 To, 16 Go de RAM, Disque Dur Seagate Barracuda 3 To, Windows 10

Hors ligne

#2144 Le 10/01/2012, à 12:58

grim7reaper

Re : /* Topic des codeurs [6] */

J’ai dis shell pas Bash, le code n’as rien de spécifique à Bash il me semble donc tu peux le faire en zsh si tu veux tongue

Hors ligne

#2145 Le 10/01/2012, à 22:29

The Uploader

Re : /* Topic des codeurs [6] */

Hop! Voilà des Bots qui changent de rôle selon les circonstances!

commit fb47b7ab391a4f32dbc18106461c74cd7fee8a58
Author: Maximilien Noal <mnoal@epsi.fr>
Date:   Tue Jan 10 21:13:19 2012 +0100

    PheroBots change dynamically between PheroMode and AntubisMode

diff --git a/src/com/Antubis/PheroBot.as b/src/com/Antubis/PheroBot.as
index 9c5cd16..a4382e8 100644
--- a/src/com/Antubis/PheroBot.as
+++ b/src/com/Antubis/PheroBot.as
@@ -20,8 +20,8 @@ package com.Antubis
         private var lastDropedPhero:Phero;
         public static var livingPheros:Number;
         private var seenPheroBot:PheroBot;
-        private var onceReachedResource:Resource;
-        private var changed:Boolean;
+        private var antubisMode:Boolean;
+        private var pheroMode:Boolean;
         
         public function PheroBot(_type:AgentType) {
             super(_type);
@@ -29,11 +29,15 @@ package com.Antubis
         }
         
         public override function Update() : void {
-            if(onceReachedResource) {
-                ChangeIntoAntubisBotIfDead();
+            if (reachedResource && !antubisMode) {
+                antubisMode = true;
+                pheroMode = false;
+                super.InitExpertSystem();
             }
-            if (reachedResource) {
-                onceReachedResource = reachedResource;
+            if (!seenResource && !lastSeenResource && !hasResource && !pheroMode) {
+                antubisMode = false;
+                pheroMode = true;
+                InitExpertSystem();
             }
             
             super.Update();
@@ -113,12 +117,5 @@ package com.Antubis
         protected function DropPhero() : void {
             Drop(lastDropedPhero = new Phero(AntubisAgentType.PHERO, Phero.BASE_LIFETIME*seenResource.GetLife()));
         }
-        
-        protected function ChangeIntoAntubisBotIfDead() : void {
-            if(onceReachedResource.GetLife() <= 0 && !changed) { 
-                changed = true;
-                super.InitExpertSystem();
-            }
-        }
     }
 }
\ No newline at end of file

commit ad5e74569f301906d4312b81441bb936fa199529
Author: Maximilien Noal <mnoal@epsi.fr>
Date:   Tue Jan 10 16:22:39 2012 +0100

    AntubisBot : cleaner onAgentCollide code

diff --git a/src/com/Antubis/AntubisBot.as b/src/com/Antubis/AntubisBot.as
index 9ea178b..a8e371f 100644
--- a/src/com/Antubis/AntubisBot.as
+++ b/src/com/Antubis/AntubisBot.as
@@ -162,16 +162,21 @@
                 seenPhero = (collidedAgent as Phero);
             }
             
+            var enemyBot:Bot;
             if (collidedAgent as Bot) {
                 if ((collidedAgent  as Bot).GetTeamId() == teamId) {
                     seenTeamBot = collidedAgent as AntubisBot;
                     Chat(seenTeamBot);
-                } else if (IsCollided(collidedAgent)) {
-                    seenEnemyBot = (collidedAgent as Bot).GetCurrentPoint();
-                    if ((collidedAgent as Bot).HasResource() && !hasResource && !stolen) {
-                        StealResource(collidedAgent as Bot);
-                        stolen = true;
-                    }
+                } else {
+                    enemyBot = (collidedAgent as Bot);
+                }
+            }
+            
+            if (enemyBot) {
+                seenEnemyBot = enemyBot.GetCurrentPoint();
+                if (IsCollided(enemyBot) && enemyBot.HasResource() && !hasResource && !stolen) {
+                    StealResource(enemyBot);
+                    stolen = true;
                 }
             }
         }
commit d6d0b60e4fa2bb7489fcca602c191c669c4cc07a
Author: Maximilien Noal <mnoal@epsi.fr>
Date:   Tue Jan 10 21:47:44 2012 +0100

    Reintroduced 50/50 PheroBot/AntubisBot team mix to retain group effect in some situations

diff --git a/src/com/Antubis/AntubisAgentType.as b/src/com/Antubis/AntubisAgentType.as
index 30927f5..26f1479 100644
--- a/src/com/Antubis/AntubisAgentType.as
+++ b/src/com/Antubis/AntubisAgentType.as
@@ -15,7 +15,8 @@
     //*****************************************************************
      
     public class AntubisAgentType {
-        public static const PHERO_BOT:AgentType = new AgentType    (PheroBot, 1);
+        public static const ANTUBIS_BOT:AgentType= new AgentType(AntubisBot, 0.50);
+        public static const PHERO_BOT:AgentType = new AgentType    (PheroBot, 0.50);
         public static const PHERO:AgentType = new AgentType        (Phero, 0);
     }

Bon, c'est la fin. big_smile

http://youtu.be/SzhkvMzA0-Q


- Oldies PC : Intel Pentium 3 @ 800 Mhz sur CM ASUS P2B-F, GeForce 4 Ti4800 SE, Disque Dur Hitachi 160 Go, 512 Mo de RAM, 3DFX Voodoo 2, Sound Blaster 16 ISA PnP, Windows 98 SE / XP)
- Desktop : Intel Core i7 6700K @ 4 GHz sur CM ASUS Z170-P, GeForce GTX 1070, SSD Samsung 850 EVO 1 To, 16 Go de RAM, Disque Dur Seagate Barracuda 3 To, Windows 10

Hors ligne

#2146 Le 10/01/2012, à 23:09

tshirtman

Re : /* Topic des codeurs [6] */

The Uploader a écrit :

c'est un progrès, mais ils pourraient commencer par ajouter des namespaces...

Hors ligne

#2147 Le 10/01/2012, à 23:13

The Uploader

Re : /* Topic des codeurs [6] */

pour ça j'utilise le mot clé module. : http://ruby-doc.org/docs/ProgrammingRub … dules.html

la page a écrit :

The answer is the module mechanism. Modules define a namespace, a sandbox in which your methods and constants can play without having to worry about being stepped on by other methods and constants

D'ailleurs, c'est ce que font nombre de gems. Ce que fait RoR aussi. En fait, tout le monde.

Ensuite, ça fait genre "Rubygame::truc::bidule"

Dernière modification par The Uploader (Le 10/01/2012, à 23:27)


- Oldies PC : Intel Pentium 3 @ 800 Mhz sur CM ASUS P2B-F, GeForce 4 Ti4800 SE, Disque Dur Hitachi 160 Go, 512 Mo de RAM, 3DFX Voodoo 2, Sound Blaster 16 ISA PnP, Windows 98 SE / XP)
- Desktop : Intel Core i7 6700K @ 4 GHz sur CM ASUS Z170-P, GeForce GTX 1070, SSD Samsung 850 EVO 1 To, 16 Go de RAM, Disque Dur Seagate Barracuda 3 To, Windows 10

Hors ligne

#2148 Le 11/01/2012, à 01:20

tshirtman

Re : /* Topic des codeurs [6] */

Ah ben voilà smile j'avais lu que ça existait pas smile, j'avais seulement vu l'utilisation pour le mixin, qui semble être un paliatif à l'absence d'héritage multiple.

Dernière modification par tshirtman (Le 11/01/2012, à 01:22)

Hors ligne

#2149 Le 11/01/2012, à 14:43

The Uploader

Re : /* Topic des codeurs [6] */

commit 490fc5e61d47b25b6a815c843e87e1a6d93a2a58
Author: Maximilien Noal <mnoal@epsi.fr>
Date:   Wed Jan 11 14:23:41 2012 +0100

    RenforcePhero, no more Bots blocked on a Phero, enhanced Chat

diff --git a/src/com/Antubis/AntubisBot.as b/src/com/Antubis/AntubisBot.as
index 2749fb8..c5a4bb0 100644
--- a/src/com/Antubis/AntubisBot.as
+++ b/src/com/Antubis/AntubisBot.as
@@ -35,14 +35,18 @@
     public class AntubisBot extends Bot {
         
         protected static const EDGE_LIMIT:Number = 6;
+        protected var stolen:Boolean             = false;
         protected var seenPhero:Phero;
         protected var seenEnemyBot:Point;
         protected var seenTeamBot:AntubisBot;
         protected var lastSeenResource:Point;
-        protected var stolen:Boolean             = false;
+        protected var takenResourceLife:Number;
+        protected var passedPheros:Array;
+        protected var resetTimer:Number;
         
         public override function AntubisBot(_type:AgentType) {
             super(_type);
+            passedPheros = new Array();
         }
         
         public override function Update() : void {
@@ -54,6 +58,11 @@
             seenEnemyBot = null;
             seenTeamBot = null;
             stolen = false;
+            resetTimer += TimeManager.timeManager.GetFrameDeltaTime();
+            if (resetTimer == TimeManager.timeManager.GetFrameDeltaTime() * 10) {
+                passedPheros = new Array();
+                resetTimer = 0;
+            }
         }
         
         protected override function InitExpertSystem() : void {
@@ -71,7 +80,13 @@
                                                                                     AgentFacts.BIGGER_RESOURCE)));
                                                                                     
             expertSystem.AddRule(new Rule(CustomBotFacts.GO_TO_PHERO,    new Array(     CustomBotFacts.SEEN_PHERO,
-                                                                                    AgentFacts.NO_RESOURCE)));
+                                                                                    CustomBotFacts.PHERO_NOT_ALREADY_PASSED,
+                                                                                    AgentFacts.NO_RESOURCE,
+                                                                                    CustomBotFacts.SEE_NO_RESOURCE,
+                                                                                    CustomBotFacts.NO_RESOURCE_SEEN)));
+                                                                                    
+            expertSystem.AddRule(new Rule(CustomBotFacts.RENFORCE_PHERO,new Array(    CustomBotFacts.SEEN_PHERO,
+                                                                                    AgentFacts.GOT_RESOURCE)));
                                                                                     
             expertSystem.AddRule(new Rule(CustomBotFacts.GO_TO_ENEMY_BOT, new Array(CustomBotFacts.SEEN_ENEMY_BOT,
                                                                                     CustomBotFacts.NO_TEAM_BOT_SEEN,    
@@ -94,6 +109,9 @@
         protected override function UpdateFacts() : void {
             if (seenPhero) {
                 expertSystem.SetFactValue(CustomBotFacts.SEEN_PHERO, true);
+                if (passedPheros.indexOf(seenPhero) == -1) {
+                    expertSystem.SetFactValue(CustomBotFacts.PHERO_NOT_ALREADY_PASSED, true);
+                }
             }
             
             if (seenEnemyBot) {
@@ -189,6 +207,9 @@
             if (_seenBot.GetHomePosition()) {
                 homePosition = _seenBot.GetHomePosition();
             }
+            if (!seenPhero) {
+                seenPhero = _seenBot.seenPhero;
+            }
         }
         
         protected override function Act() : void {
@@ -202,6 +223,10 @@
                     case CustomBotFacts.GO_TO_ENEMY_BOT:
                     GoToEnemyBot();
                     break;
+                    
+                    case CustomBotFacts.RENFORCE_PHERO:
+                    RenforcePhero();
+                    break;
                 }
             }
             super.Act();
@@ -238,13 +263,23 @@
             lastReachedResource = null;
         }
         
-        public function GoToPhero() : void {
+        protected function GoToPhero() : void {
             if (seenPhero) {
+                passedPheros.push(seenPhero);
                 GoToPoint(seenPhero.GetCurrentPoint());
                 seenPhero = null;
             }
         }
         
+        protected function RenforcePhero() : void {
+            seenPhero.lifetime += takenResourceLife * TimeManager.timeManager.GetFrameDeltaTime();
+        }
+        
+        public override function TakeResource() : void {
+            super.TakeResource();
+            takenResourceLife = takenResource.GetLife();
+        }
+        
         protected function IsAtHome() : Boolean {
             if (home) {
                 return (IsCollided(home));
diff --git a/src/com/Antubis/CustomBotFacts.as b/src/com/Antubis/CustomBotFacts.as
index b019458..2f2d38a 100644
--- a/src/com/Antubis/CustomBotFacts.as
+++ b/src/com/Antubis/CustomBotFacts.as
@@ -9,7 +9,6 @@
      * @author Maximilien Noal & Antubis Team
      * @version 1.0
      */
-
      //*****************************************************************
     // TODO : Register here all new facts used by your custom bots.
     //*****************************************************************
@@ -23,10 +22,11 @@
         public static const SEEN_ENEMY_BOT:Fact                    = new Fact("Seen an enemy Bot.");
         public static const NO_TEAM_BOT_SEEN:Fact                = new Fact("Seen no team Bot.");
         public static const SEEN_PHERO:Fact                        = new Fact("Seen a Phero.");
+        public static const PHERO_NOT_ALREADY_PASSED:Fact        = new Fact("Not already passed on this Phero.");
         public static const LAST_DROPED_PHERO_IS_TOO_FAR:Fact    = new Fact("Last droped Phero is at midway of the perceptionRadius.");
-        public static const NO_PHERO_BOT_ON_THIS_RESOURCE:Fact    = new Fact("Didn't see another PheroBot on this Resource.");
         public static const DROP_PHERO:Fact                        = new Fact("Drop Phero action.");
         public static const GO_TO_PHERO:Fact                    = new Fact("Go to Phero action.");
         public static const GO_TO_ENEMY_BOT:Fact                = new Fact("Go to enemy bot action.");
+        public static const RENFORCE_PHERO:Fact                    = new Fact("Renforce Phero action.");
     }
 }
\ No newline at end of file
diff --git a/src/com/Antubis/Phero.as b/src/com/Antubis/Phero.as
index 4c62d06..9ee6189 100644
--- a/src/com/Antubis/Phero.as
+++ b/src/com/Antubis/Phero.as
@@ -3,6 +3,7 @@ package com.Antubis
     import com.novabox.MASwithTwoNests.Agent;
     import com.Antubis.PheroBot;
     import com.novabox.MASwithTwoNests.AgentType;
+    import com.novabox.MASwithTwoNests.Bot;
     import com.novabox.MASwithTwoNests.Resource;
     import com.novabox.MASwithTwoNests.TimeManager;
     import com.novabox.MASwithTwoNests.AgentCollideEvent;
@@ -17,17 +18,14 @@ package com.Antubis
     public class Phero extends Agent 
     {
         protected var color:int;
-        protected var lifetime:Number;
+        public var lifetime:Number;
         protected var start_lifetime:Number;
-        protected var passes:Number                        = 0;
-        protected static const MAX_LIVING_PHEROS:Number    = 200;
+        protected static const MAX_LIVING_PHEROS:Number    = 300;
         public static const BASE_LIFETIME:Number        = 9000;
-        public const        MAX_PASSES:Number             = 50;
         
         public function Phero(_type:AgentType, _lifetime:Number) {
             super(_type);
             PheroBot.livingPheros++;
-            addEventListener(AgentCollideEvent.AGENT_COLLIDE, onAgentCollide);
             color = 0X6F2020;
             lifetime = _lifetime;
             start_lifetime = _lifetime;
@@ -35,18 +33,9 @@ package com.Antubis
             graphics.endFill();
         }
         
-        public function onAgentCollide(_event:AgentCollideEvent) : void {
-            var collidedAntubisBot:AntubisBot = _event.GetAgent() as AntubisBot;
-            if(collidedAntubisBot) {
-                if (!(collidedAntubisBot as PheroBot)) {
-                    passes++;
-                }
-            }
-        }
-        
         public override function Update() : void {
             lifetime -= TimeManager.timeManager.GetFrameDeltaTime();
-            if (lifetime <= 0 || passes >= MAX_PASSES || PheroBot.livingPheros > MAX_LIVING_PHEROS) {
+            if (lifetime <= 0 || PheroBot.livingPheros > MAX_LIVING_PHEROS) {
                 PheroBot.livingPheros--;
                 dead = true;
             }
diff --git a/src/com/Antubis/PheroBot.as b/src/com/Antubis/PheroBot.as
index a4382e8..3b7593c 100644
--- a/src/com/Antubis/PheroBot.as
+++ b/src/com/Antubis/PheroBot.as
@@ -17,10 +17,9 @@ package com.Antubis
      * @author Maximiliien Noal & Antubis-Team
      */
     public class PheroBot extends AntubisBot {
-        private var lastDropedPhero:Phero;
+        protected var lastDropedPhero:Phero;
         public static var livingPheros:Number;
-        private var seenPheroBot:PheroBot;
-        private var antubisMode:Boolean;
+        public    var antubisMode:Boolean;
         private var pheroMode:Boolean;
         
         public function PheroBot(_type:AgentType) {
@@ -41,21 +40,13 @@ package com.Antubis
             }
             
             super.Update();
-            seenPheroBot = null;
         }
         
         protected override function InitExpertSystem() : void {
             expertSystem = new ExpertSystem();
             
-            expertSystem.AddRule(new Rule(AgentFacts.GO_TO_RESOURCE,    new Array(     AgentFacts.SEE_RESOURCE,
-                                                                                    CustomBotFacts.NO_PHERO_BOT_ON_THIS_RESOURCE)));
+            expertSystem.AddRule(new Rule(AgentFacts.GO_TO_RESOURCE,    new Array(     AgentFacts.SEE_RESOURCE)));
                                                                                     
-            expertSystem.AddRule(new Rule(CustomBotFacts.GO_TO_ENEMY_BOT,new Array(    CustomBotFacts.SEEN_ENEMY_BOT,
-                                                                                    CustomBotFacts.NO_RESOURCE_SEEN,
-                                                                                    CustomBotFacts.SEE_NO_RESOURCE,
-                                                                                    CustomBotFacts.NO_TEAM_BOT_SEEN,
-                                                                                    AgentFacts.NO_RESOURCE)));
-            
             expertSystem.AddRule(new Rule(CustomBotFacts.DROP_PHERO,     new Array(    CustomBotFacts.LAST_DROPED_PHERO_IS_TOO_FAR,
                                                                                     AgentFacts.SEE_RESOURCE)));
                                                                                     
@@ -65,46 +56,26 @@ package com.Antubis
             expertSystem.AddRule(new Rule(AgentFacts.TAKE_RESOURCE,     new Array(    AgentFacts.NO_RESOURCE,
                                                                                     AgentFacts.AT_HOME,
                                                                                     AgentFacts.REACHED_RESOURCE)));
-                                                                                
+                                                                                    
             expertSystem.AddRule(new Rule(AgentFacts.CHANGE_DIRECTION,     new Array(    CustomBotFacts.NEAR_EDGES)));
         }
         
         protected override function UpdateFacts() : void {
             var lastSeenPhero:Phero = lastDropedPhero != null ? lastDropedPhero : seenPhero;
             if (lastSeenPhero) {
-                if(Point.distance(new Point(lastSeenPhero.x, lastSeenPhero.y), new Point(x, y)) >= perceptionRadius/2) {
+                if(Point.distance(new Point(lastSeenPhero.x, lastSeenPhero.y), new Point(x, y)) >= perceptionRadius/1.5) {
                     expertSystem.SetFactValue(CustomBotFacts.LAST_DROPED_PHERO_IS_TOO_FAR, true);
                 }
             } else {
                 expertSystem.SetFactValue(CustomBotFacts.LAST_DROPED_PHERO_IS_TOO_FAR, true);
             }
             
-            if (seenResource) {
-                expertSystem.SetFactValue(AgentFacts.SEE_RESOURCE, true);
-                if (seenPheroBot) {
-                    if(seenPheroBot.seenResource != seenResource && !seenPheroBot.IsCollided(seenResource)) {
-                        expertSystem.SetFactValue(CustomBotFacts.NO_PHERO_BOT_ON_THIS_RESOURCE, true);
-                    }
-                }
-            }
-            
             super.UpdateFacts();
         }
         
-        public override function onAgentCollide(_event:AgentCollideEvent) : void  {
-            var collidedAgent:Agent = _event.GetAgent();
-            super.onAgentCollide(_event);
-            
-            if (collidedAgent as PheroBot) {
-                seenPheroBot = collidedAgent as PheroBot;
-            }
-        }
-        
         protected override function Act() : void {
-            var inferedFacts:Array = expertSystem.GetInferedFacts();
-            
-            for (var i:int = 0; i < inferedFacts.length; i++) {
-                var fact:Fact = (inferedFacts[i] as Fact);
+            for (var i:int = 0; i < expertSystem.GetInferedFacts().length; i++) {
+                var fact:Fact = expertSystem.GetInferedFacts()[i] as Fact;
                 switch (fact) {
                     case CustomBotFacts.DROP_PHERO:
                     DropPhero();

- Oldies PC : Intel Pentium 3 @ 800 Mhz sur CM ASUS P2B-F, GeForce 4 Ti4800 SE, Disque Dur Hitachi 160 Go, 512 Mo de RAM, 3DFX Voodoo 2, Sound Blaster 16 ISA PnP, Windows 98 SE / XP)
- Desktop : Intel Core i7 6700K @ 4 GHz sur CM ASUS Z170-P, GeForce GTX 1070, SSD Samsung 850 EVO 1 To, 16 Go de RAM, Disque Dur Seagate Barracuda 3 To, Windows 10

Hors ligne

#2150 Le 12/01/2012, à 21:49

The Uploader

Re : /* Topic des codeurs [6] */

Ben alors, z'êtes morts ? yikes

Dernières touches :

commit a582c3805c770f61b7482e01e42387d73ea3ed33
Author: Maximilien Noal <mnoal@epsi.fr>
Date:   Thu Jan 12 10:35:09 2012 +0100

    fixed return on phero too soon bug

diff --git a/src/com/Antubis/AntubisBot.as b/src/com/Antubis/AntubisBot.as
index c8a5e67..b098eed 100644
--- a/src/com/Antubis/AntubisBot.as
+++ b/src/com/Antubis/AntubisBot.as
@@ -60,7 +60,7 @@
             seenEnemyBot = null;
             seenTeamBot = null;
             stolen = false;
-            if (resetTimer >= TimeManager.timeManager.GetFrameDeltaTime() * 5) {
+            if (resetTimer >= Phero.BASE_LIFETIME*World.RESOURCE_START_LIFE) {
                 passedPheros = new Array();
                 resetTimer = 0;
             }
@@ -221,9 +221,6 @@
             if (_seenBot.GetHomePosition()) {
                 homePosition = _seenBot.GetHomePosition();
             }
-            if (!seenPhero) {
-                seenPhero = _seenBot.seenPhero;
-            }
         }
         
         protected override function Act() : void {

commit ffeb094aefb095e6d15027c3a8f58fcb3f7ce33a
Author: Maximilien Noal <mnoal@epsi.fr>
Date:   Thu Jan 12 09:59:36 2012 +0100

    fine tune PheroBot

diff --git a/src/com/Antubis/AntubisBot.as b/src/com/Antubis/AntubisBot.as
index dde8ff9..c8a5e67 100644
--- a/src/com/Antubis/AntubisBot.as
+++ b/src/com/Antubis/AntubisBot.as
@@ -90,7 +90,7 @@
                                                                                     AgentFacts.GOT_RESOURCE)));
                                                                                     
             expertSystem.AddRule(new Rule(CustomBotFacts.GO_TO_ENEMY_BOT, new Array(CustomBotFacts.SEEN_ENEMY_BOT,
-                                                                                    CustomBotFacts.NO_TEAM_BOT_SEEN,    
+                                                                                    CustomBotFacts.NO_TEAM_BOT_SEEN,
                                                                                     AgentFacts.NO_RESOURCE,
                                                                                     CustomBotFacts.NO_RESOURCE_SEEN,
                                                                                     CustomBotFacts.SEE_NO_RESOURCE)));
@@ -104,7 +104,11 @@
             expertSystem.AddRule(new Rule(AgentFacts.PUT_DOWN_RESOURCE,    new Array(    AgentFacts.AT_HOME,
                                                                                     AgentFacts.GOT_RESOURCE)));
             
-            expertSystem.AddRule(new Rule(AgentFacts.CHANGE_DIRECTION,     new Array(    CustomBotFacts.NEAR_EDGES)));
+            expertSystem.AddRule(new Rule(AgentFacts.CHANGE_DIRECTION,     new Array(    CustomBotFacts.NEAR_EDGES,
+                                                                                    CustomBotFacts.NOT_GOING_HOME)));
+                                                                                    
+            expertSystem.AddRule(new Rule(AgentFacts.CHANGE_DIRECTION,     new Array(    CustomBotFacts.NEAR_EDGES,
+                                                                                    CustomBotFacts.NOT_GOING_TO_RESOURCE)));
         }
         
         protected override function UpdateFacts() : void {
@@ -115,6 +119,10 @@
                 }
             }
             
+            if (home && !home.hitTestPoint(direction.x, direction.y) || !home) {
+                expertSystem.SetFactValue(CustomBotFacts.NOT_GOING_HOME, true);
+            }
+            
             if (seenEnemyBot) {
                 expertSystem.SetFactValue(CustomBotFacts.SEEN_ENEMY_BOT, true);
             }
@@ -139,6 +147,11 @@
             } else {
                 expertSystem.SetFactValue(CustomBotFacts.NO_RESOURCE_SEEN, true);
             }
+            
+            
+            if (!seenResource || seenResource && !seenResource.hitTestPoint(direction.x, direction.y)) {
+                expertSystem.SetFactValue(CustomBotFacts.NOT_GOING_TO_RESOURCE, true);
+            }
                 
             if (seenResource) {
                 expertSystem.SetFactValue(AgentFacts.SEE_RESOURCE, true);
diff --git a/src/com/Antubis/CustomBotFacts.as b/src/com/Antubis/CustomBotFacts.as
index 2fa7aef..0de683b 100644
--- a/src/com/Antubis/CustomBotFacts.as
+++ b/src/com/Antubis/CustomBotFacts.as
@@ -22,6 +22,8 @@
         public static const SEEN_PHERO:Fact                        = new Fact("Seen a Phero.");
         public static const PHERO_NOT_ALREADY_PASSED:Fact        = new Fact("Not already passed on this Phero.");
         public static const LAST_DROPED_PHERO_IS_TOO_FAR:Fact    = new Fact("Last droped Phero is at midway of the perceptionRadius.");
+        public static const NOT_GOING_HOME:Fact                    = new Fact("My direction is not Home");
+        public static const NOT_GOING_TO_RESOURCE:Fact            = new Fact("My direction is not to a *perceivable* Resource");
         public static const DROP_PHERO:Fact                        = new Fact("Drop Phero action.");
         public static const GO_TO_PHERO:Fact                    = new Fact("Go to Phero action.");
         public static const GO_TO_ENEMY_BOT:Fact                = new Fact("Go to enemy bot action.");
diff --git a/src/com/Antubis/PheroBot.as b/src/com/Antubis/PheroBot.as
index b85e72a..860a9f0 100644
--- a/src/com/Antubis/PheroBot.as
+++ b/src/com/Antubis/PheroBot.as
@@ -33,7 +33,7 @@ package com.Antubis
                 pheroMode = false;
                 super.InitExpertSystem();
             }
-            if (IsAtHome() && !hasResource && !pheroMode) {
+            if (!seenResource && !lastSeenResource && !hasResource && !pheroMode) {
                 antubisMode = false;
                 pheroMode = true;
                 InitExpertSystem();
@@ -57,7 +57,11 @@ package com.Antubis
                                                                                     AgentFacts.AT_HOME,
                                                                                     AgentFacts.REACHED_RESOURCE)));
                                                                                     
-            expertSystem.AddRule(new Rule(AgentFacts.CHANGE_DIRECTION,     new Array(    CustomBotFacts.NEAR_EDGES)));
+            expertSystem.AddRule(new Rule(AgentFacts.CHANGE_DIRECTION,     new Array(    CustomBotFacts.NEAR_EDGES,
+                                                                                    CustomBotFacts.NOT_GOING_HOME)));
+                                                                                    
+            expertSystem.AddRule(new Rule(AgentFacts.CHANGE_DIRECTION,     new Array(    CustomBotFacts.NEAR_EDGES,
+                                                                                    CustomBotFacts.NOT_GOING_TO_RESOURCE)));
         }
         
         protected override function UpdateFacts() : void {

commit 7d1c21045172345121f659e2174a8738a1468888
Author: Maximilien Noal <mnoal@epsi.fr>
Date:   Wed Jan 11 23:59:16 2012 +0100

    reverted chat about lastSeenResource cap (not working)

diff --git a/src/com/Antubis/AntubisBot.as b/src/com/Antubis/AntubisBot.as
index bbc21d7..dde8ff9 100644
--- a/src/com/Antubis/AntubisBot.as
+++ b/src/com/Antubis/AntubisBot.as
@@ -41,7 +41,6 @@
         protected var seenEnemyBot:Point;
         protected var seenTeamBot:AntubisBot;
         protected var lastSeenResource:Point;
-        protected var lastSeenResourceLife:Number;
         protected var takenResourceLife:Number;
         protected var passedPheros:Array;
         protected var resetTimer:Number;
@@ -49,7 +48,6 @@
         public override function AntubisBot(_type:AgentType) {
             super(_type);
             resetTimer = 0;
-            lastSeenResourceLife = 0;
             passedPheros = new Array();
         }
         
@@ -59,7 +57,6 @@
             seenPhero = null;
             seenResource = null;
             lastSeenResource = null;
-            lastSeenResourceLife = 0;
             seenEnemyBot = null;
             seenTeamBot = null;
             stolen = false;
@@ -178,7 +175,6 @@
             
             if (collidedAgent as Resource) {
                 lastSeenResource = (collidedAgent as Resource).GetCurrentPoint();
-                lastSeenResourceLife = (collidedAgent as Resource).GetLife();
             }
             
             if (collidedAgent as Phero && !(collidedAgent as Phero).IsDead()) {
@@ -239,11 +235,7 @@
         
         protected function GetLastSeenResource() : Point {
             CorrectLastSeenResource();
-            if (lastSeenResourceLife / World.RESOURCE_UPDATE_VALUE >= 2) {
-                return lastSeenResource;
-            } else {
-                return null;
-            }
+            return lastSeenResource;
         }
         
         protected function CorrectLastSeenResource() : void {

commit 80d2136e8ce25858c37f6963aafc612028b10acc
Author: Maximilien Noal <mnoal@epsi.fr>
Date:   Wed Jan 11 23:28:34 2012 +0100

    fine tune some final stuff

diff --git a/src/com/Antubis/AntubisBot.as b/src/com/Antubis/AntubisBot.as
index 2216ebf..bbc21d7 100644
--- a/src/com/Antubis/AntubisBot.as
+++ b/src/com/Antubis/AntubisBot.as
@@ -13,6 +13,7 @@
     import com.novabox.MASwithTwoNests.Resource;
     import com.novabox.expertSystem.Fact;
     import com.novabox.expertSystem.Rule;
+    import com.novabox.MASwithTwoNests.World;
     import flash.display.Sprite;
     import flash.events.Event;
     import flash.geom.Point;
@@ -34,18 +35,21 @@
 
     public class AntubisBot extends Bot {
         
-        protected static const EDGE_LIMIT:Number = 6;
+        protected static const EDGE_LIMIT:Number= 6;
         protected var stolen:Boolean             = false;
         protected var seenPhero:Phero;
         protected var seenEnemyBot:Point;
         protected var seenTeamBot:AntubisBot;
         protected var lastSeenResource:Point;
+        protected var lastSeenResourceLife:Number;
         protected var takenResourceLife:Number;
         protected var passedPheros:Array;
         protected var resetTimer:Number;
         
         public override function AntubisBot(_type:AgentType) {
             super(_type);
+            resetTimer = 0;
+            lastSeenResourceLife = 0;
             passedPheros = new Array();
         }
         
@@ -55,11 +59,11 @@
             seenPhero = null;
             seenResource = null;
             lastSeenResource = null;
+            lastSeenResourceLife = 0;
             seenEnemyBot = null;
             seenTeamBot = null;
             stolen = false;
-            resetTimer += TimeManager.timeManager.GetFrameDeltaTime();
-            if (resetTimer == TimeManager.timeManager.GetFrameDeltaTime() * 20) {
+            if (resetTimer >= TimeManager.timeManager.GetFrameDeltaTime() * 5) {
                 passedPheros = new Array();
                 resetTimer = 0;
             }
@@ -144,8 +148,8 @@
                 if (IsCloser(seenResource)) {
                     expertSystem.SetFactValue(CustomBotFacts.CLOSER_RESOURCE, true);
                 } 
-                if (takenResource && seenResource.GetLife() > takenResource.GetLife()) {
-                    expertSystem.SetFactValue(AgentFacts.BIGGER_RESOURCE, true);                            
+                if (takenResource && seenResource.GetLife() > takenResourceLife) {
+                    expertSystem.SetFactValue(AgentFacts.BIGGER_RESOURCE, true);
                 }
             } else {
                 expertSystem.SetFactValue(CustomBotFacts.SEE_NO_RESOURCE, true);
@@ -174,6 +178,7 @@
             
             if (collidedAgent as Resource) {
                 lastSeenResource = (collidedAgent as Resource).GetCurrentPoint();
+                lastSeenResourceLife = (collidedAgent as Resource).GetLife();
             }
             
             if (collidedAgent as Phero && !(collidedAgent as Phero).IsDead()) {
@@ -234,7 +239,11 @@
         
         protected function GetLastSeenResource() : Point {
             CorrectLastSeenResource();
-            return lastSeenResource;
+            if (lastSeenResourceLife / World.RESOURCE_UPDATE_VALUE >= 2) {
+                return lastSeenResource;
+            } else {
+                return null;
+            }
         }
         
         protected function CorrectLastSeenResource() : void {
@@ -272,7 +281,7 @@
         }
         
         protected function RenforcePhero() : void {
-            seenPhero.lifetime += takenResourceLife * TimeManager.timeManager.GetFrameDeltaTime();
+            seenPhero.lifetime = takenResourceLife*Phero.BASE_LIFETIME;
         }
         
         public override function TakeResource() : void {
diff --git a/src/com/Antubis/CustomBotFacts.as b/src/com/Antubis/CustomBotFacts.as
index 2f2d38a..2fa7aef 100644
--- a/src/com/Antubis/CustomBotFacts.as
+++ b/src/com/Antubis/CustomBotFacts.as
@@ -1,6 +1,7 @@
 package com.Antubis 
 {
     import com.novabox.expertSystem.Fact;
+    
     /**
      * Cognitive Multi-Agent System Example
      * Part 2 : Two distinct termite nests
@@ -9,9 +10,6 @@
      * @author Maximilien Noal & Antubis Team
      * @version 1.0
      */
-     //*****************************************************************
-    // TODO : Register here all new facts used by your custom bots.
-    //*****************************************************************
     
     public class CustomBotFacts {
         public static const SEE_NO_RESOURCE:Fact                = new Fact("No Resource is perceived.");
diff --git a/src/com/Antubis/Phero.as b/src/com/Antubis/Phero.as
index 9ee6189..ca8ad77 100644
--- a/src/com/Antubis/Phero.as
+++ b/src/com/Antubis/Phero.as
@@ -21,7 +21,7 @@ package com.Antubis
         public var lifetime:Number;
         protected var start_lifetime:Number;
         protected static const MAX_LIVING_PHEROS:Number    = 300;
-        public static const BASE_LIFETIME:Number        = 9000;
+        public static const BASE_LIFETIME:Number        = 10000;
         
         public function Phero(_type:AgentType, _lifetime:Number) {
             super(_type);
diff --git a/src/com/Antubis/PheroBot.as b/src/com/Antubis/PheroBot.as
index 3b7593c..b85e72a 100644
--- a/src/com/Antubis/PheroBot.as
+++ b/src/com/Antubis/PheroBot.as
@@ -33,7 +33,7 @@ package com.Antubis
                 pheroMode = false;
                 super.InitExpertSystem();
             }
-            if (!seenResource && !lastSeenResource && !hasResource && !pheroMode) {
+            if (IsAtHome() && !hasResource && !pheroMode) {
                 antubisMode = false;
                 pheroMode = true;
                 InitExpertSystem();

commit 1c1c64df205a9d1c0a2b90012f9cec75c05af971
Author: Maximilien Noal <mnoal@epsi.fr>
Date:   Wed Jan 11 16:31:50 2012 +0100

    increased passedPheros' resetTimer

diff --git a/src/com/Antubis/AntubisBot.as b/src/com/Antubis/AntubisBot.as
index c5a4bb0..2216ebf 100644
--- a/src/com/Antubis/AntubisBot.as
+++ b/src/com/Antubis/AntubisBot.as
@@ -59,7 +59,7 @@
             seenTeamBot = null;
             stolen = false;
             resetTimer += TimeManager.timeManager.GetFrameDeltaTime();
-            if (resetTimer == TimeManager.timeManager.GetFrameDeltaTime() * 10) {
+            if (resetTimer == TimeManager.timeManager.GetFrameDeltaTime() * 20) {
                 passedPheros = new Array();
                 resetTimer = 0;
             }

(on voit que je ne fais plus vraiment attention à mes messages de commit, t'façon c'est fini, et j'ai donné le code final dans un .zip.. >_< )
Demain, on fait des matchs entre les équipes de "termites" (bots) qui ramassent du "bois" (qui bougent..) lors du dernier cours d'IA de cette (dernière) année.

Après, je vire cette fichue VM Windows, avec son fichu FlashDevelop, et son $$$*ù"é5"#~{{]]] de "langage" de merde qui met les Number à NaN par défaut et qui ne fait aucune erreur lorsque qu'on fait un += dessus (le Number reste à "NaN".... merci pour les bugs!).

Dernière modification par The Uploader (Le 12/01/2012, à 21:54)


- Oldies PC : Intel Pentium 3 @ 800 Mhz sur CM ASUS P2B-F, GeForce 4 Ti4800 SE, Disque Dur Hitachi 160 Go, 512 Mo de RAM, 3DFX Voodoo 2, Sound Blaster 16 ISA PnP, Windows 98 SE / XP)
- Desktop : Intel Core i7 6700K @ 4 GHz sur CM ASUS Z170-P, GeForce GTX 1070, SSD Samsung 850 EVO 1 To, 16 Go de RAM, Disque Dur Seagate Barracuda 3 To, Windows 10

Hors ligne