-
Notifications
You must be signed in to change notification settings - Fork 0
/
zmain.coffee
116 lines (105 loc) · 4.27 KB
/
zmain.coffee
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
main = ->
curWeapon = weaponBestRange()
weaponSelect(curWeapon)
movements = getMovements(getCell(), getMP())
safeMovements = movements
pseudoSafeMovements = movements
enemiesIndex = 0
enemiesMovements = []
enemiesDangerMaps = []
while(enemiesIndex < count(enemies))
enemiesMovements[enemies[enemiesIndex]] = getMovements(getCell(enemies[enemiesIndex]), getMP(enemies[enemiesIndex]))
i = 0
while(i < count(enemiesMovements[enemies[enemiesIndex]]))
map = getDangerMap(enemies[enemiesIndex], enemiesMovements[enemies[enemiesIndex]][i], true)
pseudoMap = getDangerMap(enemies[enemiesIndex], enemiesMovements[enemies[enemiesIndex]][i], false)
debugMarkCells(pseudoMap, COLOR_RED)
if enemiesDangerMaps[enemies[enemiesIndex]] == null
enemiesDangerMaps[enemies[enemiesIndex]] = []
j = 0
while j < count(pseudoMap)
if !inArray(enemiesDangerMaps[enemies[enemiesIndex]], pseudoMap[j])
removeElement(safeMovements, pseudoMap[j])
removeElement(pseudoSafeMovements, pseudoMap[j]) #FIXME:Caching
push(enemiesDangerMaps[enemies[enemiesIndex]], pseudoMap[j])
j++
j = 0
while j < count(map)
if !inArray(enemiesDangerMaps[enemies[enemiesIndex]], map[j])
removeElement(safeMovements, map[j])
push(enemiesDangerMaps[enemies[enemiesIndex]], map[j])
j++
i++
enemiesIndex++
sort(safeMovements)
sort(pseudoSafeMovements)
debugMarkCells(movements, COLOR_BLUE)
bFoundSafePath = false
bFoundPseudoSafePath = false
bFoundAttackPath = false
path = []
bestPathDistanceToMiddle = MAP_SIZE + 1
cellIndex = 0
aggroMap = getAggroMap(getCell(), getMP())
debugMarkCells(aggroMap, getColor(255, 255, 0))
debugMarkCells(safeMovements, COLOR_GREEN)
mapIndex = 0
while(mapIndex < count(aggroMap))
if(inArray(safeMovements, aggroMap[mapIndex]))
distance = getCellDistance(aggroMap[mapIndex], MAP_CENTER)
if(!bFoundAttackPath || distance < bestPathDistanceToMiddle)
bestPathDistanceToMiddle = distance
path = [aggroMap[mapIndex]]
bFoundSafePath = true
bFoundAttackPath = true
else if(!bFoundSafePath && inArray(pseudoSafeMovements, aggroMap[mapIndex]))
distance = getCellDistance(aggroMap[mapIndex], MAP_CENTER)
if(!bFoundAttackPath || distance < bestPathDistanceToMiddle)
bestPathDistanceToMiddle = distance
path = [aggroMap[mapIndex]]
bFoundPseudoSafePath = true
bFoundAttackPath = true
else
subMovement = getMovements(aggroMap[mapIndex], getMP() - getPathLength(getCell(), aggroMap[mapIndex]))
subMovementIndex = 0
while(subMovementIndex < count(subMovement))
if(inArray(safeMovements, subMovement[subMovementIndex]))
distance = getCellDistance(aggroMap[mapIndex], MAP_CENTER)
if (!bFoundAttackPath || distance < bestPathDistanceToMiddle)
bestPathDistanceToMiddle = distance
path = [aggroMap[mapIndex], subMovement[subMovementIndex]]
bFoundSafePath = true
bFoundAttackPath = true
subMovementIndex++
mapIndex++
if !(bFoundAttackPath && bFoundSafePath)
while(cellIndex < count(movements))
distance = getCellDistance(movements[cellIndex], MAP_CENTER)
if(inArray(safeMovements, movements[cellIndex]))
if(!bFoundSafePath || distance < bestPathDistanceToMiddle)
bFoundSafePath = true
path = [movements[cellIndex]]
bestPathDistanceToMiddle = distance
else if(!bFoundSafePath && inArray(pseudoSafeMovements, aggroMap[mapIndex]))
if(!bFoundAttackPath || distance < bestPathDistanceToMiddle)
bFoundPseudoSafePath = true
path = [movements[cellIndex]]
bestPathDistanceToMiddle = distance
else if(!bFoundSafePath && !bFoundPseudoSafePath)
if(!bFoundAttackPath || distance < bestPathDistanceToMiddle)
path = [movements[cellIndex]]
bestPathDistanceToMiddle = distance
cellIndex++
debug("bFoundSafePath:")
debug(bFoundSafePath)
debug("bFoundPseudoSafePath:")
debug(bFoundPseudoSafePath)
debug("bFoundAttackPath")
debug(bFoundAttackPath)
debug("path")
debug(path)
moveAndAttackInPath(path)
return
main()
debug("Instructions:")
debug(getOperations())