Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- ladders = {
- 1: 38,
- 4: 14,
- 8: 30,
- 21: 42,
- 28: 76,
- 50: 67,
- 71: 92,
- 80: 99,
- }
- snakes = {
- 97: 78,
- 62: 18,
- 95: 56,
- 88: 24,
- 36: 6,
- 48: 26,
- 32: 10,
- }
- class Player:
- list_of_players = []
- def __init__(self, name="", moves=0, position=0, AI=False):
- self.name = name
- self.moves = moves
- self.position = position
- self.AI = AI
- self.winner = False
- Player.list_of_players.append(self)
- def __repr__(self):
- return f"""player(AI={self.AI}, name={self.name})"""
- class Game:
- def __init__(self):
- human = input("How many human players? ")
- computer = input("How many AI's? ")
- for i in range(int(human)):
- player_name = input(f"What is your player {i + 1} name? ")
- self.player = Player(player_name)
- for j in range(int(computer)):
- self.AIplayer = Player(name=f"AI {j+1}", AI=True)
- def play(self):
- while self.player.winner is False:
- for each_player in Player.list_of_players:
- if not each_player.AI:
- input("Press Enter to roll the dice: ")
- dice = random.randint(1, 6)
- if each_player.position == 100:
- return f"{each_player.name} won!"
- elif (each_player.position + dice) > 100:
- intended_position = each_player.position + dice
- bounce_back = intended_position - 100
- each_player.position = 100 - bounce_back
- print(
- f"{each_player.name} overshot the winning tile by {bounce_back}, {each_player.name}'s position is currently {each_player.position}")
- else:
- each_player.position += dice
- print(f"{each_player.position} is {each_player.name}'s current position {dice}")
- if each_player.position == 100:
- return f"{each_player.name} won!"
- if each_player.position in ladders:
- print(f"{each_player.name} landed on a ladder! Your position is currently {ladders.get(each_player.position)}")
- each_player.position = ladders.get(each_player.position)
- elif each_player.position in snakes:
- print(f"{each_player.name} landed in a snake, Your position is current {snakes.get(each_player.position)}")
- each_player.position = snakes.get(each_player.position)
- else:
- dice = random.randint(1, 6)
- if each_player.position == 100:
- return f"{each_player.name} won!"
- elif (each_player.position + dice) > 100:
- intended_position = each_player.position + dice
- bounce_back = intended_position - 100
- each_player.position = 100 - bounce_back
- print(f"{each_player.name} overshot the winning tile by {bounce_back}, your position is currently {each_player.position}")
- else:
- each_player.position += dice
- print(f"{each_player.position} is the {each_player.name} current position {dice}")
- if each_player.position == 100:
- return f"{each_player.name} won!"
- if each_player.position in ladders:
- print(f"{each_player.name} landed on a ladder! {each_player.name} position is currently {ladders.get(each_player.position)}")
- each_player.position = ladders.get(each_player.position)
- elif each_player.position in snakes:
- print(f"{each_player.name} landed in a snake, {each_player.name} position is current {each_player.position}")
- each_player.position = snakes.get(each_player.position)
- game = Game()
- print(Player.list_of_players)
- print(game.play())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement