forked from metafy-social/python-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
127 lines (89 loc) · 2.67 KB
/
Copy pathmain.py
File metadata and controls
127 lines (89 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import random
#Setting game parameters
Overs = int(input("Enter the number of Overs for the game : "))
Wkts = int(input("Enter the number of Wickets each side : "))
Balls = Overs*6
print("\n")
def Game_1() :
Wkts_P1 = Wkts_P2 = Wkts
Balls_P1 = Balls_P2 = Balls
P2_score,P1_score = 0,0
while(Wkts_P1 != 0 and Balls_P1 != 0) :
P1_hand = int(input("Enter your hand : "))
P2_hand = random.randint(1,6)
print("Bot plays : ",P2_hand)
if( P1_hand == P2_hand ):
Wkts_P1 = Wkts_P1 - 1
print("\nYou lost a wicket!!\n")
else :
P1_score += P1_hand
Balls_P1 = Balls_P1 - 1
print("Balls left to play : ",Balls_P1,"\n")
Target = P1_score + 1
print("Bot's target is - ", Target, "\n")
while( Wkts_P2 != 0 and Balls_P2 != 0 and P2_score<Target ) :
P1_hand = int(input("Enter your hand : "))
P2_hand = random.randint(1,6)
print("Bot plays : ",P2_hand)
if( P1_hand == P2_hand ):
Wkts_P2 = Wkts_P2 - 1
print("\nBot lost a wicket!!\n")
else :
P2_score += P2_hand
Balls_P2 = Balls_P2 - 1
print("Balls left to play : ",Balls_P2)
if( Wkts_P2 == 0 or P2_score <= Target ) :
print("\nYou win the game !!!\n")
elif( Wkts != 0 and P2_score>Target ) :
print("\nBot wins the game !!!\n")
def Game_2() :
Wkts_P1 = Wkts_P2 = Wkts
Balls_P1 = Balls_P2 = Balls
P2_score,P1_score = 0,0
while(Wkts_P1 != 0 and Balls_P1 != 0) :
P2_hand = int(input("Enter your hand : "))
P1_hand = random.randint(1,6)
print("Bot plays : ",P1_hand)
if( P1_hand == P2_hand ):
Wkts_P1 = Wkts_P1 - 1
print("Bot loses a wicket!!\n")
else :
P1_score += P1_hand
Balls_P1 = Balls_P1 - 1
print("Balls left to play : ",Balls_P1,"\n")
Target = P1_score + 1
print("Your target is - ", Target, "\n")
while( Wkts_P2 != 0 and Balls_P2 != 0 and P2_score<Target ) :
P2_hand = int(input("Enter your hand : "))
P1_hand = random.randint(1,6)
print("Bot plays : ",P2_hand)
if( P1_hand == P2_hand ):
Wkts_P2 = Wkts_P2 - 1
print("You lost a wicket!!\n")
else :
P2_score += P2_hand
Balls_P2 = Balls_P2 - 1
print("Balls left to play : ",Balls_P2,"\n")
if( Wkts_P2 == 0 or P2_score <= Target ) :
print("\nBot wins the game !!!\n")
elif( Wkts != 0 and P2_score>Target ) :
print("\nYou win the game !!!\n")
#Toss
Toss_choice = input("You -> Enter H (Head) or T (Tails) : ")
Toss = random.choice(["H","T"])
if Toss_choice == Toss:
print("You win the Toss.\n")
P1 = input("Choose B(Batting) or F(Fielding) : ")
print("You chose to " ,P1, "first.\n")
if P1 == "B" :
Game_1()
else :
Game_2()
else:
print("Bot wins the Toss.\n")
P2 = random.choice(["B","F"])
print("Bot chose to " ,P2, "first.\n")
if P2 == "B" :
Game_2()
else :
Game_1()