🌿 Smart Garden Manager in C++ with Robotics, UI, Drones, and Sound "A Rainwater Conservation System for Tomorrow’s Farms"

Hey guys! This is going to be a very interesting project because we will be building a mini-game that many of us played in our childhood. Let's go!
This Tic-Tac-Toe program allows two players to play on a 3x3 grid. Players take turns marking cells with 'X' and 'O'. The game checks for a win, a draw, or if the players want to continue after each move. Players also have the option to reset or exit the game.
#include <iostream>
#include <vector>
using namespace std;
// Function prototypes
void displayBoard(const vector<vector<char>> &board);
bool checkWin(const vector<vector<char>> &board, char player);
bool checkDraw(const vector<vector<char>> &board);
void resetBoard(vector<vector<char>> &board);
int main() {
vector<vector<char>> board = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'}
};
char currentPlayer = 'X';
bool gameRunning = true;
cout << "Welcome to Tic-Tac-Toe!\n";
while (gameRunning) {
displayBoard(board);
int choice;
cout << "Player " << currentPlayer << ", enter your move (1-9): ";
cin >> choice;
bool validMove = false;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
if (board[i][j] == (choice + '0')) {
board[i][j] = currentPlayer;
validMove = true;
break;
}
}
if (validMove) break;
}
if (!validMove) {
cout << "Invalid move! Try again.\n";
continue;
}
if (checkWin(board, currentPlayer)) {
displayBoard(board);
cout << "Player " << currentPlayer << " wins! Congratulations!\n";
gameRunning = false;
} else if (checkDraw(board)) {
displayBoard(board);
cout << "It's a draw!\n";
gameRunning = false;
} else {
currentPlayer = (currentPlayer == 'X') ? 'O' : 'X';
}
if (!gameRunning) {
char playAgain;
cout << "Do you want to play again? (y/n): ";
cin >> playAgain;
if (playAgain == 'y' || playAgain == 'Y') {
resetBoard(board);
currentPlayer = 'X';
gameRunning = true;
} else {
cout << "Thank you for playing! Goodbye!\n";
}
}
}
return 0;
}
void displayBoard(const vector<vector<char>> &board) {
cout << "\nTic-Tac-Toe Board:\n";
for (const auto &row : board) {
for (const auto &cell : row) {
cout << " " << cell << " ";
}
cout << "\n---|---|---\n";
}
}
bool checkWin(const vector<vector<char>> &board, char player) {
for (int i = 0; i < 3; ++i) {
if ((board[i][0] == player && board[i][1] == player && board[i][2] == player) ||
(board[0][i] == player && board[1][i] == player && board[2][i] == player))
return true;
}
if ((board[0][0] == player && board[1][1] == player && board[2][2] == player) ||
(board[0][2] == player && board[1][1] == player && board[2][0] == player))
return true;
return false;
}
bool checkDraw(const vector<vector<char>> &board) {
for (const auto &row : board) {
for (const auto &cell : row) {
if (cell != 'X' && cell != 'O')
return false;
}
}
return true;
}
void resetBoard(vector<vector<char>> &board) {
char cellValue = '1';
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
board[i][j] = cellValue++;
}
}
cout << "Board reset. Let's play again!\n";
}
Tech companies developing AI often use Tic-Tac-Toe for testing algorithms. Google DeepMind applied such techniques while working on AI projects for games like Go and Chess.
Many mobile apps implement Tic-Tac-Toe using a client-server model, enabling real-time dual-player matches across devices. Networking deployment allows players from different locations to compete.
Coding camps and schools use Tic-Tac-Toe as a learning exercise for programming logic, game theory, and AI development. Students also use it to practice algorithms.
In the 1950s, IBM developed AI programs for Tic-Tac-Toe, marking a foundational step in AI. The game was used to test how computers make decisions under constraints.
AI researchers applied reinforcement learning to Tic-Tac-Toe. This concept extended to more complex games, contributing to breakthroughs like AlphaGo.
Researchers used Tic-Tac-Toe to teach quantum computing principles. The quantum version allowed players to make moves in superposition, introducing unique strategies.
To add AI as an opponent, the Minimax algorithm enables the system to find the best move by simulating future turns. This approach is widely used in AI-driven Tic-Tac-Toe.
A robust error-handling system prevents players from making duplicate or invalid moves, ensuring a smooth gaming experience.
While the standard grid is 3x3, developers can create 4x4 or 5x5 grids with new win conditions to increase the challenge.
Comments
Post a Comment