@@ -2,14 +2,14 @@ function SmartPlantEater() {
22 this . energy = 30 ;
33 this . direction = "e" ;
44}
5- SmartPlantEater . prototype . act = function ( context ) {
6- var space = context . find ( " " ) ;
5+ SmartPlantEater . prototype . act = function ( view ) {
6+ var space = view . find ( " " ) ;
77 if ( this . energy > 90 && space )
88 return { type : "reproduce" , direction : space } ;
9- var plants = context . findAll ( "*" ) ;
9+ var plants = view . findAll ( "*" ) ;
1010 if ( plants . length > 1 )
1111 return { type : "eat" , direction : randomElement ( plants ) } ;
12- if ( context . look ( this . direction ) != " " && space )
12+ if ( view . look ( this . direction ) != " " && space )
1313 this . direction = space ;
1414 return { type : "move" , direction : this . direction } ;
1515} ;
@@ -20,12 +20,12 @@ function Tiger() {
2020 // Used to track the amount of prey seen per turn in the last six turns
2121 this . preySeen = [ ] ;
2222}
23- Tiger . prototype . act = function ( context ) {
23+ Tiger . prototype . act = function ( view ) {
2424 // Average number of prey seen per turn
2525 var seenPerTurn = this . preySeen . reduce ( function ( a , b ) {
2626 return a + b ;
2727 } , 0 ) / this . preySeen . length ;
28- var prey = context . findAll ( "O" ) ;
28+ var prey = view . findAll ( "O" ) ;
2929 this . preySeen . push ( prey . length ) ;
3030 // Drop the first element from the array when it is longer than 6
3131 if ( this . preySeen . length > 6 )
@@ -35,10 +35,10 @@ Tiger.prototype.act = function(context) {
3535 if ( prey . length && seenPerTurn > 0.25 )
3636 return { type : "eat" , direction : randomElement ( prey ) } ;
3737
38- var space = context . find ( " " ) ;
38+ var space = view . find ( " " ) ;
3939 if ( this . energy > 400 && space )
4040 return { type : "reproduce" , direction : space } ;
41- if ( context . look ( this . direction ) != " " && space )
41+ if ( view . look ( this . direction ) != " " && space )
4242 this . direction = space ;
4343 return { type : "move" , direction : this . direction } ;
4444} ;
0 commit comments