0

have a look at my game of fifteen code at: http://pastebin.com/gpZnkTPp it is showing errors in check50 , but i don't know what's wrong with my code check50 2015.fall.pset3.fifteen fifteen.c :) fifteen.c exists :) fifteen.c compiles :) init initializes 3x3 board correctly :) init initializes 4x4 board correctly :( 3x3 board, move blank up twice \ expected prompt for input, not exit code of 0 :( 3x3 board, move blank left twice \ expected prompt for input, not exit code of 0 :( 3x3 board, move blank left then right \ expected prompt for input, not exit code of 0 :( 3x3 board, move blank up then down \ expected prompt for input, not exit code of 0 :( 3x3 board, move up-up-left-down-down-left-up-up-right-down-down-right \ expected prompt for input, not exit code of 0 :( 3x3 board, from start try to move tile 2, 4, 5, 6, 7, 8 \ expected prompt for input, not exit code of 0 :( 3x3 board, move blank left (tile 1) then up (tile 4), then try to move tiles 1, 2, 6, 8 \ expected prompt for input, not exit code of 0 :( 3x3 board, move blank up (tile 3), then try tile 2 \ expected prompt for input, not exit code of 0 :| 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 https://sandbox.cs50.net/checks/3582bdb042c94f6cb1a886ae5495acfa

0

There are two serious issues. First, your draw function has serious issues, but they should be easy to resolve. Since I don't think you've seen them because of what follows, you should have the chance to work on it first. ;-)

The more serious problem is the won() function. If you look closely at it and trace it out, you would see that the flag variable gets set every time a board array element is checked in the loop. The net effect of this is that even if an earlier tile is out of position, it won't matter. If the last tile is the blank tile, it will result in flag being set to 0 and a win reported.

Instead, think about what needs to happen. As each board element is checked, once any tile is found to be incorrect, the won function can immediately return false. No further checking needs to be done. You should be able to take this info and make use of it in a slight redesign. ;-)

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

| improve this answer | |
  • i don't understand what's wrong with my draw function – Ketan Verma Oct 23 '16 at 16:28
  • Your draw function doesn't display the board correctly. It prints out all the numbers of the board as one line, with no spaces between the numbers, just one continuous string. This is a simple matter of refining your printf statements and adding appropriate line feeds. However, you can't work on that until you fix the won code (or simply replace the won code with a return false while you test the draw function.) – Cliff B Oct 23 '16 at 23:50

You must log in to answer this question.

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