"""
Practice Projects: Zombie Dice Bots
Page 155
"""

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)
