diff --git a/src/dawn/games/tictactoe/TicTacToeLogic.hpp b/src/dawn/games/tictactoe/TicTacToeLogic.hpp index 4ebfe200..d3d8e78c 100644 --- a/src/dawn/games/tictactoe/TicTacToeLogic.hpp +++ b/src/dawn/games/tictactoe/TicTacToeLogic.hpp @@ -17,4 +17,9 @@ namespace Dawn { const std::map board, std::vector *winningCombo ); + + int32_t ticTacToeGetAiMove( + std::map board, + enum TicTacToeTileState player + ); } \ No newline at end of file diff --git a/src/dawntictactoe/components/TicTacToeGame.cpp b/src/dawntictactoe/components/TicTacToeGame.cpp index b326377f..8234cf28 100644 --- a/src/dawntictactoe/components/TicTacToeGame.cpp +++ b/src/dawntictactoe/components/TicTacToeGame.cpp @@ -10,7 +10,11 @@ using namespace Dawn; -TicTacToeGame::TicTacToeGame(SceneItem *item) : SceneItemComponent(item) {} +TicTacToeGame::TicTacToeGame(SceneItem *item) : + SceneItemComponent(item), + winner(TIC_TAC_TOE_EMPTY), + nextMove(TIC_TAC_TOE_NOUGHT) +{} void TicTacToeGame::onStart() { // Map tiles by tile number = tile @@ -21,8 +25,20 @@ void TicTacToeGame::onStart() { ++itTiles; } - // Listen + useEffect([&]{ + if(nextMove != TIC_TAC_TOE_CROSS) return; + std::cout << "AI Move" << std::endl; + }, nextMove); + + useEffect([&]{ + if(winner == TIC_TAC_TOE_NOUGHT) return; + std::cout << "Winner is " << winner << std::endl; + }, winner); + useEvent([&](float_t delta) { + // Only allow player input if it's their turn. + if(nextMove != TIC_TAC_TOE_NOUGHT) return; + // Get mouse in screen space. auto mouse = getGame()->inputManager.getAxis2D(INPUT_BIND_MOUSE_X, INPUT_BIND_MOUSE_Y); mouse *= 2.0f; @@ -75,6 +91,6 @@ void TicTacToeGame::onStart() { // Determine winner std::vector winningCombo; - auto winner = ticTacToeDetermineWinner(tileMap, &winningCombo); + winner = ticTacToeDetermineWinner(tileMap, &winningCombo); }, getScene()->eventSceneUpdate); } \ No newline at end of file diff --git a/src/dawntictactoe/components/TicTacToeGame.hpp b/src/dawntictactoe/components/TicTacToeGame.hpp index 29983eeb..bb627f06 100644 --- a/src/dawntictactoe/components/TicTacToeGame.hpp +++ b/src/dawntictactoe/components/TicTacToeGame.hpp @@ -11,8 +11,9 @@ namespace Dawn { class TicTacToeGame : public SceneItemComponent { public: + StateProperty winner; std::map tiles; - enum TicTacToeTileState nextMove = TIC_TAC_TOE_NOUGHT; + StateProperty nextMove; TicTacToeGame(SceneItem *item);