-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabheet.cpp
69 lines (57 loc) · 1.58 KB
/
abheet.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <array>
#include <tuple>
#include <random>
// X denotes human. O denotes AI.
// turn = 1, denotes human's turn.
// turn = 0, denotes AI's turn.
std::tuple<int, int> humanInput() // takes human input (coordinates)
{
std::cout << "Enter x and y coordinates (Starting from 0 to 2)\n: ";
int x, y = -1;
std::cin >> x >> y;
return std::make_tuple(x, y);
}
void AI()
{
std::array<std::array<char, 3>, 3> board{}; // generate an empty 3x3 board for tic-tac-toe
int flagFirstMove = -1;
int turn = 1;
while(true)
{
if(turn == 1)
{
auto coordinates = humanInput();
int x, y = -1;
x = std::get<0>(coordinates);
y = std::get<1>(coordinates);
// make code snippet where an X is placed at (x, y)
// board[x][y]='X';
//showboard(board);
if(flagFirstMove == -1); // This runs ONLY once. First move is by human always.
{
std::cout << "The game begins!\n";
flagFirstMove = 1;
turn = 0;
std::default_random_engine integer_generator;
std::uniform_int_distribution<int> distributor(0, 2);
int x = distributor(integer_generator);
int y = distributor(integer_generator);
// add code to place an O at (x, y)
continue; // dont check the else-if statement this time, cause AI did its job here.
}
}
else if(turn == 0)
{
// AI ka code banao
}
// write code to check if
// the board ran out of empty spaces.
// or if
//someone reached 3-unit-long-streak
}
int main()
{
AI();
return 0;
}