1 /** 2 * Copyright: © 2012-2014 Anton Gushcha 3 * License: Subject to the terms of the MIT license, as written in the included LICENSE file. 4 * Authors: NCrashed <ncrashed@gmail.com>, 5 * LeMarwin <lemarwin42@gmail.com>, 6 * Nazgull09 <nazgull90@gmail.com> 7 */ 8 module ant.sense; 9 10 import devol.operator; 11 import devol.operatormng; 12 import devol.argument; 13 14 import devol.individ; 15 import devol.line; 16 import devol.world; 17 18 import devol.typemng; 19 20 import devol.type; 21 import devol.std.typepod; 22 import devol.std.argpod; 23 24 import ant.progtype; 25 import ant.world; 26 27 class OpSense : Operator 28 { 29 TypePod!bool booltype; 30 this() 31 { 32 booltype = cast(TypePod!bool)(TypeMng.getSingleton().getType("Typebool")); 33 assert(booltype, "We need void type!"); 34 35 mRetType = booltype; 36 super("<O>", "Sense", ArgsStyle.NULAR_STYLE); 37 } 38 39 override Argument apply(IndAbstract individ, Line line, WorldAbstract world) 40 { 41 auto ind = cast(Ant)(individ); 42 auto Wrld = cast(AntWorld)(world); 43 ind.IsFood = false; 44 final switch(ind.Direction) 45 { 46 case ind.Faces.NORTH: 47 if(ind.y<=Wrld.size-1) 48 ind.IsFood = Wrld.checkForFood(ind.x,ind.y+1); 49 break; 50 case ind.Faces.SOUTH: 51 if(ind.y>=2) 52 ind.IsFood = Wrld.checkForFood(ind.x,ind.y-1); 53 break; 54 case ind.Faces.EAST: 55 if(ind.x<=Wrld.size-1) 56 ind.IsFood = Wrld.checkForFood(ind.x-1,ind.y); 57 break; 58 case ind.Faces.WEST: 59 if(ind.x>=2) 60 ind.IsFood = Wrld.checkForFood(ind.x+1,ind.y); 61 break; 62 } 63 ArgPod!bool ret = booltype.getNewArg(); 64 ret = ind.IsFood; 65 return ret; 66 } 67 }