-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsolver.py
66 lines (55 loc) · 2.29 KB
/
solver.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
from ortools.linear_solver import pywraplp
import settings
from settings import eqTypeEnum
from settings import rarityEnum
from settings import simpleActionEnum
from settings import paramsActionEnum
from settings import waeponEnum
def safeget(dct, *keys):
for key in keys:
try:
dct = dct[key]
except KeyError:
return None
return dct
def getEquipEffectValue(dct,equipId,arg2=None):
var = safeget(dct,"definition","equipEffects",equipId,"effect","definition","params")
if var != None:
return var[0]+var[1]*50
return 0
def getEquipmentType(dct,equipmentTypeId,arg2=None):
var = dct["definition"]["item"]["baseParameters"]["itemTypeId"]
if var != None and var == equipmentTypeId:
return 1
return 0
def getWaeponType(dct,waeponTypeString,arg2=None):
var = safeget(dct,"definition","item","baseParameters",waeponTypeString)
if var != None:
return 1
return 0
def getRarity(dct,rarity,arg2=None):
var = safeget(dct,"definition","item","baseParameters","rarity")
if var != None and var == rarity:
return 1
return 0
def getEquipEffectValueWithParams(dct,equipId,ratio=1):
var = safeget(dct,"definition","equipEffects",equipId,"effect","definition","params")
if var != None:
if ratio >= var[2]:
return var[0] * var[2]
else :
return var[0]*ratio
return 0
def getLevel(dct):
var = safeget(dct,"definition","item","level")
if var != None:
return var
return 0
def createSimpleAddSubstractConstraint(actionAdd,actionMinus,ratio=1):
return (createConstraintWithFunc(getEquipEffectValue,actionAdd,ratio) - createConstraintWithFunc(getEquipEffectValue,actionMinus,ratio))
def createParamsConstraint(actionAdd,actionMinus,ratio=1):
return (createConstraintWithFunc(getEquipEffectValueWithParams,actionAdd,ratio) - createConstraintWithFunc(getEquipEffectValueWithParams,actionMinus,ratio))
def createConstraintWithFunc(function,arg1,arg2=None):
return sum(var*function(settings.ITEMS_DATA[id],arg1,arg2) for id,var in settings.VARIABLES.items() if function(settings.ITEMS_DATA[id],arg1,arg2) != 0)
def createLevelConstraint(level):
return sum(var for id,var in settings.VARIABLES.items() if getLevel(settings.ITEMS_DATA[id]) >= level )