Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
import curses
from curses import wrapper
import queue
import time
maze = [
    ['#','#','#','#','#','0','#','#','#'],
    ['#',' ',' ',' ',' ',' ',' ',' ','#'],
    ['#',' ','#','#',' ','#','#',' ','#'],
    ['#',' ','#',' ',' ',' ','#',' ','#'],
    ['#',' ', '#',' ','#',' ','#',' ','#'],
    ['#',' ', '#',' ','#',' ','#',' ','#'],
    ['#',' ','#',' ','#',' ','#','#','#'],
    ['#',' ',' ',' ',' ',' ',' ',' ','#'],
    ['#','#','#','#','#','#','#','X','#',]
]

def print_maize(maze,stdscr,path=[]):
    blue = curses.color_pair(1)
    red =  curses.color_pair(2)

    for i,row in enumerate(maze):
        for j,value in enumerate(row):
            stdscr.addstr(i,j,value)

def main(stdscr):
    curses.init_pair(1,curses.COLOR_BLUE,curses.COLOR_BLACK)
    blue_and_black = curses.color_pair(1)
    stdscr.clear()
    print_maize(maze,stdscr)
    stdscr.refresh()
    stdscr.getch()

wrapper(main)



error code
<pre>  File "c:\Python\New python learning.py\new proj.py", line 24, in print_maize
    stdscr.addstr(i,j,value)
_curses.error: addwstr() returned ERR


What I have tried:

trying to create a maze game but not getting the output at this stage ,
error code as mentioned above



I am not able to understand how to proceed ahead
Posted
Updated 4-Jul-23 18:17pm
Comments
Richard MacCutchan 24-Nov-22 7:32am    
Have you called initscr to initialise the curses module?
I see that the call to wrapper does that for you.
ALEXANDER ABRAHAM 2022 24-Nov-22 8:00am    
No how do you call that can you help? the tutorial person when he runs this code he gets the output, even this code also doesn't work COLOR_BLUE,curses.COLOR_BLACK in the code
Richard MacCutchan 24-Nov-22 8:04am    
Then as suggested by OriginalGriff below, ask the person who wrote the tutorial. The only information that we have is the code you have posted. See also the resulting output I got in my Solution below.

Go back to where you got the tutorial from, and ask there: we have no access to the code or any idea what it should look like.

THough a better solution would be to stop watching tutorials, and read a book on Python instead: they cover the subject much better than video tutorials do, especially if you found it on YouTube ...
 
Share this answer
 
I just ran that code and the result is:
#####0###
#       #
# ## ## #
# #   # #
# # # # #
# # # # #
# # # ###
#       #
#######X#

I suspect the error message is the clue, in that it appears to think that your characters are in Unicode rather than ASCII. But I have no idea why that may be. You should check the tutorial again to see if there is any mention of this.
 
Share this answer
 
v3
Comments
ALEXANDER ABRAHAM 2022 24-Nov-22 8:04am    
no such mention in the tutorial, tutorial link https://www.youtube.com/watch?v=txKBWtvV99Y&t=331s
in the first 10minutes he mentions.
hows that possible your getting the result and not me?
it is related to extension, even i have downloaded python3 -m pip install windows-curses extension also
Richard MacCutchan 24-Nov-22 8:07am    
Sorry, I only downloaded the curses library to test your code. But I have no experience of it, so cannot offer any suggestions.
ALEXANDER ABRAHAM 2022 24-Nov-22 8:08am    
ok, do you know any better sites on internet to learn free python projects with explanation
Richard MacCutchan 24-Nov-22 8:13am    
I have a better idea, go to The Python Tutorial — Python 3.10.8 documentation[^] and learn the language properly. Once you understand it you will find samples much easier to work with.
Hi @Alexander Abraham 2022,

Not sure if you were finally able to proceed beyond this error. I'm watching the same tutorial and also got the exact same error as you. I saw your question when I googled the error - so cool to see you've been through this just a few months ago in November.

Anyway, I'm assuming you were running this on Pycharm 2023.x - the trick which worked for me is to drag-up the run window up so it is big enough for the maze to print. I made my mycharm window larger and the maze printed just like in Tim's tutorial.

How's your python journey so far? Have you found other practice projects?
 
Share this answer
 
v2
Quote:
How do I move forward for maze game as I am watching though tutorial

May be not your error, but:
Python
maze = [
    ['#','#','#','#','#','0','#','#','#'],
    ['#',' ',' ',' ',' ',' ',' ',' ','#'],
    ['#',' ','#','#',' ','#','#',' ','#'],
    ['#',' ','#',' ',' ',' ','#',' ','#'],
    ['#',' ', '#',' ','#',' ','#',' ','#'],
    ['#',' ', '#',' ','#',' ','#',' ','#'],
    ['#',' ','#',' ','#',' ','#','#','#'],
    ['#',' ',' ',' ',' ',' ',' ',' ','#'],
    ['#','#','#','#','#','#','#','X','#',]
]
#                                       ^ remove the comma here

This may not have great impact with python, but other languages don't like it.
Another good habit is to not mix writing rules. Commas should be always followed with a space or never.
Python
maze = [
    ['#','#','#','#','#','0','#','#','#'],
    ['#',' ',' ',' ',' ',' ',' ',' ','#'],
    ['#',' ','#','#',' ','#','#',' ','#'],
    ['#',' ','#',' ',' ',' ','#',' ','#'],
    ['#',' ','#',' ','#',' ','#',' ','#'],
    ['#',' ','#',' ','#',' ','#',' ','#'],
    ['#',' ','#',' ','#',' ','#','#','#'],
    ['#',' ',' ',' ',' ',' ',' ',' ','#'],
    ['#','#','#','#','#','#','#','X','#',]
]

This way, it is more obvious that something os off in last line of maze.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900