-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_engine.py
More file actions
40 lines (35 loc) · 1.25 KB
/
game_engine.py
File metadata and controls
40 lines (35 loc) · 1.25 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
import random
class RussianRoulette:
def __init__(self, bullet_position=None):
self.chambers = 6
if bullet_position is not None:
self.bullet_position = bullet_position
else:
self.bullet_position = random.randint(0, 5)
self.current_chamber = 0
self.game_over = False
def pull_trigger(self):
"""
Simula apretar el gatillo.
Retorna:
"BANG" si la bala está en la recámara actual.
"CLICK" si la recámara está vacía.
"ALREADY_OVER" si el juego ya terminó.
"""
if self.game_over:
return "ALREADY_OVER"
result = "CLICK"
if self.current_chamber == self.bullet_position:
result = "BANG"
self.game_over = True
self.current_chamber += 1
return result
def get_status(self):
"""
Retorna el estado actual del revólver.
"""
return {
"chamber_index": self.current_chamber,
"total_chambers": self.chambers,
"probability_percent": round(100 / (self.chambers - self.current_chamber), 1) if self.current_chamber < self.chambers else 100
}