Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'java'
- require 'lib/gridworld.jar'
- java_import "info.gridworld.actor.Critter"
- java_import "info.gridworld.actor.Flower"
- java_import "info.gridworld.grid.Location"
- java_import "java.util.ArrayList"
- class Grub < Critter
- def initialize(distance)
- @max_distance = distance
- end
- def getRandomDirection
- rand(8) * 45
- end
- def getMoveLocations
- locs = ArrayList.new
- loc = getLocation
- dir = getRandomDirection
- 0.upto (@max_distance - 1) do |i|
- loc = loc.getAdjacentLocation(dir)
- locs.add(loc) if getGrid.isValid(loc)
- end
- locs
- end
- def selectMoveLocation(locs)
- unless locs.size == 0
- loc = locs.get(rand(locs.size))
- at_loc = getGrid.get(loc)
- return loc if at_loc.nil? or at_lot.is_a? Flower
- nil
- end
- getLocation
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement