Skip to main content
fix counterexample
Source Link
  1. Computing a square-root is unnecessary; further, it only works when kBoardSize is a perfect square. Prefer

     const int kBoardLength = 3;
     const int kBoardSize = kBoardLength * kBoardLength;
    
  2. Your test for unreachability is not complete. You verify that O has made no more moves than X, but you really need to check that the winner made the last move. If X won, then should have numberOfX = numberOfO + 1; if O won then should have numberOfO = numberOfX. It should be clear how to add these checks to your CheckTicTacToeBoard method.

  3. A more overarching tension in this code is: should the board size really be a constant? The code is written so abstractly as to support any board size. But then the board size is fixed to a constant. I would choose one of the following directions to proceed in:

  • Commit to a board size of 9. In this case, I would recommend hard-coding the win conditions in winDetection. There are only 8 ways to win, so the resulting code would be a lot cleaner.

  • Allow arbitrary board sizes. In this case, you should accept a boardLength argument. Further, you will have to refine the notion of an UnreachableState. For example, in 45-by-45 tic tac toe, the following state is unreachable, but not detected by your code would return Xwins:

          x x x x x
          o o. o . o
          x x x x x
          o . o . o
          o o x o o
    
  1. Computing a square-root is unnecessary; further, it only works when kBoardSize is a perfect square. Prefer

     const int kBoardLength = 3;
     const int kBoardSize = kBoardLength * kBoardLength;
    
  2. Your test for unreachability is not complete. You verify that O has made no more moves than X, but you really need to check that the winner made the last move. If X won, then should have numberOfX = numberOfO + 1; if O won then should have numberOfO = numberOfX. It should be clear how to add these checks to your CheckTicTacToeBoard method.

  3. A more overarching tension in this code is: should the board size really be a constant? The code is written so abstractly as to support any board size. But then the board size is fixed to a constant. I would choose one of the following directions to proceed in:

  • Commit to a board size of 9. In this case, I would recommend hard-coding the win conditions in winDetection. There are only 8 ways to win, so the resulting code would be a lot cleaner.

  • Allow arbitrary board sizes. In this case, you should accept a boardLength argument. Further, you will have to refine the notion of an UnreachableState. For example, in 4-by-4 tic tac toe, the following state is unreachable, but not detected by your code:

          x x x x
          o o o o
          x x x x
          o o o o
    
  1. Computing a square-root is unnecessary; further, it only works when kBoardSize is a perfect square. Prefer

     const int kBoardLength = 3;
     const int kBoardSize = kBoardLength * kBoardLength;
    
  2. Your test for unreachability is not complete. You verify that O has made no more moves than X, but you really need to check that the winner made the last move. If X won, then should have numberOfX = numberOfO + 1; if O won then should have numberOfO = numberOfX. It should be clear how to add these checks to your CheckTicTacToeBoard method.

  3. A more overarching tension in this code is: should the board size really be a constant? The code is written so abstractly as to support any board size. But then the board size is fixed to a constant. I would choose one of the following directions to proceed in:

  • Commit to a board size of 9. In this case, I would recommend hard-coding the win conditions in winDetection. There are only 8 ways to win, so the resulting code would be a lot cleaner.

  • Allow arbitrary board sizes. In this case, you should accept a boardLength argument. Further, you will have to refine the notion of an UnreachableState. For example, in 5-by-5 tic tac toe, the following state is unreachable, your code would return Xwins:

          x x x x x
          o . o . o
          x x x x x
          o . o . o
          o o x o o
    
Formatting fixes
Source Link
Toby Speight
  • 81.7k
  • 14
  • 101
  • 308
  1. Computing a square-root is unnecessary; further, it only works when kBoardSize is a perfect square. Prefer

    Computing a square-root is unnecessary; further, it only works when kBoardSize is a perfect square. Prefer

     const int kBoardLength = 3;
     const int kBoardSize = kBoardLength * kBoardLength;
    
  2. Your test for unreachability is not complete. You verify that O has made no more moves than X, but you really need to check that the winner made the last move. If X won, then should have numberOfX = numberOfO + 1; if O won then should have numberOfO = numberOfX. It should be clear how to add these checks to your CheckTicTacToeBoard method.

  3. A more overarching tension in this code is: should the board size really be a constant? The code is written so abstractly as to support any board size. But then the board size is fixed to a constant. I would choose one of the following directions to proceed in:

const int kBoardLength = 3;
const int kBoardSize = kBoardLength * kBoardLength;
  1. Your test for unreachability is not complete. You verify that O has made no more moves than X, but you really need to check that the winner made the last move. If X won, then should have numberOfX = numberOfO + 1; if O won then should have numberOfO = numberOfX. It should be clear how to add these checks to your CheckTicTacToeBoard method.

  2. A more overarching tension is this code is: should the board size really be a constant? The code is written so abstractly as to support any board size. But then the board size is fixed to a constant. I would choose one of the following directions to proceed in:

    i. Commit to a board size of 9. In this case, I would recommend hard-coding the win conditions in winDetection. There are only 8 ways to win, so the resulting code would be a lot cleaner.

    ii. Allow arbitrary board sizes. In this case, you should accept a boardLength argument. Further, you will have to refine the notion of an UnreachableState. For example, in 4-by-4 tic tac toe, the following state is unreachable, but not detected by your code:

x x x x
o o o o
x x x x
o o o o
  • Commit to a board size of 9. In this case, I would recommend hard-coding the win conditions in winDetection. There are only 8 ways to win, so the resulting code would be a lot cleaner.

  • Allow arbitrary board sizes. In this case, you should accept a boardLength argument. Further, you will have to refine the notion of an UnreachableState. For example, in 4-by-4 tic tac toe, the following state is unreachable, but not detected by your code:

          x x x x
          o o o o
          x x x x
          o o o o
    
  1. Computing a square-root is unnecessary; further, it only works when kBoardSize is a perfect square. Prefer
const int kBoardLength = 3;
const int kBoardSize = kBoardLength * kBoardLength;
  1. Your test for unreachability is not complete. You verify that O has made no more moves than X, but you really need to check that the winner made the last move. If X won, then should have numberOfX = numberOfO + 1; if O won then should have numberOfO = numberOfX. It should be clear how to add these checks to your CheckTicTacToeBoard method.

  2. A more overarching tension is this code is: should the board size really be a constant? The code is written so abstractly as to support any board size. But then the board size is fixed to a constant. I would choose one of the following directions to proceed in:

    i. Commit to a board size of 9. In this case, I would recommend hard-coding the win conditions in winDetection. There are only 8 ways to win, so the resulting code would be a lot cleaner.

    ii. Allow arbitrary board sizes. In this case, you should accept a boardLength argument. Further, you will have to refine the notion of an UnreachableState. For example, in 4-by-4 tic tac toe, the following state is unreachable, but not detected by your code:

x x x x
o o o o
x x x x
o o o o
  1. Computing a square-root is unnecessary; further, it only works when kBoardSize is a perfect square. Prefer

     const int kBoardLength = 3;
     const int kBoardSize = kBoardLength * kBoardLength;
    
  2. Your test for unreachability is not complete. You verify that O has made no more moves than X, but you really need to check that the winner made the last move. If X won, then should have numberOfX = numberOfO + 1; if O won then should have numberOfO = numberOfX. It should be clear how to add these checks to your CheckTicTacToeBoard method.

  3. A more overarching tension in this code is: should the board size really be a constant? The code is written so abstractly as to support any board size. But then the board size is fixed to a constant. I would choose one of the following directions to proceed in:

  • Commit to a board size of 9. In this case, I would recommend hard-coding the win conditions in winDetection. There are only 8 ways to win, so the resulting code would be a lot cleaner.

  • Allow arbitrary board sizes. In this case, you should accept a boardLength argument. Further, you will have to refine the notion of an UnreachableState. For example, in 4-by-4 tic tac toe, the following state is unreachable, but not detected by your code:

          x x x x
          o o o o
          x x x x
          o o o o
    
added 365 characters in body
Source Link

Computing a square-root is unnecessary; further, it only works when kBoardSize is a perfect square. Prefer

  1. Computing a square-root is unnecessary; further, it only works when kBoardSize is a perfect square. Prefer
const int kBoardLength = 3;
const int kBoardSize = kBoardLength * kBoardLength;

A more overarching tension is this code is: should the board size really be a constant? The code is written so abstractly as to support any board size. But then the board size is fixed to a constant. I would choose one of the following directions to proceed in:

  1. Commit to a board size of 9. In this case, I would recommend hard-coding the win conditions in winDetection. There are only 8 ways to win, so the resulting code would be a lot cleaner.

  2. Allow arbitrary board sizes. In this case, you should accept a boardLength argument. Further, you will have to refine the notion of an UnreachableState. For example, in 4-by-4 tic tac toe, the following state is unreachable, but not detected by your code:

  1. Your test for unreachability is not complete. You verify that O has made no more moves than X, but you really need to check that the winner made the last move. If X won, then should have numberOfX = numberOfO + 1; if O won then should have numberOfO = numberOfX. It should be clear how to add these checks to your CheckTicTacToeBoard method.

  2. A more overarching tension is this code is: should the board size really be a constant? The code is written so abstractly as to support any board size. But then the board size is fixed to a constant. I would choose one of the following directions to proceed in:

    i. Commit to a board size of 9. In this case, I would recommend hard-coding the win conditions in winDetection. There are only 8 ways to win, so the resulting code would be a lot cleaner.

    ii. Allow arbitrary board sizes. In this case, you should accept a boardLength argument. Further, you will have to refine the notion of an UnreachableState. For example, in 4-by-4 tic tac toe, the following state is unreachable, but not detected by your code:

x x x x
o o o o
x x x x
o o o o

Computing a square-root is unnecessary; further, it only works when kBoardSize is a perfect square. Prefer

const int kBoardLength = 3;
const int kBoardSize = kBoardLength * kBoardLength;

A more overarching tension is this code is: should the board size really be a constant? The code is written so abstractly as to support any board size. But then the board size is fixed to a constant. I would choose one of the following directions to proceed in:

  1. Commit to a board size of 9. In this case, I would recommend hard-coding the win conditions in winDetection. There are only 8 ways to win, so the resulting code would be a lot cleaner.

  2. Allow arbitrary board sizes. In this case, you should accept a boardLength argument. Further, you will have to refine the notion of an UnreachableState. For example, in 4-by-4 tic tac toe, the following state is unreachable, but not detected by your code:

x x x x
o o o o
x x x x
o o o o
  1. Computing a square-root is unnecessary; further, it only works when kBoardSize is a perfect square. Prefer
const int kBoardLength = 3;
const int kBoardSize = kBoardLength * kBoardLength;
  1. Your test for unreachability is not complete. You verify that O has made no more moves than X, but you really need to check that the winner made the last move. If X won, then should have numberOfX = numberOfO + 1; if O won then should have numberOfO = numberOfX. It should be clear how to add these checks to your CheckTicTacToeBoard method.

  2. A more overarching tension is this code is: should the board size really be a constant? The code is written so abstractly as to support any board size. But then the board size is fixed to a constant. I would choose one of the following directions to proceed in:

    i. Commit to a board size of 9. In this case, I would recommend hard-coding the win conditions in winDetection. There are only 8 ways to win, so the resulting code would be a lot cleaner.

    ii. Allow arbitrary board sizes. In this case, you should accept a boardLength argument. Further, you will have to refine the notion of an UnreachableState. For example, in 4-by-4 tic tac toe, the following state is unreachable, but not detected by your code:

x x x x
o o o o
x x x x
o o o o
Source Link
Loading