unified code for cumputing next player
This commit is contained in:
parent
fedfbb3dbc
commit
5c334577bf
|
|
@ -25,6 +25,18 @@ class Util {
|
||||||
emptyBoardClassic,
|
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 stateText(TTCState state) => state.name.toUpperCase();
|
||||||
static String cellAddress(int index) =>
|
static String cellAddress(int index) =>
|
||||||
"${index % 3}, ${(index / 3).floor()}";
|
"${index % 3}, ${(index / 3).floor()}";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue