#๐ Help in converting Tetris grid (2D array of tuples)
127 messages ยท Page 1 of 1 (latest)
@fervent bronze
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Sounds like you're draggin/dropping a file? Try copy/paste of the file's contents.
!code
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
and what r u trying to do ? @fervent bronze
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
I want to convert grid at eack tick
2D array of tuples -> 2D array of 1s and 0s
for my AI to interpret
I'm not using CNN
now I just need help
for that
hmmm
you got the idea?
can u send what u need converted to what?
only the inputs and outputs? samples
maybe we could help
@fervent bronze
This is the input grid at a particular tick: https://paste.pythondiscord.com/DMLA
ok?
This is what output looks like:
[[0, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [0, 2, 1, 2, 2, 2, 2, 2, 2, 2], [1, 2, 2, 0, 2, 2, 2, 2, 2, 2]]
I want the placeholder 2's gone
not only that, all the (0,0,0) tuples must turn into 0s. The rest should be 1.
wait this is all 2s
oh ok
do u know how to use collection expressions?
!e
from pprint import pprint
mat = [
[1, 2, 3],
[4, 5, 6],
]
mat = [
j
for i in mat
for j in i
]
pprint(mat)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
[1, 2, 3, 4, 5, 6]
!e
from pprint import pprint
mat = [[0, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [0, 2, 1, 2, 2, 2, 2, 2, 2, 2], [1, 2, 2, 0, 2, 2, 2, 2, 2, 2]]
mat = [
0 if j == 2 else 1
for i in mat
for j in i
]
pprint(mat)
for my pygame project for Year 12
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | [1,
002 | 0,
003 | 0,
004 | 0,
005 | 0,
006 | 0,
007 | 0,
008 | 0,
009 | 0,
010 | 0,
... (truncated - too many lines)
Full output: https://paste.pythondiscord.com/3LEFBLNB4O7K32N4UNQMOH3C7Q
not really the output I wanted
is this what u needed?
hmm, what kinda output do u want?
My original goal was to take a list of tuples from "grid" and then spit out numbers instead
grid = 2D array (20 rows 10 columns) of tuples
this is how u access them, and rebuild a collection
and what is inside this tuple?
output grid = 2D array (20 rows 10 columns) of 1s and 0s
ah
oh its a color
(255, 255,0) is yellow
okay
something like that
yeah yeahh
now?
okay
and how do u determine
what color is a 1 or a 0?
that's what
if at that moment a block is black, at that index, the output array should have 0
eg.
[[(0,0,0), (0,5,255)], [(1,2,3),(8,6,5)]] -> [[0,1],[1,1]]
yeah but
it doesn't work
i dont get that
I tried easy approach
why is the output a list, second, why is it 0,1 ?
ahh okay look at this then
the (0,5,255) in input list is 1 at same index in output list
however\
i'm thinkg of doing something like:
if current_time - last time = 1 tick, do something
!e
from pprint import pprint
mat = [
[(0,0,0), (0,5,255)],
[(1,2,3),(8,6,5)]
]
mat = [
[0 if i == (0, 0, 0) else 1 for i in row]
for row in mat]
pprint(mat)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
[[0, 1], [1, 1]]
im on my phone rn, sorry it took so long lol
no worries
i dont understand, do u manually draw pixels?
ahhh tetris
why do u need tuples for colors? why not
pygame
class ai?
from drawing the grid
to shape format when it's locked
at bottom of grid
that's what
I'm on my phone, i cant really... make sense of it all, the picture is too big to see in a reasonable time frame
ok
but I need to be able to take the current grid position at each tick
the grid is a 2D array of tuples
with rgb
all right? you with me so far?
yes
and convert to 1s and 0s
is this code what u needed?
yw
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.