0

I have completed Game of Fifteen which works fine using txt inputs check, but if fails to pass check50. Here is the code: https://github.com/bmind12/CS50/blob/master/pset3/fifteen/fifteen.c

~/workspace/pset3/fifteen/ $ check50 2015.fall.pset3.fifteen fifteen.c
:) fifteen.c exists
:) fifteen.c compiles
:( init initializes 3x3 board correctly
   \ expected "8" character 1 of line 1, not "0":( init initializes 4x4 board correctly
   \ expected file to be of length 38, not 32
:| 3x3 board, move blank up twice
   \ can't check until a frown turns upside down
:| 3x3 board, move blank left twice
   \ can't check until a frown turns upside down
:| 3x3 board, move blank left then right
   \ can't check until a frown turns upside down
:| 3x3 board, move blank up then down
   \ can't check until a frown turns upside down
:| 3x3 board, move up-up-left-down-down-left-up-up-right-down-down-right
   \ can't check until a frown turns upside down
:| 3x3 board, from start try to move tile 2, 4, 5, 6, 7, 8
   \ can't check until a frown turns upside down
:| 3x3 board, move blank left (tile 1) then up (tile 4), then try to move tiles 1, 2, 6, 8
   \ can't check until a frown turns upside down
:| 3x3 board, move blank up (tile 3), then try tile 2
   \ can't check until a frown turns upside down
:| 3x3.txt wins the 3x3 board
   \ can't check until a frown turns upside down
:| 4x4.txt wins the 4x4 board
   \ can't check until a frown turns upside down

Want to mention that I don't use all the functions like init or draw to init and draw. As long as it is not possible to pass 2D array with game's schema.

1

Check50 depends on the log.txt file being processed correctly. The code for that was already created and correct in the distro file. That code depends on the board[][] array being populated by the existing code and your added code.

Unfortunately, you chose to create a separate array, brd[][] instead of using board[][]. From the instructions: "But we ask that you not alter the flow of logic in main itself so that we can automate some tests of your program once submitted. "

As a side note, I took a quick look at the code. While it may work (ignoring the problem noted above), the design shows a lack of understanding of why functions are created. If this were graded as part of the on-campus class, it would lose a fair amount of points because of it as part of the design review.

Functions are supposed to encapsulate an entire process in one place so that it can be reused by any other part of the code. A common process should not be split between the calling process and the function. Take a close look at how you implemented draw(). The draw() function should handle the entire task of drawing the game board. You have implemented it so that draw() only prints the individual tiles, while the rest of the logic that controls where and what to print is in main. All of that logic should be in draw(). Another example is init(). Its empty! All of the init code is in main. The intent of this pset was to implement each of the four functions in those functions, with minimal or no change to main(). Again, from the instructions: "But we ask that you not alter the flow of logic in main itself so that we can automate some tests of your program once submitted. " This is one of the hidden lessons in this class. In a team programming environment, different people work on different parts of code that have to work together later. Changing something (like main) that everyone depends on in writing their code would have disastrous effects when the team tries to piece everything together.

My recommendation is to go back and try again. First review main and understand how it works, and implement all of the incomplete functions without making changes in main.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • Thank you very much for a deep insight. I decided not to use functions because I have no idea how to pass 2D arrays and as I investigated it is not so straightforward. How could I pass it? May you advice some literature or a topic I may refer to? – Sergey Ryabov Aug 27 '16 at 5:29
  • This is why board[][] is declared as a global array variable. All functions within the program have direct access to it. Also, one of the main points of this lesson is to learn how to use functions. – Cliff B Aug 27 '16 at 5:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .