Progress
This commit is contained in:
@ -17,4 +17,9 @@ namespace Dawn {
|
|||||||
const std::map<uint8_t, enum TicTacToeTileState> board,
|
const std::map<uint8_t, enum TicTacToeTileState> board,
|
||||||
std::vector<uint8_t> *winningCombo
|
std::vector<uint8_t> *winningCombo
|
||||||
);
|
);
|
||||||
|
|
||||||
|
int32_t ticTacToeGetAiMove(
|
||||||
|
std::map<uint8_t, enum TicTacToeTileState> board,
|
||||||
|
enum TicTacToeTileState player
|
||||||
|
);
|
||||||
}
|
}
|
@ -10,7 +10,11 @@
|
|||||||
|
|
||||||
using namespace Dawn;
|
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() {
|
void TicTacToeGame::onStart() {
|
||||||
// Map tiles by tile number = tile
|
// Map tiles by tile number = tile
|
||||||
@ -21,8 +25,20 @@ void TicTacToeGame::onStart() {
|
|||||||
++itTiles;
|
++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) {
|
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.
|
// Get mouse in screen space.
|
||||||
auto mouse = getGame()->inputManager.getAxis2D(INPUT_BIND_MOUSE_X, INPUT_BIND_MOUSE_Y);
|
auto mouse = getGame()->inputManager.getAxis2D(INPUT_BIND_MOUSE_X, INPUT_BIND_MOUSE_Y);
|
||||||
mouse *= 2.0f;
|
mouse *= 2.0f;
|
||||||
@ -75,6 +91,6 @@ void TicTacToeGame::onStart() {
|
|||||||
|
|
||||||
// Determine winner
|
// Determine winner
|
||||||
std::vector<uint8_t> winningCombo;
|
std::vector<uint8_t> winningCombo;
|
||||||
auto winner = ticTacToeDetermineWinner(tileMap, &winningCombo);
|
winner = ticTacToeDetermineWinner(tileMap, &winningCombo);
|
||||||
}, getScene()->eventSceneUpdate);
|
}, getScene()->eventSceneUpdate);
|
||||||
}
|
}
|
@ -11,8 +11,9 @@
|
|||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class TicTacToeGame : public SceneItemComponent {
|
class TicTacToeGame : public SceneItemComponent {
|
||||||
public:
|
public:
|
||||||
|
StateProperty<TicTacToeTileState> winner;
|
||||||
std::map<int32_t, TicTacToeTile*> tiles;
|
std::map<int32_t, TicTacToeTile*> tiles;
|
||||||
enum TicTacToeTileState nextMove = TIC_TAC_TOE_NOUGHT;
|
StateProperty<enum TicTacToeTileState> nextMove;
|
||||||
|
|
||||||
TicTacToeGame(SceneItem *item);
|
TicTacToeGame(SceneItem *item);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user