-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsp_dota_2.py
85 lines (62 loc) · 1.97 KB
/
csp_dota_2.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
from itertools import combinations
from simpleai.search import (
CspProblem,
backtrack,
min_conflicts,
MOST_CONSTRAINED_VARIABLE,
HIGHEST_DEGREE_VARIABLE,
LEAST_CONSTRAINING_VALUE,
)
from simpleai.search.csp import convert_to_binary
variables = ["slot_a", "slot_b", "slot_c"]
COSTOS = {
"assault_cuirass": 5000,
"battlefury": 4000,
"cloak": 500,
"hyperstone": 2000,
"quelling_blase": 200,
"shadow_blade": 3000,
"veil_of_discord": 2000,
}
# name, price
dominios = {}
for variable in ["slot_b", "slot_c"]:
dominios[variable] = [
"assault_cuirass",
"battlefury",
"cloak",
"hyperstone",
"quelling_blase",
"shadow_blade",
"veil_of_discord",
]
dominios["slot_a"] = ["battlefury", "veil_of_discord"]
restricciones = []
def sumar_items(variables, values):
costo_total = sum(COSTOS[item] for item in values)
return costo_total <= 6000
restricciones.append(
(('slot_a', 'slot_b', 'slot_c'), sumar_items),
)
def hyperstone_no_con_shadow_blade(variables, values):
mala_combinacion = {"hyperstone", "shadow_blade"}
return set(values) != mala_combinacion
def quelling_no_con_shadow(variables, values):
mala_combinacion = {"quelling_blase", "shadow_blade"}
return set(values) != mala_combinacion
def cloack_no_con_veil(variables, values):
mala_combinacion = {"cloak", "veil_of_discord"}
return set(values) != mala_combinacion
def diferentes(variables, values):
item_a, item_b = values
return item_a != item_b
for variable1, variable2 in combinations(variables, 2):
restricciones.extend([
((variable1, variable2), hyperstone_no_con_shadow_blade),
((variable1, variable2), quelling_no_con_shadow),
((variable1, variable2), cloack_no_con_veil),
((variable1, variable2), diferentes),
])
problem = CspProblem(variables, dominios, restricciones)
result = min_conflicts(problem, iterations_limit=100)
print(result)