Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding and End point for AI moves #20

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions api/controllers/game/ai-move.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = async function (req, res) {
try {
const gameId = req.session.game;
const game = await gameService.findGame({ gameId });

if (!game) {
return res.status(404).json({ message: 'Game not found' });
}

if (!game.isVsAI) {
return res.status(400).json({ message: 'This game is not against an AI opponent' });
}

// Call the AI move logic
await aiMoveHelper.makeMove(game);

return res.status(200).json({ message: 'AI move made successfully' });
} catch (err) {
return res.status(500).json({ message: err.message });
}
};