Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tic-tac-toe "nobody wins" when winning move fills the board #18

Closed
btheado opened this issue Jun 25, 2017 · 1 comment
Closed

Tic-tac-toe "nobody wins" when winning move fills the board #18

btheado opened this issue Jun 25, 2017 · 1 comment
Assignees
Labels

Comments

@btheado
Copy link

btheado commented Jun 25, 2017

As reported here: https://groups.google.com/d/msg/tiddlywiki/u46WpoCWac8/Fs8LN1iJAQAJ.

I am able to duplicate the issue. When the winning move fills the board, the winning cells are marked correctly, but the message says that nobody wins.

@joshuafcole joshuafcole self-assigned this Jun 27, 2017
@joshuafcole
Copy link
Contributor

joshuafcole commented Jun 27, 2017

This is actually a problem in the tic-tac-toe program. I attempted to rewrite it for clarity and made it handle this edge case incorrectly instead. The correct scoring block is:

search
  board = [#board size: N, not(winner)]
  (winner, winning-cell) =
  if cell = [#cell row player] N = gather/count[for: cell per: (row, player)] then (player, cell)
  else if cell = [#cell column player] N = gather/count[for: cell per: (column, player)] then (player, cell)
  else if cell = [#diagonal player] N = gather/count[for: cell per: player] then (player, cell)
  else if cell = [#anti-diagonal player] N = gather/count[for: cell per: player] then (player, cell)
  else if N * N = gather/count[for: [#cell]] then ("nobody", "nothing") // Cat's game!

commit
  board.winner := winner
  winning-cell += #winner

The gist of the problem: In the correct block we look groupwise at the rows, columns, and diagonals. In the incorrect block, we look at the row, column, and diagonals intersecting a particular cell. The former will just see the winning line(s) and stop there, The latter will continue looking through all the other cells of the board. Obviously on a full board not all cells contributed to the winning line(s), so those that did not will fall through to the cat's game clause. We'll restore this to the correct scoring block in the upcoming release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants