-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.py
89 lines (68 loc) · 3.05 KB
/
start.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
from backshot import *
import time
bot = BackshotRoulette()
def string_to_item(item_string: str):
item_string = item_string.lower()
items = []
for char in item_string:
match char:
case "h":
items += [Items.HANDCUFFS]
case "s":
items += [Items.HAND_SAW]
case "c":
items += [Items.CIGARETTES]
case "b":
items += [Items.BEER]
case "m":
items += [Items.MAGNIFYING_GLASS]
case "a":
items += [Items.ADRENALINE]
case "e":
items += [Items.EXPIRED_MEDICINE]
case "f":
items += [Items.BURNER_PHONE]
case "i":
items += [Items.INVERTER]
return items
def idiot_input(prompt: object = "", condition = lambda x: 1):
while True:
var = input(prompt)
if condition(var): return var
IS_DIGIT_STRING = lambda x: x.isdigit() if type(x) == str else False
is_players_turn = input("Is it the players turn? (Y/N) ").lower().startswith("y")
max_health = int(idiot_input("Maximum health? ", IS_DIGIT_STRING))
dealer_health = int(idiot_input("Dealer's health? ", IS_DIGIT_STRING))
player_health = int(idiot_input("Player's health? ", IS_DIGIT_STRING))
lives = int(idiot_input("# live shells? ", IS_DIGIT_STRING))
blanks = int(idiot_input("# blank shells? ", IS_DIGIT_STRING))
print("Item Key: [H]andcuffs, Hand [S]aw, [C]igarettes, [B]eer, [M]agnifying Glass")
dealer_items = string_to_item(idiot_input("Dealer's items? ", lambda x: len(x) <= 8))
player_items = string_to_item(idiot_input("Player's items? ", lambda x: len(x) <= 8))
current_shell = input("Current shell? ('live', 'blank', leave empty for unknown) ").lower()
if current_shell.startswith("l"):
current_shell = "live"
elif current_shell.startswith("b"):
current_shell = "blank"
else:
current_shell = None
handcuffed = int(idiot_input("Is the other player handcuffed? (0 - No, 1 - Has already skipped turn, 2 - Has not skipped turn) ", lambda x: IS_DIGIT_STRING(x) and x in ["0", "1", "2"]))
sawed = input("Is the gun sawed? (Y/N) ").lower().startswith("y")
position = BuckshotRouletteMove(is_players_turn,
max_health, dealer_health, player_health,
lives, blanks,
dealer_items,
player_items)
position.loaded_shells.set_shell(0, current_shell)
position.handcuffed = handcuffed
position.gun_is_sawed = sawed
max_depth = 18
start_time = time.time()
for depth in range (1, max_depth + 1):
depth_start_time = time.time()
bot.max_depth = depth
bot.positions_searched = 0
print("Starting search with depth", depth)
print(bot.search(depth, position))
print(f"Searched {bot.positions_searched} positions in {time.time() - depth_start_time} seconds.")
print(f"Completed search in {time.time() - start_time} seconds.")