| Paste number 63936: | Game |
| Pasted by: | zachb |
| 4 months, 1 week ago | |
| None | |
| Paste contents: |
| def game(home, away, verbose=False): #a survival game #eat, plant, steal, poke field = Field() field.seeds = 0 field.crops = 3 home.hunger = 0 away.hunger = 0 home.happy = 100 away.happy = 100 home.lastmove = "-" away.lastmove = "-" homeaway = [home, away] for turn in range(50): if verbose: print "Turn: %s; Field: %sc | %ss; Home (%s): %s | %s; Away (%s): %s | %s" % (turn, field.crops, field.seeds, home.lastmove, home.hunger, home.happy, away.lastmove, away.hunger, away.happy) field.seeds += field.crops / 2 if field.seeds == field.crops == 0: field.seeds = 1 for i in range(2): player = homeaway[i] opp = homeaway[i-1] player.happy -= player.hunger player.hunger = min(player.hunger + 1, 10) move = player.evaluate([turn, player.happy, player.hunger, field.seeds, field.crops]) % 4 player.lastmove = move if move == 0: #eat! if field.crops: player.happy += 10 #food feels good player.hunger = max(player.hunger - 2, 0) if player.hunger == 0: player.happy += 10 #full stomach feels awesome field.crops -= 1 else: player.happy -= 15 elif move == 1: #plant! if field.seeds: player.happy -= 5 #work hurts field.seeds -= 1 field.crops += 2 else: player.happy -= 10 #work, but nothing in return!? elif move == 2: #steal! if opp.hunger < 8: player.happy -= 5 #i feel bad stealing... player.hunger -= 1 opp.hunger += 1 opp.happy -= 10 #i was stolen from! else: player.happy -= 10 #that sucks, i got nothing opp.happy += 10 #whoo! i thwarted his attempt! elif move == 3: #poke player.happy -= 5 #that was lame opp.happy -= 10 #ow! #whoever is happiest wins |
This paste has no annotations.