#๐Ÿ”’ Help in converting Tetris grid (2D array of tuples)

127 messages ยท Page 1 of 1 (latest)

sand pantherBOT
#

@fervent bronze

Python help channel opened

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.

fervent bronze
#

I'm unable to paste code.

#

Because it converts it to .txt file

tiny skiff
#

Sounds like you're draggin/dropping a file? Try copy/paste of the file's contents.

#

!code

sand pantherBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

modest spire
#

!paste

sand pantherBOT
#
Pasting large amounts of 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.

modest spire
#

and what r u trying to do ? @fervent bronze

fervent bronze
#

just wait

#

!paste

sand pantherBOT
#
Pasting large amounts of 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.

fervent bronze
#

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

modest spire
#

hmmm

fervent bronze
#

you got the idea?

modest spire
#

can u send what u need converted to what?

#

only the inputs and outputs? samples

#

maybe we could help

#

@fervent bronze

fervent bronze
#

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.

modest spire
#

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)
sand pantherBOT
fervent bronze
#

in the sense

#

yeah

modest spire
#

!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)
fervent bronze
#

for my pygame project for Year 12

sand pantherBOT
fervent bronze
#

not really the output I wanted

modest spire
fervent bronze
#

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

modest spire
#

and what is inside this tuple?

fervent bronze
#

output grid = 2D array (20 rows 10 columns) of 1s and 0s

modest spire
#

ah

fervent bronze
#

the tuple is like an RGB format

#

like (0,0,0) is black

modest spire
#

oh its a color

fervent bronze
#

(255, 255,0) is yellow

modest spire
#

okay

fervent bronze
#

something like that

modest spire
#

yeah yeahh

fervent bronze
#

now?

modest spire
#

okay

modest spire
#

what color is a 1 or a 0?

fervent bronze
#

that's what

#

if at that moment a block is black, at that index, the output array should have 0

#

eg.

modest spire
#

so only if its black should it be 0?

#

anything else is a 1?

#

that's easy then

fervent bronze
#

[[(0,0,0), (0,5,255)], [(1,2,3),(8,6,5)]] -> [[0,1],[1,1]]

#

yeah but

#

it doesn't work

modest spire
#

i dont get that

fervent bronze
#

I tried easy approach

modest spire
#

why is the output a list, second, why is it 0,1 ?

fervent bronze
#

that's what

#

the (0,0,0) in input list is 0 at the same index in ouput list

modest spire
#

ahh okay look at this then

fervent bronze
#

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

modest spire
#

!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)
sand pantherBOT
modest spire
#

im on my phone rn, sorry it took so long lol

fervent bronze
#

no worries

modest spire
fervent bronze
#

no

#

the Tetris has a set grid

#

each time tetris pieece moves, it updates grid

modest spire
#

ahhh tetris

fervent bronze
#

that's what I meant

#

look at the title

modest spire
#

why do u need tuples for colors? why not

fervent bronze
#

pygame

modest spire
#

use 0-4 for red green cyan blue

#

and THEN get the color?

fervent bronze
#

it interprets it as rgb

#

check the actual code

#

you'll ssee what I mean

modest spire
#

which lines should i look at

#

382?

fervent bronze
#

if you could

#

look at everything

modest spire
#

class ai?

fervent bronze
#

from drawing the grid

#

to shape format when it's locked

#

at bottom of grid

#

that's what

modest spire
fervent bronze
#

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?

modest spire
#

yes

modest spire
#

is this code what u needed?

fervent bronze
#

yep

#

bt dubs, your previous code worked i think

modest spire
#

aight I'm glad i could help!

#

lmk how it goes and how you finish it up

fervent bronze
#

ok

#

thx

modest spire
#

yw

sand pantherBOT
#
Python help channel closed

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.