Skip to content

Commit 16836d5

Browse files
committed
Function to turn char to int representation
1 parent 5a2a7ee commit 16836d5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

main-module/src/main/java/com/diffblue/javatest/TicTacToe.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,23 @@ byte checkTicTacToePosition(byte[] a) {
7878
// Neither player has won yet
7979
return 0;
8080
}
81+
82+
/**
83+
* Convert char representaion of board state to byte representation.
84+
*/
85+
static byte ticTacToeCharToByte(char c) {
86+
switch (c) {
87+
case 'X':
88+
case 'x':
89+
return 1;
90+
case 'O':
91+
case 'o':
92+
case '0':
93+
return 2;
94+
case ' ':
95+
return 0;
96+
default:
97+
throw new Error("Character " + c + " not recognized");
98+
}
99+
}
81100
}

0 commit comments

Comments
 (0)