1

by checking with check50. I got following error

:( 3x3 board, move blank up (tile 3), then try tile 2 \ expected "0" character 5 of line 10, not "2":) 3x3.txt wins the 3x3 board

Link:

https://sandbox.cs50.net/checks/cc00590ead9e428ea8d19110beadd25d

Can anybody tell what is wrong?

1

In my code when the problem was that

in 3 x 3 board when I was starting game with 3 then tile goes up and after that if you exchange with 2, it was exchanging which is not a permissible move one can understand from following

8|7|6

5|4|3 initial condition

2|1|_

after one move

8|7|6

5|4|_

2|1|3

2nd move(which is not permissible)

8|7|6

5|4|2

_|1|3

But with my code it was happening so this was the mistake.

3
  • Which is exactly what I said, invalid moves need to be rejected, which your code did not.
    – Blauelf
    Apr 6 '17 at 10:28
  • No didn't specified the mistake. You had written "In case of an illegal move, when empty tile and tile to move are not adjacent, do not swap and return true, but instead return false." And my code was working for all other cases except this.
    – Rahul
    Apr 6 '17 at 10:33
  • Your programme did not reject the invalid move in that case.
    – Blauelf
    Apr 6 '17 at 10:36
-1

The answer is in the code comments:

/**
 * If tile borders empty space, moves tile and returns true, else
 * returns false. 
 */

In case of an illegal move, when empty tile and tile to move are not adjacent, do not swap and return true, but instead return false.

2
  • if (tile == 32) { return false; } I tried this but it's still not working
    – Rahul
    Apr 4 '17 at 14:24
  • Without the code, I have no idea what that snippet means.
    – Blauelf
    Apr 4 '17 at 14:32

You must log in to answer this question.

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