-
Notifications
You must be signed in to change notification settings - Fork 0
/
plinko.py
212 lines (169 loc) · 6.02 KB
/
plinko.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import random
import matplotlib.pyplot as plt
import numpy as np
import pygame
# We'll be using pygame for this game/simulation!
pygame.init()
# Setting the screen size (Don't change)
res = (720, 720)
screen = pygame.display.set_mode(res)
width = screen.get_width()
height = screen.get_height()
# Set background colour
screen.fill((222, 222, 222))
# Set caption
pygame.display.set_caption("Plinko Game")
# Create colour shortcuts
white = (255, 255, 255)
color_light = (170, 170, 170)
color_dark = (100, 100, 100)
black = (0, 0, 0)
red = (255, 0, 0)
red2 = (255, 60, 0)
orange = (255, 120, 0)
orange2 = (255, 180, 0)
yellow = (255, 240, 0)
# Balance
n = 50000
quit_font = pygame.font.SysFont('Corbel', 35)
quit_text = quit_font.render('quit', True, white)
bin_font = pygame.font.SysFont('Ariel', 25)
balance_font = pygame.font.SysFont('Corbel', 35)
# Plinko ball
ball_radius = 8
ball_x = width/2
ball_y1 = 50
# Creating a dict to store all outcomes
# bin = {"left4": 0, "left3": 0, "left2": 0, "left1": 0, "mid": 0,
# "right1": 0, "right2": 0, "right3": 0, "right4": 0}
# # Here are the odds
# multiplier = [11.5, 3.15, 1.30, 0.70, 0.35, 0.70, 1.30, 3.15, 11.5]
# num_trials = 50000
# # User will set starting amount and bet amount
# dollars = int(input("Enter your starting amount: $"))
# bet = int(input("Enter your bet amount: $"))
# Create the plinko ball object
# def draw_ball():
# pygame.draw.circle(screen, black, (ball_x, ball_y), ball_radius)
# Create the bin objects
def draw_rect():
pygame.draw.rect(screen, red, (25, height-60, 70, 40))
pygame.draw.rect(screen, red2, (100, height-60, 70, 40))
pygame.draw.rect(screen, orange, (175, height-60, 70, 40))
pygame.draw.rect(screen, orange2, (250, height-60, 70, 40))
pygame.draw.rect(screen, yellow, (325, height-60, 70, 40))
pygame.draw.rect(screen, orange2, (400, height-60, 70, 40))
pygame.draw.rect(screen, orange, (475, height-60, 70, 40))
pygame.draw.rect(screen, red2, (550, height-60, 70, 40))
pygame.draw.rect(screen, red, (625, height-60, 70, 40))
def bin_text():
bin_text = bin_font.render('11.5x', True, black)
screen.blit(bin_text, (35, height-45))
screen.blit(bin_text, (635, height-45))
bin_text = bin_font.render('3.15x', True, black)
screen.blit(bin_text, (110, height-45))
screen.blit(bin_text, (560, height-45))
bin_text = bin_font.render('1.30x', True, black)
screen.blit(bin_text, (185, height-45))
screen.blit(bin_text, (485, height-45))
bin_text = bin_font.render('0.70x', True, black)
screen.blit(bin_text, (260, height-45))
screen.blit(bin_text, (410, height-45))
bin_text = bin_font.render('0.35x', True, black)
screen.blit(bin_text, (335, height-45))
balance_text = balance_font.render(str(n), True, black)
screen.blit(balance_text, (50, 50))
clock = pygame.time.Clock()
while True:
ball_y1 = ball_y1 + 4
if ball_y1 > height-60:
ball_y1 = 50
screen.fill((222, 222, 222))
for ev in pygame.event.get():
# When user clicks the "Quit" button
if ev.type == pygame.QUIT:
pygame.quit()
if ev.type == pygame.MOUSEBUTTONDOWN:
if width-155 <= mouse[0] <= width-15 and 15 <= mouse[1] <= 55:
pygame.quit()
pygame.draw.circle(screen, black, (ball_x, ball_y1), ball_radius)
clock.tick(60)
mouse = pygame.mouse.get_pos()
if width-155 <= mouse[0] <= width-15 and 15 <= mouse[1] <= 55:
pygame.draw.rect(screen, color_light, [width-155, 15, 140, 40])
else:
pygame.draw.rect(screen, color_dark, [width-155, 15, 140, 40])
draw_rect()
bin_text()
screen.blit(quit_text, (width-105, 20))
pygame.display.update()
# for i in range(num_trials):
# dollars -= bet
# decider = random.randint(0, 1)
# index = 4
# for i in range(8):
# random_number = random.randint(0, 1)
# if random_number == 0:
# index += 0.5
# elif random_number == 1:
# index -= 0.5
# if index % 1 == 0.5:
# if decider == 0:
# index += 0.5
# else:
# index -= 0.5
# # Falling in one of the bins will change value of bin & total
# if index == 0:
# bin["left4"] += 1
# dollars += bet*multiplier[0]
# elif index == 1:
# bin["left3"] += 1
# dollars += bet*multiplier[1]
# elif index == 2:
# bin["left2"] += 1
# dollars += bet*multiplier[2]
# elif index == 3:
# bin["left1"] += 1
# dollars += bet*multiplier[3]
# elif index == 4:
# bin["mid"] += 1
# dollars += bet*multiplier[4]
# elif index == 5:
# bin["right1"] += 1
# dollars += bet*multiplier[5]
# elif index == 6:
# bin["right2"] += 1
# dollars += bet*multiplier[6]
# elif index == 7:
# bin["right3"] += 1
# dollars += bet*multiplier[7]
# elif index == 8:
# bin["right4"] += 1
# dollars += bet*multiplier[8]
# location = list(bin.keys())
# value = list(bin.values())
# percent_norm = []
# # Let's calculate the odds of balls falling into each bin!
# for i in value:
# percent_norm.append(i/num_trials * 100)
# percent = [round(num, 2) for num in percent_norm]
# # Let's also check what the house edge for the current simulation is
# house_edge = 100
# for i in range(len(multiplier)):
# house_edge -= percent[i] * multiplier[i]
# print()
# print("***** DISTRIBUTION *****")
# print("Occurrences - ", value)
# print("Percent - ", percent)
# print()
# print("***** BALANCE *****")
# print(round(dollars, 2))
# print("***** RECORDED HOUSE EDGE *****")
# print(round(house_edge, 2), "%")
# *** TESTERS ***
# x_axis = np.array(value)
# plt.plot(x_axis)
# plt.xlabel("Bins")
# plt.ylabel("Number of Occurrences")
# plt.title("Plinko Chart")
# plt.show()