chkgk / otree_slider_puzzle

Two-player slider puzzle for oTree
MIT License
2 stars 1 forks source link

Program occasionally consider unsolved puzzles as solved #5

Closed yukitakahashi1 closed 4 years ago

yukitakahashi1 commented 4 years ago

Hi Christian, I'm sorry to ask you several questions, but as I tested the program, I found that it occasionally considered unsolved puzzles as solved (please see the attached screenshot). Do you have any idea why this occurs? The screenshot and the codes below are from the single-player version with history tracking, but I also encountered this behavior in the two-player version.

The following is the set of boards I used to get the screenshot and the screenshot is from the last board.

 let boards = [[
                [1, 2, 3],
                [4, 5, null],
                [7, 8, 6]
            ], [
                [1, 2, null],
                [4, 5, 3],
                [7, 8, 6]
            ], [
                [2, 5, 3],
                [1, 7, 6],
                [4, 8, null]
            ]
        ];

The following is the history list.

[[{"from":[2,2],"to":[1,2]}],
[{"from":[1,2],"to":[0,2]},{"from":[2,2],"to":[1,2]}],
[{"from":[1,2],"to":[2,2]},{"from":[1,1],"to":[1,2]},{"from":[0,1],"to":[1,1]},{"from":[0,0],"to":[0,1]},{"from":[1,0],"to":[0,0]},{"from":[1,1],"to":[1,0]},{"from":[1,0],"to":[1,1]},{"from":[2,0],"to":[1,0]},{"from":[2,1],"to":[2,0]},{"from":[2,2],"to":[2,1]}]]
Screen Shot 2020-10-01 at 18 18 14
chkgk commented 4 years ago

Hi Yuki,

Thanks for pointing this out. There is a mistake in the solved() function. The && in the condition in line 213 of Game.html should have been ||, i.e. "or" instead of "and".

The wrong condition reads:

if (r !== rows - 1  && c !== cols - 1) {

Correct would be:

if (r !== rows - 1 || c !== cols - 1) {

I have updated the code in the repository to fix the mistake. Sorry for the inconvenience!

yukitakahashi1 commented 4 years ago

I see, yes, it now works properly. Thanks a lot Christian!