-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmain.py
58 lines (43 loc) · 1.44 KB
/
main.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
from time import time
from json import load
from functools import cmp_to_key
from src.spellcast import Spellcast
from src.searchnode import SearchNode
start_time = time()
config = load(open("config.json"))
game = Spellcast()
game.load_file("board.txt")
def compare_moves(a: SearchNode, b: SearchNode):
a_score = a.estimated_long_term_score(game)
b_score = b.estimated_long_term_score(game)
difference = a_score - b_score
if difference == 0:
return a.gem_count() - b.gem_count()
else:
return difference
if __name__ == "__main__":
print("searching for moves...")
best_moves = game.legal_moves(
cmp_to_key(compare_moves)
if config["gemManagement"]
else SearchNode.score
)
if config["logResults"]:
found_words = [move.word() for move in best_moves]
found_words.sort(reverse=True, key=len)
log_file = open("results.log", "w")
log_file.write("\n".join(found_words))
log_file.close()
shuffle_score, shuffle_recommended = game.evaluate_shuffle(best_moves[0])
if shuffle_recommended:
print(f"engine recommends shuffling - {shuffle_score} estimated value")
print("\n".join([
f"{i + 1} > {node.to_string(game)}"
for i, node in enumerate(
best_moves[:config["movesShown"]]
)
]))
print(
f"found {len(best_moves)} words"
+ f" in {round(time() - start_time, 2)} seconds."
)