what's this test output mean python

I'm working on an open source project. The project's goal is to create a game of tetris. There are a series of tests involved when you are building the game. The first test ensures the computer can find your code. basically just saving a file in the right place. I pass it every time. Then the second test is to print the game board. This is the p command code to pass the second test:

   def test2():
        while True:
         qp = raw_input('')
         if qp=='p':

          for i in range(0,22):
             for j in range(0,10):
           return exit()


It prints the output, a matrix of dots. 10 x 22 output of dots that resembles a tetris layout. The code then goes to step 3 which is to use the 'g command' to populate some internal representation into the matrix. It also says "The input format should be identical to the output produced by the 'p' command". When it says input format does it mean the code? I tried a variety of codes that culminated in me combining the two arguments into a while statement. Specifically this while statement:

  def test3():
        while True:
            qp = raw_input('')
            if qp == 'p' or qp == 'g':

                for i in range(0, 22):
                    for j in range(0, 10):

                return exit()


Obviously when I run the code in my PyCharm debugger, it spits out a blank 10x22 matrix regardless if I type 'p' or 'g'. I'm guessing that's to be expected since they use the same while loop. But when I run it in my mac's terminal it does not produce a blank matrix. It produces a horribly spaced and distorted output (https://imgur.com/a/ryNsN) of the expected output (which can be seen on the link at the bottom). So I know my code is wrong but I think it's because I misunderstand the prompt while awaiting the results for test 3. What does the program mean when it says:

 The 'g' command instructs learntris to read 22 lines
of text from the standard input stream, and use the
characters on these lines to populate some internal
representation of the matrix.

The letter 'g' is a mnemonic for the word 'given', as
in: "given the following matrix...."

The input format should be identical to the output
produced by the 'p' command.

The letters used in the representation correspond to
the set of colors used for blocks in the game:

. = empty (black)     b = blue         c = cyan
g = green             m = magenta      o = orange
r = red               y = yellow

You can learn more about the expected output for test 3 here: https://github.com/LearnProgramming/learntris/blob/master/testplan.org#establish-a-way-to-set-the-entire-matrix-g

So can anyone help me figure out what "the input format should be identical to the output produced by the 'p' command" means so I can solve this code and move onto the next step?

1 answer

  • answered 2018-03-13 20:39 Prune

    Very simply, the output of the p command becomes the input to the g command; this is a straightforward data flow. Do not combine the code for the two commands. Code the p command first, and check the output by eye. Then, code the g command -- and the first step of that is to make it read the file that the p command produced.