unified code for cumputing next player

This commit is contained in:
Andrei Stoica 2024-12-30 12:09:02 -05:00
parent fedfbb3dbc
commit 5c334577bf
1 changed files with 12 additions and 0 deletions

View File

@ -25,6 +25,18 @@ class Util {
emptyBoardClassic,
];
static TTCState nextTurn(TTCState currentPlayer,
{TTCState defaultState = TTCState.x}) {
switch (currentPlayer) {
case TTCState.x:
return TTCState.o;
case TTCState.o:
return TTCState.x;
default:
return defaultState;
}
}
static String stateText(TTCState state) => state.name.toUpperCase();
static String cellAddress(int index) =>
"${index % 3}, ${(index / 3).floor()}";