Skip to content

Instantly share code, notes, and snippets.

@BrianLitwin
Last active January 30, 2019 14:48
Show Gist options
  • Save BrianLitwin/2add9e58ff6c7f008637657dbbf2eb5c to your computer and use it in GitHub Desktop.
Save BrianLitwin/2add9e58ff6c7f008637657dbbf2eb5c to your computer and use it in GitHub Desktop.

https://codepen.io/gaearon/pen/gWWZgR?editors=0010

  1. Display the location for each move in the format (col, row) in the move history list.
function getColRow(i) {

    function col(i) {
      const one = new Set([0, 3, 6])
      const two = new Set([1, 4, 7])
      const three = new Set([2, 5, 8])
      if (one.has(i)) {
        return 1
      } else if (two.has(i)) {
        return 2
      } else if (three.has(i)) {
        return 3
      }
  }

  function row(i) {
      if (i <= 2) {
        return 1
      } else if (i <= 5) {
        return 2
      } else {
        return 3
      }
  }

  return "col: " + col(i) + "row: " + row(i)
}
  1. Bold the currently selected item in the move list.
  2. Rewrite Board to use two loops to make the squares instead of hardcoding them.
  3. Add a toggle button that lets you sort the moves in either ascending or descending order.
  4. When someone wins, highlight the three squares that caused the win.
  5. When no one wins, display a message about the result being a draw.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment