u/TheEyebal

How do I position the player to be positioned on the matrix

matrix_data = [[1, 1, 1, 1, 1, 1],
                [1, 0, 0, 0, 0, 1],
                [1, 0, 0, 0, 0, 1],
                [1, 0, 0, 0, 0, 1],
                [1, 1, 1, 1, 1, 1]]

I have a matrix data in pygame and in my programming I am already iterating to draw the squares to resemble the matrices but how would I have the player align with the data and move along the board?

The concept is like a board game.

Right now I am looking at checkers and chess programs to see how those games are programmed and how the player moves around the board.

Resources and advice on this topic would be very appreciated

reddit.com
u/TheEyebal — 7 days ago

How do I run pygbag?

I have tried to run pygbag, I followed the documentation, asked chatgpt, went on Youtube, asked reddit and for some reason I cannot see my gameplay.

It is running but I only see the directory listing or computer logs or 404 Error.

What can I do or is there an alternative?

I am running this through a linux virtual machine

reddit.com
u/TheEyebal — 13 days ago
▲ 5 r/pygame

How do I run pygbag?

I have tried to run pygbag, I followed the documentation, asked chatgpt, went on Youtube, asked reddit and for some reason I cannot see my gameplay.

It is running but I only see the directory listing or computer logs.

What can I do and is there an alternative.

I am running this through a linux virtual machine

reddit.com
u/TheEyebal — 13 days ago
▲ 52 r/vim

I have a basic understanding of vim, like getting around but I want to know is it possible to delete a specific word in a specific range

Example: From line 3 -7 delete the word "Everyday." where it appears within that range

reddit.com
u/TheEyebal — 15 days ago

Right now I am debugging, and. was able to get my program to do what I want, but I wanted to know why is it when I had my range from (1, 43) did it exclude the last list but when I did range(43) it gives me the whole thing.

I want my program to iterate from 1 - 42 (42 is included) and add every time there is a length of 7.

Why does the computer do that?

Here are snippets of my code

# This is inside main function
days = {months[0]: 31, months[1]: 28, months[2]: 31, 
        months[3]: 30, months[4]: 31, 
        months[5]: 30, months[6]: 31,
        months[7]: 31, months[8]: 30, 
        months[9]: 31, months[10]: 30, months[11]: 31}

def incrementDays(days):
        numStore = []
        dayList = []
        weekList = []

        for i in range(1, 43):
                # i += 1 
                if len(dayList) == 7:
                        numStore.append(dayList)
                        dayList = []

                if i > dayDisplay:
                        i = ""

                dayList.append(i)

        for i in range(0, len(numStore)):
                weeks = {"MON": numStore[i][0], "TUE": numStore[i][1],
                "WED": numStore[i][2], "THU": numStore[i][3],
                "FRI": numStore[i][4], 
                "SAT": numStore[i][5], "SUN": numStore[i][6]}

                weekList.append(weeks)

        print(f"{numStore}\n")

        return weekList

OUTPUT: [[1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14], [15, 16, 17, 18, 19, 20, 21], [22, 23, 24, 25, 26, 27, 28], [29, 30, 31, '', '', '', '']]

CORRECT VERSION

def incrementDays(days):
        numStore = []
        dayList = []
        weekList = []

        for i in range(43):
                # i += 1 
                if len(dayList) == 7:
                        numStore.append(dayList)
                        dayList = []

                if i > dayDisplay:
                        i = ""

                dayList.append(i)

        for i in range(0, len(numStore)):
                weeks = {"MON": numStore[i][0], "TUE": numStore[i][1],
                "WED": numStore[i][2], "THU": numStore[i][3],
                "FRI": numStore[i][4], 
                "SAT": numStore[i][5], "SUN": numStore[i][6]}

                weekList.append(weeks)

        print(f"{numStore}\n")

        return weekList

OUTPUT: [[0, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12, 13], [14, 15, 16, 17, 18, 19, 20], [21, 22, 23, 24, 25, 26, 27], [28, 29, 30, 31, '', '', ''], ['', '', '', '', '', '', '']]

This is not the full code and it is just rewritten to show the context of my question.

UPDATE
After reading the comments below, I was able to figure out why it was not displaying the full 42 indexes

I only changed the range stopping point

def incrementDays(days):
        numStore = []
        dayList = []
        weekList = []

        for i in range(1, 44):
                # i += 1 
                if len(dayList) == 7:
                        numStore.append(dayList)
                        dayList = []

                if i > dayDisplay:
                        i = ""

                dayList.append(i)

        for i in range(0, len(numStore)):
                weeks = {"MON": numStore[i][0], "TUE": numStore[i][1],
                "WED": numStore[i][2], "THU": numStore[i][3],
                "FRI": numStore[i][4], 
                "SAT": numStore[i][5], "SUN": numStore[i][6]}

                weekList.append(weeks)
                
        print(f"{numStore}\n")

        return weekList

OUTPUT: [[1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14], [15, 16, 17, 18, 19, 20, 21], [22, 23, 24, 25, 26, 27, 28], [29, 30, 31, '', '', '', ''], ['', '', '', '', '', '', '']]
reddit.com
u/TheEyebal — 15 days ago

weeks = {}
def test(weeks):
    for i in range(0,5):
        weeks = {"MON": numStore[i][0], "TUE": numStore[i][1],
        "WED": numStore[i][2], "THU": numStore[i][3],
        "FRI": numStore[i][4], "SAT": numStore[i][5], 
        "SUN": numStore[i][6]}

    return weeks
    
print(test(weeks))

The program only displays either the first 7 (1, 2, 3, 4, 5, 6, 7) if I return inside the loop or the last 7 (29, 30, 31, "", "", "", "")

how do I return all values (1 - 31)?

The Output should be like this

{'MON': 1, 'TUE': 2, 'WED': 3, 'THU': 4, 'FRI': 5, 'SAT': 6, 'SUN': 7}
{'MON': 8, 'TUE': 9, 'WED': 10, 'THU': 11, 'FRI': 12, 'SAT': 13, 'SUN': 14}
{'MON': 15, 'TUE': 16, 'WED': 17, 'THU': 18, 'FRI': 19, 'SAT': 20, 'SUN': 21}
{'MON': 22, 'TUE': 23, 'WED': 24, 'THU': 25, 'FRI': 26, 'SAT': 27, 'SUN': 28}
{'MON': 29, 'TUE': 30, 'WED': 31, 'THU': '', 'FRI': '', 'SAT': '', 'SUN': ''}

SOLUTION

Thank you to those who commented. I took y'all advice and added an empty list for store the dictionary to get all the values

numStore = []
dayList = []

weekList = []

for i in range(1, 42):
    if len(dayList) == 7:
        numStore.append(dayList)
        dayList = []
        
    if i >= 32:
        i = ""
        
    dayList.append(i)

for i in range(0,5):
    weeks = {"MON": numStore[i][0], "TUE": numStore[i][1],
    "WED": numStore[i][2], "THU": numStore[i][3],
    "FRI": numStore[i][4], "SAT": numStore[i][5], 
    "SUN": numStore[i][6]}
      
    weekList.append(weeks)
    
print(weekList)
reddit.com
u/TheEyebal — 16 days ago

My Plan
Start with an empty array [dayList] with the max length being 7. Once the array reaches the max length, return the data from dayList to the second list [numStore] and delete the data from the array [dayList] and repeat until the the second list [numStore] reaches a length of 6 than print.

Here is what I got so far

numStore = []
dayList = []

for i in range(1, 32):
    dayList.append(i)
    
    if len(dayList) == 7:
        numStore.append(dayList)
        # dayList.clear()
        
        if len(numStore) == 6:
            break
        
print(numStore)

What is happening

Only creating one list with dayList.clear commented out or only outputting the last 2 elements with dayList.clear()

What output should look like

numStore = [[1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14],...[25, 26, 27, 28, 29, 30, 31]]
dayList will be the list inside with numbers

--SOLVED--

numStore = []
dayList = []

for i in range(1, 43):
    
    if len(dayList) == 7:
        numStore.append(dayList)
        dayList = []
        
    if i >= 32:
        i = ""
    
    dayList.append(i)
        
print(numStore)
reddit.com
u/TheEyebal — 18 days ago

I mostly use pygame but i've been dabbling in c++ learning fundamentals and I am itching to do raycasting in C++.

I was reading the https://lodev.org/cgtutor/raycasting.html and it explains in lower level. I know there are python resources but what should I do?

I feel like if I jump into a low level language I will burnout and drop it which I do not want to do.

What is your opinion on this subject?

reddit.com
u/TheEyebal — 20 days ago

I am making a calendar in the CLI and I am stuck on adding the dates properly. How do I add it properly in my program

yearPick = input("Enter a year: ").lower()

wk = ["MON", "TUE", "WED", "THUR", "FRI", "SAT", "SUN"]

d = [1, 2, 3, 4, 5, 6, 7]

if len(yearPick) != 4:
    print("Invalid Input")
    sys.exit()

elif yearPick == "exit":
    sys.exit()

else:
    monthPick = int(input("Enter a month (1-12): "))

    if monthPick < 1 or monthPick > 12:
        print("Invalid Input")
        sys.exit()
    else:

        currentTime = datetime.datetime(int(yearPick), monthPick, 1)

        YEAR = currentTime.year
        MONTH = currentTime.strftime('%b')
        WEEK = currentTime.strftime('%w')
        DAY = currentTime.strftime('%d')

        title = "My CLI Calandar"

table = f"""
                                                        {title}

                                {MONTH} {YEAR}
                                
                                {wk[0]} {wk[1]} {wk[2]} {wk[3]} {wk[4]} {wk[5]} {wk[6]}
                                _________________________________________________________
                                |{d[0]} |{d[1]} |{d[2]} |{d[3]} |{d[4]} |{d[5]} |{d[6]} |
                                |_______|_______|_______|_______|_______|_______|_______|       
                                |       |       |       |       |       |       |       |
                                |_______|_______|_______|_______|_______|_______|_______|
                                |       |       |       |       |       |       |       |
                                |_______|_______|_______|_______|_______|_______|_______|
                                |       |       |       |       |       |       |       |
                                |_______|_______|_______|_______|_______|_______|_______|
                                |       |       |       |       |       |       |       |
                                |_______|_______|_______|_______|_______|_______|_______|
                                |       |       |       |       |       |       |       |
                                |_______|_______|_______|_______|_______|_______|_______|

                        """

print(table)

I FIXED THE ISSUE

# weekday() gives 0=Monday, 6=Sunday
start_day = currentTime.weekday()

if monthPick == 12:
    next_month = datetime.datetime(int(yearPick) + 1, 1, 1)
else:   
    next_month = datetime.datetime(int(yearPick), monthPick + 1, 1)
days_in_month = (next_month - currentTime).days

# Create a flat list of dates in order, filling empty spots with 0
d = [0] * start_day  # empty spots before the first
for day in range(1, days_in_month + 1):
    d.append(day)

d_str = [f"{day:>2}" if day != 0 else "  " for day in d]

title = "My CLI Calendar"

print("Mo  Tu  We  Th  Fr  Sa  Su")
print("_____________________________")

for i in range(0, len(d_str), 7):
    row = d_str[i:i+7]
    # Fill missing cells if the last row has fewer than 7
    while len(row) < 7:
        row.append("  ")
    formatted_row = "".join(f" {cell}|" for cell in row)
    print(f"|{formatted_row}")
    print("|" + "___|"*7)
reddit.com
u/TheEyebal — 21 days ago