<s> import random <EOL> import items , world <EOL> __author__ = '<STR_LIT>' <EOL> class Player ( ) : <EOL> def __init__ ( self ) : <EOL> self . inventory = [ items . Gold ( <NUM_LIT:15> ) , items . Rock ( ) ] <EOL> self . hp = <NUM_LIT:100> <EOL> self . location_x , self . location_y = world . starting_position <EOL> self . victory = False <EOL> def is_alive ( self ) : <EOL> return self . hp > <NUM_LIT:0> <EOL> def do_action ( self , action , ** kwargs ) : <EOL> action_method = getattr ( self , action . method . __name__ ) <EOL> if action_method : <EOL> action_method ( ** kwargs ) <EOL> def print_inventory ( self ) : <EOL> for item in self . inventory : <EOL> print ( item , '<STR_LIT:\n>' ) <EOL> def move ( self , dx , dy ) : <EOL> self . location_x += dx <EOL> self . location_y += dy <EOL> print ( world . tile_exists ( self . location_x , self . location_y ) . intro_text ( ) ) <EOL> def move_north ( self ) : <EOL> self . move ( dx = <NUM_LIT:0> , dy = - <NUM_LIT:1> ) <EOL> def move_south ( self ) : <EOL> self . move ( dx = <NUM_LIT:0> , dy = <NUM_LIT:1> ) <EOL> def move_east ( self ) : <EOL> self . move ( dx = <NUM_LIT:1> , dy = <NUM_LIT:0> ) <EOL> def move_west ( self ) : <EOL> self . move ( dx = - <NUM_LIT:1> , dy = <NUM_LIT:0> ) <EOL> def attack ( self , enemy ) : <EOL> best_weapon = None <EOL> max_dmg = <NUM_LIT:0> <EOL> for i in self . inventory : <EOL> if isinstance ( i , items . Weapon ) : <EOL> if i . damage > max_dmg : <EOL> max_dmg = i . damage <EOL> best_weapon = i <EOL> print ( "<STR_LIT>" . format ( best_weapon . name , enemy . name ) ) <EOL> enemy . hp -= best_weapon . damage <EOL> if not enemy . is_alive ( ) : <EOL> print ( "<STR_LIT>" . format ( enemy . name ) ) <EOL> else : <EOL> print ( "<STR_LIT>" . format ( enemy . name , enemy . hp ) ) <EOL> def flee ( self , tile ) : <EOL> """<STR_LIT>""" <EOL> available_moves = tile . adjacent_moves ( ) <EOL> r = random . randint ( <NUM_LIT:0> , len ( available_moves ) - <NUM_LIT:1> ) <EOL> self . do_action ( available_moves [ r ] ) </s>
