witheve / eve-starter

Start here if you're new to Eve.
http://witheve.com
Apache License 2.0
30 stars 20 forks source link

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

Closed btheado closed 7 years ago

btheado commented 7 years ago

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 commented 7 years ago

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.