#NEWLINE# def getGameState( self ) : #NEWLINE# #INDENT# '\n\n        Returns\n        -------\n\n        dict\n            * snake head x position.\n            * snake head y position.\n            * food x position.\n            * food y position.\n            * distance from head to each snake segment.\n\n            See code for structure.\n\n        ' #NEWLINE# state = { #NEWLINE# #INDENT# 'snake_head_x' : self . player . head . pos . x , #NEWLINE# 'snake_head_y' : self . player . head . pos . y , #NEWLINE# 'food_x' : self . food . pos . x , #NEWLINE# 'food_y' : self . food . pos . y , #NEWLINE# 'snake_body' : [ ] , #NEWLINE# #UNINDENT# } #NEWLINE# for s in self . player . body : #NEWLINE# #INDENT# dist = math . sqrt ( ( ( ( self . player . head . pos . x - s . pos . x ) ** 2 ) + ( ( self . player . head . pos . y - state . pos . y ) ** 2 ) ) ) #NEWLINE# state [ 'snake_body' ] . append ( dist ) #NEWLINE# #UNINDENT# return state