-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathludo.py
175 lines (118 loc) · 3.54 KB
/
ludo.py
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import random
player1_goti1 = 0
player1_goti2 = 0
player1_goti3 = 0
player1_goti4 = 0
player2_goti1 = 0
player2_goti2 = 0
player2_goti3 = 0
player2_goti4 = 0
player_turn = 0
def roll():
min_number = 1
max_number = 6
roll = random.randint(min_number,max_number)
return roll
def run_goti(number,goti_number,player_number):
global player1_goti1
global player1_goti2
global player1_goti3
global player1_goti4
global player2_goti1
global player2_goti2
global player2_goti3
global player2_goti4
if player_number == 1:
if goti_number == 1:
player1_goti1 += number
if goti_number == 2:
player1_goti2 += number
if goti_number == 3:
player1_goti3 += number
if goti_number == 4:
player1_goti4 += number
if player_number == 2:
if goti_number == 1:
player2_goti1 += number
if goti_number == 2:
player2_goti2 += number
if goti_number == 3:
player2_goti3 += number
if goti_number == 4:
player2_goti4 += number
def wake_up_goti(goti_number,player_number):
global player1_goti1
global player1_goti2
global player1_goti3
global player1_goti4
global player2_goti1
global player2_goti2
global player2_goti3
global player2_goti4
if player_number == 1:
if goti_number == 1:
player1_goti1 = 1
if goti_number == 2:
player1_goti2 = 1
if goti_number == 3:
player1_goti3 = 1
if goti_number == 4:
player1_goti4 = 1
if player_number == 2:
if goti_number == 1:
player2_goti1 = 1
if goti_number == 2:
player2_goti2 = 1
if goti_number == 3:
player2_goti3 = 1
if goti_number == 4:
player2_goti4 = 1
for i in range(20):
player_turn += 1
print("Player {}'s turn".format(player_turn))
if player_turn == 1:
print('Player1 goties =', player1_goti1, player1_goti2, player1_goti3, player1_goti4)
print('Player2 goties =' , player2_goti1,player2_goti2,player2_goti3, player2_goti4)
input('Press Enter to roll: ')
value = roll()
print('You got',value)
goti_number = int(input('Enter goti number: '))
player1_goties = {'1':player1_goti1,'2':player1_goti2,'3':player1_goti3,'4':player1_goti4}
if value == 1 or value == 6:
if int(player1_goties.get(str(goti_number))) == 0:
wake_up_goti(goti_number,player_turn)
else:
run_goti(1,goti_number,player_turn)
else:
if int(player1_goties.get(str(goti_number))) != 0:
run_goti(value,goti_number,player_turn)
if value == 6:
player_turn = 0
if player_turn == 2:
print('Player1 goties =', player1_goti1, player1_goti2, player1_goti3, player1_goti4)
print('Player2 goties =' , player2_goti1,player2_goti2,player2_goti3, player2_goti4)
input('Press Enter to roll: ')
value = roll()
print('You got',value)
goti_number = int(input('Enter goti number: '))
player2_goties = {'1':player2_goti1,'2':player2_goti2,'3':player2_goti3,'4':player2_goti4}
if value == 1 or value == 6:
if int(player2_goties.get(str(goti_number))) == 0:
wake_up_goti(goti_number,player_turn)
else:
run_goti(1,goti_number,player_turn)
else:
if int(player2_goties.get(str(goti_number))) != 0:
run_goti(value,goti_number,player_turn)
if value == 6:
player_turn = 1
else:
player_turn = 0
player1_total_score = player1_goti1 + player1_goti2 + player1_goti3 + player1_goti4
player2_total_score = player2_goti1 + player2_goti2 + player2_goti3 + player2_goti4
if player1_total_score > player2_total_score:
print('Player1 wins!!')
if player1_total_score < player2_total_score:
print('Player2 wins!!')
if player1_total_score == player2_total_score:
print('Tie!!')