MCPcopy Index your code
hub / github.com/aws-samples/eb-java-scorekeep / toInt

Method toInt

src/main/java/scorekeep/TicTacToe.java:77–86  ·  view source on GitHub ↗
(char[] state, char turn)

Source from the content-addressed store, hash-verified

75 * are '0'.
76 */
77 public static int toInt(char[] state, char turn) {
78 int out = 0;
79 int len = state.length;
80 for ( int i = 1; i <= len; i++ ){
81 if ( state[len-i] == turn) {
82 out += Math.pow( 2, i-1 );
83 }
84 }
85 return out;
86 }
87
88 /* Compare an integer game state against known winning states for tic tac
89 * toe. For example, X can win with three Xs on the bottom row:

Callers 3

gameplayTestMethod · 0.95
checkWinTestMethod · 0.95
moveMethod · 0.95

Calls

no outgoing calls

Tested by 2

gameplayTestMethod · 0.76
checkWinTestMethod · 0.76