# CS6 15 Treasured In Ice Level Help

Hello, here comes some errors about types during I write the code. I have been searching for the solution for a few months, but still couldnβt get the solutionπ­. Here is my code:

exitPosition = {βxβ: 150, βyβ: 120}
distanceBetweenRooms = 16
zeroShift = {βxβ: 10, βyβ: 10}

inSearch = True
width = 19
height = 15

def coorConvert(i, dist):
return i * distanceBetweenRooms / 2 + zeroShift.x

wall = βXβ
unknown = β?β
empty = β.β

maze =

for i in range(height):
maze.append([wall])

for i in range(height):
if i % 2:
for j in range(width - 1):
maze[i].append(unknown)
else:
for j in range(width - 1):
if j % 2:
maze[i].append(wall)
else:
maze[i].append(unknown)

def checkPaths(cMap):
cMap[hero.row][hero.col] = β.β
dirs = [[1, 0, north], [-1, 0, south], [0, 1, west], [0, -1, east]]
for d in range(len(dirs)):
dx = dirs[d][0]
dy = dirs[d][1]
dPosFunc = dirs[d][2]
if (cMap[hero.row+dx][hero.col+dy] == β?β
and hero.isPathClear(hero.pos, dPosFunc())):
cMap[hero.row+dx][hero.col+dy] = β.β
return cMap

def findPath(m, needExit):
stack = [[hero.row, hero.col, ββ]]
visited =
index = 0
while len(stack):
current = stack[index]
index += 1
row = current[0]
col = current[1]
path = current[2]
data = m[row-1][col] + " "
strPos = row + β-β + col
if visited.indexOf(strPos) != 1:
continue
visited.append(strPos)
if not needExit and m[row][col] == β?β:
return path
if needExit and row == exitRow and col == exitCol:
return path + β!β
if m[row-1][col] == β.β:
stack.append([row-2, col, path + βSβ])
if m[row+1][col] == β.β:
stack.append([row+2, col, path + βNβ])
if m[row][col+1] == β.β:
stack.append([row, col + 2, path + βWβ])
if m[row][col-1] == β.β:
stack.append([row, col - 2, path + βEβ])
for p in range(len(path)):
moveDir(path[p])

def moveDir(direction):
newPosFunc = {
βNβ : north,
βSβ : south,
βEβ : east,
βWβ : west,
β!β : exit
}[direction]
newPos = newPosFunc()
hero.moveXY(newPos.x, newPos.y)
if direction == β!β:
inSearch = False
hero.row = newPos.row
hero.col = newPos.col

def east():
return {βxβ : coorConvert(hero.col - 2),
βyβ : coorConvert(hero.row),
βrowβ : hero.row, βcolβ : hero.col - 2}

def west():
return {βxβ : coorConvert(hero.col + 2),
βyβ : coorConvert(hero.row),
βrowβ : hero.row, βcolβ : hero.col + 2}

def south():
return {βxβ : coorConvert(hero.col),
βyβ : coorConvert(hero.row - 2),
βrowβ : hero.row - 2, βcolβ : hero.col}

def north():
return {βxβ : coorConvert(hero.col),
βyβ : coorConvert(hero.row + 2),
βrowβ : hero.row + 2, βcolβ : hero.col}

def exit():
return exitPosition

path = ββ
treasureFound = False

while inSearch:
maze = checkPaths(maze)
if hero.gold > 0:
treasureFound = True
inSearch = False
path = findPath(maze, treasureFound)
if not path:
pass
else:
for p in range(len(path)):
moveDir(path[p])

Welcome to the codecombat discourse! a place to talk about code combat and code a cozy chatting place maybe! by the way when asking for solutions please format your code with the </> button

[quote=βTsaibow, post:1, topic:35828, full:trueβ]
Hello, here comes some errors about types during I write the code. I have been searching for the solution for a few months, but still couldnβt get the solutionπ­. Here is my code:

exitPosition = {βxβ: 150, βyβ: 120}
distanceBetweenRooms = 16
zeroShift = {βxβ: 10, βyβ: 10}

inSearch = True
width = 19
height = 15

def coorConvert(i, dist):
return i * distanceBetweenRooms / 2 + zeroShift.x

wall = βXβ
unknown = β?β
empty = β.β

maze =

for i in range(height):
maze.append([wall])

for i in range(height):
if i % 2:
for j in range(width - 1):
maze[i].append(unknown)
else:
for j in range(width - 1):
if j % 2:
maze[i].append(wall)
else:
maze[i].append(unknown)

def checkPaths(cMap):
cMap[hero.row][hero.col] = β.β
dirs = [[1, 0, north], [-1, 0, south], [0, 1, west], [0, -1, east]]
for d in range(len(dirs)):
dx = dirs[d][0]
dy = dirs[d][1]
dPosFunc = dirs[d][2]
if (cMap[hero.row+dx][hero.col+dy] == β?β
and hero.isPathClear(hero.pos, dPosFunc())):
cMap[hero.row+dx][hero.col+dy] = β.β
return cMap

def findPath(m, needExit):
stack = [[hero.row, hero.col, ββ]]
visited =
index = 0
while len(stack):
current = stack[index]
index += 1
row = current[0]
col = current[1]
path = current[2]
data = m[row-1][col] + " "
strPos = row + β-β + col
if visited.indexOf(strPos) != 1:
continue
visited.append(strPos)
if not needExit and m[row][col] == β?β:
return path
if needExit and row == exitRow and col == exitCol:
return path + β!β
if m[row-1][col] == β.β:
stack.append([row-2, col, path + βSβ])
if m[row+1][col] == β.β:
stack.append([row+2, col, path + βNβ])
if m[row][col+1] == β.β:
stack.append([row, col + 2, path + βWβ])
if m[row][col-1] == β.β:
stack.append([row, col - 2, path + βEβ])
for p in range(len(path)):
moveDir(path[p])

def moveDir(direction):
newPosFunc = {
βNβ : north,
βSβ : south,
βEβ : east,
βWβ : west,
β!β : exit
}[direction]
newPos = newPosFunc()
hero.moveXY(newPos.x, newPos.y)
if direction == β!β:
inSearch = False
hero.row = newPos.row
hero.col = newPos.col

def east():
return {βxβ : coorConvert(hero.col - 2),
βyβ : coorConvert(hero.row),
βrowβ : hero.row, βcolβ : hero.col - 2}

def west():
return {βxβ : coorConvert(hero.col + 2),
βyβ : coorConvert(hero.row),
βrowβ : hero.row, βcolβ : hero.col + 2}

def south():
return {βxβ : coorConvert(hero.col),
βyβ : coorConvert(hero.row - 2),
βrowβ : hero.row - 2, βcolβ : hero.col}

def north():
return {βxβ : coorConvert(hero.col),
βyβ : coorConvert(hero.row + 2),
βrowβ : hero.row + 2, βcolβ : hero.col}

def exit():
return exitPosition

path = ββ
treasureFound = False

while inSearch:
maze = checkPaths(maze)
if hero.gold > 0:
treasureFound = True
inSearch = False
path = findPath(maze, treasureFound)
if not path:
pass
else:
for p in range(len(path)):
moveDir(path[p])

maze =
First error i see gotta check more code

also because you formatted the same unformatted code even when formated its well wrong

Thanks for the tip. I will make it better

exitPosition = {βxβ: 150, βyβ: 120}
distanceBetweenRooms = 16
zeroShift = {βxβ: 10, βyβ: 10}

inSearch = True
width = 19
height = 15

def coorConvert(i, dist):
return i * distanceBetweenRooms / 2 + zeroShift.x

wall = βXβ
unknown = β?β
empty = β.β

maze =[]

for i in range(height):
maze.append([wall])

for i in range(height):
if i % 2:
for j in range(width - 1):
maze[i].append(unknown)
else:
for j in range(width - 1):
if j % 2:
maze[i].append(wall)
else:
maze[i].append(unknown)

def checkPaths(cMap):
cMap[hero.row][hero.col] = β.β
dirs = [[1, 0, north], [-1, 0, south], [0, 1, west], [0, -1, east]]
for d in range(len(dirs)):
dx = dirs[d][0]
dy = dirs[d][1]
dPosFunc = dirs[d][2]
if (cMap[hero.row+dx][hero.col+dy] == β?β
and hero.isPathClear(hero.pos, dPosFunc())):
cMap[hero.row+dx][hero.col+dy] = β.β
return cMap

def findPath(m, needExit):
stack = [[hero.row, hero.col, ββ]]
visited =[]
index = 0
while len(stack):
current = stack[index]
index += 1
row = current[0]
col = current[1]
path = current[2]
data = m[row-1][col] + " "
strPos = row + β-β + col
if visited.indexOf(strPos) != 1:
continue
visited.append(strPos)
if not needExit and m[row][col] == β?β:
return path
if needExit and row == exitRow and col == exitCol:
return path + β!β
if m[row-1][col] == β.β:
stack.append([row-2, col, path + βSβ])
if m[row+1][col] == β.β:
stack.append([row+2, col, path + βNβ])
if m[row][col+1] == β.β:
stack.append([row, col + 2, path + βWβ])
if m[row][col-1] == β.β:
stack.append([row, col - 2, path + βEβ])

for p in range(len(path)):
moveDir(path[p])

def moveDir(direction):
newPosFunc = {
βNβ : north,
βSβ : south,
βEβ : east,
βWβ : west,
β!β : exit
}[direction]
newPos = newPosFunc()
hero.moveXY(newPos.x, newPos.y)
if direction == β!β:
inSearch = False
hero.row = newPos.row
hero.col = newPos.col

def east():
return {βxβ : coorConvert(hero.col - 2),
βyβ : coorConvert(hero.row),
βrowβ : hero.row, βcolβ : hero.col - 2}

def west():
return {βxβ : coorConvert(hero.col + 2),
βyβ : coorConvert(hero.row),
βrowβ : hero.row, βcolβ : hero.col + 2}

def south():
return {βxβ : coorConvert(hero.col),
βyβ : coorConvert(hero.row - 2),
βrowβ : hero.row - 2, βcolβ : hero.col}

def north():
return {βxβ : coorConvert(hero.col),
βyβ : coorConvert(hero.row + 2),
βrowβ : hero.row + 2, βcolβ : hero.col}

def exit():
return exitPosition

path = ββ
treasureFound = False

while inSearch:
maze = checkPaths(maze)
if hero.gold > 0:
treasureFound = True
inSearch = False
path = findPath(maze, treasureFound)
if not path:
pass
else:
for p in range(len(path)):
moveDir(path[p])

because i havent exactly played this lvl could you send me the link of it?

Hi, this is the link of the level.

https://reurl.cc/XE95GE

thanks well since i use a course subscription too i cant exactly help you other than try and debug the code soβ¦ @moonwatcher348 and @PeterPalov maybe you guys can help a bit?

the reason i cant is im stll saving too actually buy another subscription so so far i need some time before i can help you

IN the meantime ill be checking the code in a code editor

np this is the first time ive been useful to someone with code issues

really???
you look like an expertπ

nah i pretty much am bad at this i do more normal like real python more im better at that but ill try to do as much as possible to help