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

Thank you for your help!!! :joy:

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

@MarmiteOnToast could you help please?

It seems that the problem is here:

Hulloo
I’ll do my best to assist Tsaibow and yourself with any issues you encounter on CodeCombat - Coding games to learn Python and JavaScript
(I apologise for the late response)

finally ive never done this so i appreciete

ok so it means it cant use the non object type i guess? in some way

yes but i really dont know how to solve it