From 5c334577bf751fe16fba4c01c6e4f35dc43f6139 Mon Sep 17 00:00:00 2001 From: Andrei Stoica Date: Mon, 30 Dec 2024 12:09:02 -0500 Subject: [PATCH] unified code for cumputing next player --- lib/util.dart | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/util.dart b/lib/util.dart index edaf5e1..aefa59d 100644 --- a/lib/util.dart +++ b/lib/util.dart @@ -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()}";