Game

Hi,

anyone have the code of the game Tic Tac Toa ?
Google - "code tic tac toe"
100's to choose from!
Well, depends on what platform you need, if you want it with GUI or in console, if you want an unbeatable AI (which is easy to achieve for tic tac toe, you can program it to always end in a tie). It's not that hard to program one yourself tbh, even with AI, as there are just some "Magic Moves".
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
	char tictoc[3][3] = { '1', '2', '3', '4', '5', '6', '7', '8', '9' }, player = 'X';
	int choise;
	while (true)
	{
		system("cls");
		for (int i = 0; i < 3; i++)
		{
			for (int j = 0; j < 3; j++)
			{
				cout << " " << tictoc[i][j] << " ";
			}
			cout << endl;
		}
		cout << "Enter The Number : ";
		cin >> choise;
		if (choise == 1)
		{
			tictoc[0][0] = player;
		}
		else if (choise == 2)
		{
			tictoc[0][1] = player;
		}
		else if (choise == 3)
		{
			tictoc[0][2] = player;
		}
		else if (choise == 4)
		{
			tictoc[1][0] = player;
		}
		else if (choise == 5)
		{
			tictoc[1][1] = player;
		}
		else if (choise == 6)
		{
			tictoc[1][2] = player;
		}
		else if(choise == 7)
		{
			tictoc[2][0] = player;
		}
		else if (choise == 8)
		{
			tictoc[2][1] = player;
		}
		else if (choise == 9)
		{
			tictoc[2][2] = player;
		}
		else if (choise >= 10)
		{
			cout << "invalid input";
			break;
		}
		 if (player == 'X')
		{
			player = 'O';
		}
		else
		{
			player = 'X';
		}
		 if (tictoc[0][0] == 'X'&&tictoc[0][1] == 'X'&&tictoc[0][2] == 'X')
		{
			cout << "Player one won";
			break;
		}
		 else if (tictoc[1][0] == 'X'&&tictoc[1][1] == 'X'&&tictoc[1][2] == 'X')
		{
			cout << "Player one won";
			break;
		}
		 else if (tictoc[2][0] == 'X'&&tictoc[2][1] == 'X'&&tictoc[2][2] == 'X')
		{
			cout << "Player one won";
			break;
		}
		 else if (tictoc[0][0] == 'X'&&tictoc[1][0] == 'X'&&tictoc[2][0] == 'X')
		{
			cout << "Player one won";
			break;
		}
		 else if (tictoc[0][1] == 'X'&&tictoc[1][1] == 'X'&&tictoc[2][1] == 'X')
		{
			cout << "Player one won";
			break;
		}
		 else if (tictoc[0][2] == 'X'&&tictoc[1][2] == 'X'&&tictoc[2][2] == 'X')
		{
			cout << "Player one won";
			break;
		}
		 else if (tictoc[0][0] == 'X'&&tictoc[1][1] == 'X'&&tictoc[2][2] == 'X')
		{
			cout << "Player one won";
			break;
		}
		 else if (tictoc[0][2] == 'X'&&tictoc[1][1] == 'X'&&tictoc[2][0] == 'X')
		{
			cout << "Player one won";
			break;
		}
		 else if (tictoc[0][0] == 'O'&&tictoc[0][1] == 'O'&&tictoc[0][2] == 'O')
		{
			cout << "Player two won";
			break;
		}
		 else if (tictoc[1][0] == 'O'&&tictoc[1][1] == 'O'&&tictoc[1][2] == 'O')
		{
			cout << "Player two won";
			break;
		}
		 else if (tictoc[2][0] == 'O'&&tictoc[2][1] == 'O'&&tictoc[2][2] == 'O')
		{
			cout << "Player two won";
			break;
		}
		 else if (tictoc[0][0] == 'O'&&tictoc[1][0] == 'O'&&tictoc[2][0] == 'O')
		{
			cout << "Player two won";
			break;
		}
		 else if (tictoc[0][1] == 'O'&&tictoc[1][1] == 'O'&&tictoc[2][1] == 'O')
		{
			cout << "Player two won";
			break;
		}
		 else if (tictoc[0][2] == 'O'&&tictoc[1][2] == 'O'&&tictoc[2][2] == 'O')
		{
			cout << "Player two won";
			break;
		}
		 else if (tictoc[0][0] == 'O'&&tictoc[1][1] == 'O'&&tictoc[2][2] == 'O')
		{
			cout << "Player two won";
			break;
		}
		 else if (tictoc[0][2] == 'O'&&tictoc[1][1] == 'O'&&tictoc[2][0] == 'O')
		{
			cout << "Player two won";
			break;
		}
	}
	_getch();
}
Topic archived. No new replies allowed.