Dice game

Pig Game (Dice Game) – Description

Pig is a simple two-player dice game where the goal is to be the first player to reach a target score (often 100 points).

On each turn, a player rolls a die repeatedly until either:

1. They roll a 1 – in which case they score nothing for that turn, and it becomes the other player’s turn.


2. They choose to “hold” – which means they stop rolling and add their turn total to their overall score.



The risk is that if you roll a 1, you lose all points accumulated in that turn.

The strategy is deciding when to keep rolling for more points or when to “hold” and secure your current turn score.


The game is called “Pig” because it’s about greed vs. caution – players must decide whether to be greedy and risk it all, or play safe.

import random

def roll():
 min_value = 1
 max_value = 6
 roll = random.randint(min_value,max_value)
 return roll
value = roll()
print(value)

while True:
 players = input("Enter the number of players ?")
 if players.isdigit():
  players = int(players)
  if 2 <= players <= 4:
   break
  else: 
   print("player must be in 2 - 4")
 else:
  print("invalid again")

max_score = 50  
player_score = [0 for i in range(players)]
print(player_score)

while max(player_score) < max_score:
 for player_idx in range(players):
  print("\n Player number",player_idx+1,"turn has just started")
  current_score = 0
  while True:
   should_roll = input("would you like to play (y)")
   if should_roll != "y":
    break
   value = roll()
    
   if value == 1:
    print("you loose all points")
    current_score = 0
    break
   else:
    current_score = current_score + value
   
   print("you rolled a",value)
   print("your score is",current_score)
   
   player_score[player_idx] += current_score
   print("your total score is-",player_score[player_idx])

If you want more projects like this visit my github profile Github
   

Comments

Popular posts from this blog

Rock paper scissors