Skip to content

Commit

Permalink
- Use the brain class/instance for ai (at the moment for satisfaction…
Browse files Browse the repository at this point in the history
… of needs, character/object recognition and movement)

- Interaction with characters. (needs a lot of improvment)
- Added need urination and toilet in-world object.
- Radii are now defined in object files and per activity.
- Radii are now handled of the brain object.
- Current simulation speed is 1.50 ticks per second (real time).
  • Loading branch information
Florian R. A. Angermeier committed Jun 26, 2011
1 parent 8ab1112 commit 012e005
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 250 deletions.
2 changes: 1 addition & 1 deletion Server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class Server:
def __init__( self ):
# Initializing the simulation
self.world = World( 1 )
self.world = World( 2 )
def run( self ):
print '\033[32mInfo\033[0m Starting world thread...'
reactor.callInThread( self.world.run )
Expand Down
101 changes: 75 additions & 26 deletions gameEngine/Brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,52 @@ def __init__( self, character ):
'food': 'eatSnack',
'water': 'drink',
'urination': 'use',
'hygiene': 'shower'
'hygiene': 'shower',
'fun': 'watch',
'social': 'talk' }
self.activitiesMedium = { 'sleep': 'rest',
'food': 'cook',
'water': 'drink',
'urination': 'use',
'hygiene': 'shower'
'hygiene': 'shower',
'fun': 'watch',
'social': 'talk' }
self.activitiesLow = { 'sleep': 'sleep',
'food': 'cook',
'water': 'drink',
'urination': 'use',
'hygiene': 'shower'
'hygiene': 'shower',
'fun': 'watch',
'social': 'talk' }
self.activityTimes = { 'rest': 900,
'sleep': 28800,
'eatSnack': 300,
'cook': 900,
'drink': 60,
'use': 450,
'shower': 1800,
'watch': 1800,
'talk': 300 }
self.activityInteractiveTypes = { 'rest': 'Bed',
'sleep': 'Bed',
'eatSnack': 'Refrigerator',
'cook': 'Cooker',
'drink': 'Refrigerator',
'use': 'Toilet',
'shower': 'Shower',
'watch': 'TvSet',
'talk': 'Character' }
self.activity = None
self.activityTimer = 0
self.activityInteractive = None

def getLowestNeed( self ):
# Returns the lowest need including its value as a tuple.
lowestNeed = (None, 1000)
for need in self.character.needs.keys():
try:
if( self.character.needs[need] < lowestNeed(1) ):
lowestNeed(0) = need
lowestNeed(1) = self.character.needs[need]
if( self.character.needs[need] < lowestNeed[1] ):
lowestNeed = ( need, self.character.needs[need] )
except:
print '\033[31mError\033[0m Character: %i\tNeed %s does not exist.' % ( self.character.id, need )
return lowestNeed
Expand All @@ -58,24 +78,50 @@ def getHighestNeed( self ):
highestNeed = (None, 0)
for need in self.character.needs.keys():
try:
if( self.character.needs[need] > highestNeed(1) ):
highestNeed(0) = need
highestNeed(1) = self.character.needs[need]
if( self.character.needs[need] > highestNeed[1] ):
highestNeed = ( need, self.character.needs[need] )
except:
print '\033[31mError\033[0m Character: %i\tNeed %s does not exist.' % ( self.character.id, need )
return highestNeed

def getNextActivity( self ):
# Get the next activity to satisfy the lowest need.
if( self.getLowestNeed()(1) <= 750 ): # 3/4, High
return self.activitiesHigh[ self.getLowestNeed()(0) ]
elif( self.getLowestNeed()(1) <= 500 ): # 1/2, Medium
return self.activitiesMedium[ self.getLowestNeed()(0) ]
elif( self.getLowestNeed()(1) <= 250 ): # 1/4, Low
return self.activitiesLow[ self.getLowestNeed()(0) ]
if( self.getLowestNeed()[1] <= 250 ): # 1/4, Low
self.activity = self.activitiesLow[ self.getLowestNeed()[0] ]
self.activityTimer = self.activityTimes[ self.activity ]
if( self.activityInteractiveTypes[ self.activity ] == 'Character' ):
self.activityInteractive = self.getCharacterById( 1 )
else:
self.activityInteractive = self.getObjectByType( self.activityInteractiveTypes[ self.activity ] )
return self.activitiesLow[ self.getLowestNeed()[0] ]
elif( self.getLowestNeed()[1] <= 500 ): # 1/2, Medium
self.activity = self.activitiesMedium[ self.getLowestNeed()[0] ]
self.activityTimer = self.activityTimes[ self.activity ]
if( self.activityInteractiveTypes[ self.activity ] == 'Character' ):
self.activityInteractive = self.getCharacterById( 1 )
else:
self.activityInteractive = self.getObjectByType( self.activityInteractiveTypes[ self.activity ] )
return self.activitiesMedium[ self.getLowestNeed()[0] ]
elif( self.getLowestNeed()[1] <= 750 ): # 3/4, High
self.activity = self.activitiesHigh[ self.getLowestNeed()[0] ]
self.activityTimer = self.activityTimes[ self.activity ]
if( self.activityInteractiveTypes[ self.activity ] == 'Character' ):
self.activityInteractive = self.getCharacterById( 1 )
else:
self.activityInteractive = self.getObjectByType( self.activityInteractiveTypes[ self.activity ] )
return self.activitiesHigh[ self.getLowestNeed()[0] ]
else:
self.activity = None
self.activityTimer = 0
self.activityInteractive = None
return None

def getCharacterById( self, id ):
# Searches for a character in the world by id and returns it.
for character in self.character.world.characters:
if( character.id == id ):
return character

def getObjectById( self, id ):
# Searches for an object in the world by id and returns it.
for object in self.character.world.objects:
Expand All @@ -90,19 +136,22 @@ def getObjectByType( self, type ):

def isInRange( self, characterOrObject, radiusType ):
# Checks if a character or object is in range by utilization of a bounding box and returns True if the object is in range.
# X axis
if( self.character.pos[ 0 ] >= characterOrObject.pos[ 0 ] - characterOrObject.radii[ radiusType ]
self.character.pos[ 0 ] <= characterOrObject.pos[ 0 ] + characterOrObject.radii[ radiusType ] ):
# Y axis
if( self.character.pos[ 1 ] >= characterOrObject.pos[ 1 ] - characterOrObject.radii[ radiusType ]
self.character.pos[ 1 ] <= characterOrObject.pos[ 1 ] + characterOrObject.radii[ radiusType ] ):
# Z axis
if( self.character.pos[ 2 ] >= characterOrObject.pos[ 2 ] - characterOrObject.radii[ radiusType ]
self.character.pos[ 2 ] <= characterOrObject.pos[ 2 ] + characterOrObject.radii[ radiusType ] ):
return True
try:
# X axis
if( self.character.pos[ 0 ] >= characterOrObject.pos[ 0 ] - characterOrObject.radii[ radiusType ] and
self.character.pos[ 0 ] <= characterOrObject.pos[ 0 ] + characterOrObject.radii[ radiusType ] ):
# Y axis
if( self.character.pos[ 1 ] >= characterOrObject.pos[ 1 ] - characterOrObject.radii[ radiusType ] and
self.character.pos[ 1 ] <= characterOrObject.pos[ 1 ] + characterOrObject.radii[ radiusType ] ):
# Z axis
if( self.character.pos[ 2 ] >= characterOrObject.pos[ 2 ] - characterOrObject.radii[ radiusType ] and
self.character.pos[ 2 ] <= characterOrObject.pos[ 2 ] + characterOrObject.radii[ radiusType ] ):
return True
else:
return False
else:
return False
else:
return False
else:
except:
return False
Loading

0 comments on commit 012e005

Please sign in to comment.