Why is this codes graphics not working?

So my code is a supposed to be a ascii playable version of tetris, I myself wrote maybe 50% with the other half coming from chatgpt but quality checked and rewrote to made sure it worked, neither chatgpt nor replit can find an error in it but it refuses to show ascii or any graphics at all within the console/terminal.

import curses
import time
import random

# Define the game settings
ROWS = 20
COLS = 10
BLOCK_TYPES = ["I", "J", "L", "O", "S", "T", "Z"]
BLOCK_SHAPES = {
    "I": ["####"],
    "J": ["#  ", "###"],
    "L": ["  #", "###"],
    "O": ["##", "##"],
    "S": [" ##", "## "],
    "T": [" # ", "###"],
    "Z": ["## ", " ##"]
}
BLOCK_COLORS = {
    "I": curses.COLOR_CYAN,
    "J": curses.COLOR_BLUE,
    "L": curses.COLOR_YELLOW,
    "O": curses.COLOR_MAGENTA,
    "S": curses.COLOR_GREEN,
    "T": curses.COLOR_RED,
    "Z": curses.COLOR_WHITE
}
SCORES = {
    1: 40,
    2: 100,
    3: 300,
    4: 1200
}

def create_block():
    """Create a new random block"""
    block_type = random.choice(BLOCK_TYPES)
    block_shape = BLOCK_SHAPES[block_type]
    block_color = BLOCK_COLORS[block_type]
    block_x = COLS // 2 - len(block_shape[0]) // 2
    block_y = 0
    return {
        "type": block_type,
        "shape": block_shape,
        "color": block_color,
        "x": block_x,
        "y": block_y
    }

def draw_block(screen, block):
    """Draw the block on the screen"""
    block_shape = block["shape"]
    block_color = block["color"]
    block_x = block["x"]
    block_y = block["y"]
    for i in range(len(block_shape)):
        for j in range(len(block_shape[i])):
            if block_shape[i][j] == "#":
                screen.addstr(block_y + i, block_x + j, "#", curses.color_pair(block_color))

def erase_block(screen, block):
    """Erase the block from the screen"""
    block_shape = block["shape"]
    block_x = block["x"]
    block_y = block["y"]
    for i in range(len(block_shape)):
        for j in range(len(block_shape[i])):
            if block_shape[i][j] == "#":
                screen.addstr(block_y + i, block_x + j, " ")

def move_block(block, dx, dy):
    """Move the block by dx and dy"""
    block["x"] += dx
    block["y"] += dy

def update_board(board, block):
    """Update the board with the current block"""
    block_shape = block["shape"]
    block_x = block["x"]
    block_y = block["y"]
    block_type = block["type"]
    for i in range(len(block_shape)):
        for j in range(len(block_shape[i])):
            if block_shape[i][j] == "#":
                x = block_x + j
                y = block_y + i
                board[y][x] = block_type

def check_rows(board):
    """Check if any rows are complete"""
    complete_rows = []
    for i in range(ROWS):
        if 0 not in board[i]:
            complete_rows.append(i)
    return complete_rows

def remove_rows(board, rows):
    """Remove the complete rows from the board"""
    for row in rows:
        for i in range(row, 0, -1):
            board[i] = board[i-1][:]
        board[0] = [0] * COLS
name = __name__

def check_collision(board, block):
    """Check if the block has collided with the board"""
    block_shape = block["shape"]
    block_x = block["x"]
    block_y = block["y"]
    for i in range(len(block_shape)):
        for j in range(len(block_shape[i])):
            if block_shape[i][j] == "#":
                x = block_x + j
                y = block_y + i
                if y >= ROWS or x < 0 or x >= COLS or board[y][x] != 0:
                    return True
    return False


def draw_board(screen, board):
    """Draw the board on the screen"""
    for i in range(ROWS):
        for j in range(COLS):
            if board[i][j] != 0:
                color = BLOCK_COLORS[board[i][j]]
                screen.addstr(i, j*2, " ", curses.color_pair(color) | curses.A_REVERSE)


def draw_score(screen, score):
    """Draw the score on the screen"""
    screen.addstr(ROWS+2, 0, "Score: {}".format(score), curses.color_pair(7))


if name == "main":
    curses.wrapper(main)

Hi @ChaseDuncan1 thanks for your question.

Can you share a link to your Repl please? It would be easier to see if there are any issues by looking at the code in a Repl.

However at first glance I cannot see a curses.initscr call which would be required. Take a look here for more info: Curses Programming in Python | DevDungeon

Absolutely, https://replit.com/@ChaseDuncan1/Tetris?v=1

Thanks @ChaseDuncan1 yeah, there is a lot wrong with this code. There are functions which aren’t being called, the curses screen isn’t being initialised, etc. I recommend looking at the beginner example programs on the site I shared earlier and then adapt your code using those beginner programs as a template.

Not sure if you are also using Ghostwriter but when I forked your program it got itself tied up in knots trying to resolve the issue. Have you built anything using Curses before that you can use as a reference here?

1 Like

apologies, but I have not had much experience with curses at all hence why I attempted to use the assistance of chatgpt but it clearly did not work

I will study some through the link to the course you provided and then hopefully retry this with success, thank you

1 Like

No worries, good luck with this!!

1 Like

It is good to look through things, although there are a lot of plain python mistakes, not related to curses, so a basic python tutorial might help.