Skip to main content
turned pseudocode into real code
Source Link
Adam
  • 5.1k
  • 1
  • 29
  • 45

I'd use a decision table here:

GameState[][]GameState[,] decisionTable = new GameState[2][2];GameState[2,2];
decisionTable[0][0]decisionTable[0,0] = GameState.Ok;
decisionTable[0][1]decisionTable[0,1] = GameState.Stalemate;
decisionTable[1][0]decisionTable[1,0] = GameState.Check;
decisionTable[1][1]decisionTable[1,1] = GameState.Mate;
 
return decisionTable[decisionTable[Convert.ToInt32(intisCheck)isCheck][, Convert.ToInt32(intisStuck)isStuck];];

(It's just a pseudocode.)

From Code Complete 2nd Edition, Chapter 19: General Control Issues, page 431:

Use decision tables to replace complicated conditions

Sometimes you have a complicated test involving several variables. It can be helpful to use a decision table to perform the test rather than using ifs or cases. A decision-table lookup is easier to code initially, having only a couple of lines of code and no tricky control structures. This minimization of complexity minimizes the opportunity for mistakes. If your data changes, you can change a decision table without changing the code; you only need to update the contents of the data structure.

I'd use a decision table here:

GameState[][] decisionTable = new GameState[2][2];
decisionTable[0][0] = GameState.Ok;
decisionTable[0][1] = GameState.Stalemate;
decisionTable[1][0] = GameState.Check;
decisionTable[1][1] = GameState.Mate;
 
return decisionTable[(int)isCheck][(int)isStuck];

(It's just a pseudocode.)

From Code Complete 2nd Edition, Chapter 19: General Control Issues, page 431:

Use decision tables to replace complicated conditions

Sometimes you have a complicated test involving several variables. It can be helpful to use a decision table to perform the test rather than using ifs or cases. A decision-table lookup is easier to code initially, having only a couple of lines of code and no tricky control structures. This minimization of complexity minimizes the opportunity for mistakes. If your data changes, you can change a decision table without changing the code; you only need to update the contents of the data structure.

I'd use a decision table here:

GameState[,] decisionTable = new GameState[2,2];
decisionTable[0,0] = GameState.Ok;
decisionTable[0,1] = GameState.Stalemate;
decisionTable[1,0] = GameState.Check;
decisionTable[1,1] = GameState.Mate;
return decisionTable[Convert.ToInt32(isCheck), Convert.ToInt32(isStuck)];

From Code Complete 2nd Edition, Chapter 19: General Control Issues, page 431:

Use decision tables to replace complicated conditions

Sometimes you have a complicated test involving several variables. It can be helpful to use a decision table to perform the test rather than using ifs or cases. A decision-table lookup is easier to code initially, having only a couple of lines of code and no tricky control structures. This minimization of complexity minimizes the opportunity for mistakes. If your data changes, you can change a decision table without changing the code; you only need to update the contents of the data structure.

Source Link
palacsint
  • 29.9k
  • 9
  • 81
  • 156

I'd use a decision table here:

GameState[][] decisionTable = new GameState[2][2];
decisionTable[0][0] = GameState.Ok;
decisionTable[0][1] = GameState.Stalemate;
decisionTable[1][0] = GameState.Check;
decisionTable[1][1] = GameState.Mate;

return decisionTable[(int)isCheck][(int)isStuck];

(It's just a pseudocode.)

From Code Complete 2nd Edition, Chapter 19: General Control Issues, page 431:

Use decision tables to replace complicated conditions

Sometimes you have a complicated test involving several variables. It can be helpful to use a decision table to perform the test rather than using ifs or cases. A decision-table lookup is easier to code initially, having only a couple of lines of code and no tricky control structures. This minimization of complexity minimizes the opportunity for mistakes. If your data changes, you can change a decision table without changing the code; you only need to update the contents of the data structure.