MCPcopy Create free account
hub / github.com/codecombat/codecombat / permuteActions

Function permuteActions

app/lib/level-generation.js:1142–1404  ·  view source on GitHub ↗
({ actions, thangs, checkDistanceTraveled, checkZapTurns, checkHitTurns })

Source from the content-addressed store, hash-verified

1140// - Should turn when hero turns, go forward when it goes forward, goes backwards when it goes backwards
1141// - Should follow similar patterns for hit and zap
1142function permuteActions ({ actions, thangs, checkDistanceTraveled, checkZapTurns, checkHitTurns }) {
1143 const hero = _.find(thangs, { id: 'Hero Placeholder' })
1144 const heroPhysical = _.find(hero.components, (component) => component.original === PhysicalID)
1145 const startPos = simplifyPos(heroPhysical.config.pos)
1146 const currentPosSrc = startPos.copy()
1147 const currentPosNew = startPos.copy()
1148 let lastDirectionsPerActionSrc = {}
1149 let lastDirectionsPerActionNew = {}
1150 const actionsSrc = actions
1151 const actionsNew = []
1152 const thangsSrc = thangs
1153 const thangsNew = _.cloneDeep(thangs)
1154 setPositionPlaceholders(thangsNew)
1155 const visitedPositions = [startPos.copy()]
1156 let hasSeenZap = false
1157 let lastAction
1158 const loopStack = []
1159 let actionIndex = 0
1160 while (actionIndex < actionsSrc.length) {
1161 const inRepeatedLoop = _.find(loopStack, (loop) => loop.currentIteration > 0)
1162 const actionSrc = actionsSrc[actionIndex]
1163 const actionNew = inRepeatedLoop ? actionsNew[actionIndex] : actionSrc.clone()
1164 const lastDirectionSrc = lastDirectionsPerActionSrc[actionSrc.type]
1165
1166 if (actionSrc.type === 'for') {
1167 loopStack.push({ startIndex: actionIndex, iterations: actionSrc.loopCount, currentIteration: 0 })
1168 if (!inRepeatedLoop) {
1169 actionsNew.push(actionNew)
1170 }
1171 ++actionIndex
1172 continue
1173 }
1174
1175 if (actionSrc.type === '}') {
1176 if (loopStack.length > 0) {
1177 const currentLoop = loopStack[loopStack.length - 1]
1178 if (++currentLoop.currentIteration < currentLoop.iterations) {
1179 actionIndex = currentLoop.startIndex
1180 } else {
1181 loopStack.pop()
1182 }
1183 }
1184 if (!inRepeatedLoop) {
1185 actionsNew.push(actionNew)
1186 }
1187 actionIndex++
1188 continue
1189 }
1190
1191 const lastDirectionNew = lastDirectionsPerActionNew[actionNew.type]
1192 const currentDirectionRelationshipSrc = lastDirectionSrc ? actionSrc.direction.getRelationship(lastDirectionSrc) : undefined
1193 if (actionSrc.type === 'go') {
1194 const targetCurrentPosSrc = currentPosSrc.copy().add(actionSrc.direction.vector.copy().multiply(actionSrc.distance || 1))
1195 const targetDistanceFromStart = manhattanDistance(startPos, targetCurrentPosSrc)
1196 let targetCurrentPosNew, valid
1197 let tries = 0
1198 do {
1199 valid = true

Callers 1

Calls 9

simplifyPosFunction · 0.85
setPositionPlaceholdersFunction · 0.85
manhattanDistanceFunction · 0.85
findThangAtFunction · 0.85
moveThangFunction · 0.85
processExplosiveChainFunction · 0.85
getRelationshipMethod · 0.80
logMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected