Ejercicio 6b

This commit is contained in:
perro tuerto 2023-03-08 08:57:54 -08:00
parent 5eb6909977
commit 6ddf94087d
1 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,51 @@
import random
import zombiedice
class MyZombie:
def __init__(self, name):
self.name = name
def turn(self, gameState):
diceRollResults = zombiedice.roll()
turns = 0
brains = 0
shotgun = 0
while diceRollResults is not None:
turns += 1
brains += diceRollResults["brains"]
shotgun += diceRollResults["shotgun"]
again = True if random.randrange(0, 1) == 1 else False
roll_again = True
match self.name:
case "bot1":
roll_again = again
case "bot2":
if brains >= 2:
roll_again = False
case "bot3":
if shotgun >= 2:
roll_again = False
case "bot4":
if shotgun >= 2 or turns == 4:
roll_again = False
else:
roll_again = again
case "bot5":
if shotgun > brains:
roll_again = False
if roll_again:
diceRollResults = zombiedice.roll()
else:
break
zombies = (
MyZombie(name="bot1"),
MyZombie(name="bot2"),
MyZombie(name="bot3"),
MyZombie(name="bot4"),
MyZombie(name="bot5"),
)
zombiedice.runTournament(zombies=zombies, numGames=1000)