Next, we decided to build the Fish. The Fish were tricky, in terms of figuring out how to move. We decided to just use a uniform distribution from the Random class so that the Fish would just as likely go up as down as left as right.
" Defining the class " LivingOrganism subclass: #Fish instanceVariableNames: 'food ' classVariableNames: '' poolDictionaries: '' category: 'FishWorld' Fish methodsFor: 'initialization' initialize: anOcean at: anX at: anY "Initialize food besides everything else" food := OrderedCollection new. super initialize: anOcean at: anX at: anY. Fish methodsFor: 'live processing' activate live ifTrue: [self move. self eat.] eat "Is there food where I am? If not (returns nil), leave. If so, EAT IT!" | localfood | localfood := ocean isFood: food at: x at: y. (localfood isNil) ifTrue: [^false]. localfood beEaten. move | randomizer arandom | randomizer := Random new. arandom := randomizer next. (arandom > 0.75) ifTrue: [x := x + 1] ifFalse: [(arandom > 0.5) ifTrue: [y := y + 1] ifFalse: [(arandom > 0.25) ifTrue: [ x:= x - 1] ifFalse: [y:= y - 1] ] ]. Fish methodsFor: 'food processing' canEat: something food add: something