svelte-tic-tac-toe icon indicating copy to clipboard operation
svelte-tic-tac-toe copied to clipboard

Winner evaluation

Open fkereki opened this issue 6 years ago • 5 comments

I believe the getWinner logic is wrong; see the attached screenshot. If a row/column is totally empty, it stops looking at the other rows/columns, and it misses wins. My suggestion would be:

function getWinner(board) {
    for (let i = 0; i < 3; i++) {
        if (board[i][0] && board[i][0] === board[i][1] && board[i][1] === board[i][2]) {
            return board[i][1];
        }
        if (board[0][i] && board[0][i] === board[1][i] && board[1][i] === board[2][i]) {
            return board[1][i];
        }
    }

    if (
        (board[0][0] && board[0][0] === board[1][1] && board[1][1] == board[2][2]) ||
        (board[0][2] && board[0][2] === board[1][1] && board[1][1] == board[2][0])
    ) {
        return board[1][1];
    }

    return null;
}

Screenshot_20190722_201034

fkereki avatar Jul 22 '19 23:07 fkereki

Sure. Do you want to make a pull request?

jesseskinner avatar Jul 23 '19 20:07 jesseskinner

A problem: it seems it won´t allow me to push code?

fkerekiglobant avatar Jul 24 '19 13:07 fkerekiglobant

I think you need to fork the repo and push to that, then create a pull request from that? Or did you do that?

jesseskinner avatar Jul 24 '19 16:07 jesseskinner

I forked the project; I´ll try the PR from there, but since I made many more changes, I doubt that will work out...

image

fkereki avatar Jul 24 '19 17:07 fkereki

Hi! I think you´ll have to do the PR on your own... sorry about that! I forked the project, and then went on to experiment with a store, writables, deriveds, etc., etc., so I´ve got plenty of changes.

Best regards, FK

On Wed, Jul 24, 2019 at 1:50 PM Jesse Skinner [email protected] wrote:

I think you need to fork the repo and push to that, then create a pull request from that? Or did you do that?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jesseskinner/svelte-tic-tac-toe/issues/2?email_source=notifications&email_token=AAS2RX2YRVW4UBNWGUSA2BLQBCB6DA5CNFSM4IF53VHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2W6FRQ#issuecomment-514712262, or mute the thread https://github.com/notifications/unsubscribe-auth/AAS2RX64FZXC4CNJ6EHXH23QBCB6DANCNFSM4IF53VHA .

fkereki avatar Jul 26 '19 14:07 fkereki