Can someone review my master program?

Here is the code for my master program. Please tell me what you think so I can make improvements.

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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507


#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <ctime>
#include <string>
#include <cctype>
#include <algorithm>
#include <vector>
#include <fstream>
#include "windows.h"
#include "MMsystem.h"
#include <stdlib.h> 
#include <sstream>
#include <limits>
#include <cstdlib>

using namespace std;

void connect4();
void displayboard(string board);
void directions();
int getchoice();
string changeboard(string board, int choice);
void checklegal();
void changeturn();
void getturn();
char checkwinner();
bool checkfull(int choice);
void dh(int iter, string board);
void dh2(int start, string board);
void coutinblue(char output = ' ');
void coutinblue(string output = " ");
void coutinallblue(char output = ' ');
void coutinallblue(string output = " ");
void ccout(string outputstring, string color = "0");
string ctostr(char input = ' ');
string inttostr(int tmp);
int handler(int type, string prompt = "Input Invalid. Please re-enter");
void box();
void newline(int newlines = 1);
void clrscr();
void gotoXY(int x, int y);


const string YY = "yy";
const string BY = "by";
const string BRY = "bry";
const string RY = "ry";
string board = "                                                                             ";
char turn = 'O';
const char E = ' ';


int main()
{
	if (board != "                                                                             ")
	{
		box();
		char temp = ' ';
		std::cout << "Do you want to use instant recovery?(y/n):\n";
		temp = handler(temp,"Please enter 'y' or 'n'\n");
		if (temp == 'n')
		{
			box();
			std::cout << "Are you sure? Previous data will be lost.(y/n):\n";
			temp = handler(temp,"Please enter 'y' or 'n' \n");
			if (temp =='y')
			{
				box();
				board = "                                                                             ";
			}
			
		}
		
	}
	bool exit = false;
	directions();
	char winner = checkwinner();
	while(!exit)
	{
		while(winner != ' ' && winner != 'T')
		{
			box();
			changeturn();
			if (turn == 'X')
			{
				cout << "Black";
			}
			if (turn == 'O')
			{
				cout << "Red";
			}
			cout << ", it's your turn. \n";
			displayboard(board);
			int choice = getchoice();
			if (choice == 9)
			{
				box();
				return 0;
			}
			board = changeboard(board, choice);		
			winner = checkwinner();
			if (winner == 'T')
			{
				box();
				std::cout << "\n It's a tie!\n";
			}
			else if (winner == 'X' || winner == 'O')
			{
				box();
				std::cout <<endl <<  winner << " wins !\n";
				displayboard(board);
				break;
			}
		}
		char i = ' ';
				
		while(true)
		{
			std::cout << "Do you want to play again?(y/n)";
			i = handler(i, "Please enter 'y' or 'n'\n");
			if(i == 'y')
			{
				board = "                                                                             ";
				box();
				break;
			}

			if(i == 'n')
			{
				board = "                                                                             ";
				box();
				return 0;
			}
		
			else
			{
				continue;
			}
		}
		continue;
	}
	

	box();
	return 0;
}

void directions()
{
	std::cout << "\t Welcome to Connect Four.\n\n";
	std::cout << "The goal in this game is to get four in a row.\n";
	std::cout << "You select a number of a column for your piece to drop into.\n";
	std::cout << "Let's play!\n\n";
	system("pause");
}

void displayboard(string board)
{
    ccout("  1 | 2 | 3 | 4 | 5 | 6 | 7 | 8  ", "r");
	ccout(" 9 to Quit", "g");
	newline();
	coutinallblue("++++++++++++++++++++++++++++++++");
	dh2(8,board); ccout(" ", YY);
	dh2(16,board); ccout(" ", YY);
	dh2(24,board); ccout(" ", YY);
	dh2(32,board); ccout(" ", YY);
	dh2(40,board); ccout(" ", YY);
	dh2(48,board); ccout(" ", BY); 
	coutinallblue(" ");	
	newline();
	coutinallblue("+++++++++++++++++++++++++++++++++");
	newline(2);
	return;
}

void dh(int iter, string board)
{
	WORD wOldColorAttrs;
	CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
	GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfo);
	/*
	* First save the current color information
	*/
	wOldColorAttrs = csbiInfo.wAttributes;
	if (board[iter] == 'X')
	{
		SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),0xe0);
		cout << "o";
	}

	else if (board[iter] == 'O')
	{
		SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 0xec);
		cout << "o";
	}
	else 
	{
		SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 0xee);
		cout << " ";
	}
	SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),wOldColorAttrs);
    return;
}

 void dh2(int start, string board)
{
	coutinallblue(" ");	
	newline();
	coutinallblue(" ");
	ccout(" ", BY);
	int j;
	for (int i = start; i < (start + 7); ++i)
	{
		dh(i , board);
		ccout(" | ", BY);
		j = i;
	}
	dh(j + 1, board);
	return;
}

int getchoice()
{
	int choice = 0;
	do
	{
		
		std::cout << "What is your choice (1-8): ";
		choice = handler(choice, "Please enter a number (1-8)");
		if (choice == 9)
		{
			return 9;
		}
		
		if (choice <= 0 || choice > 8)
		{
			continue;
		}
		else
		{
			if (choice == 1)
			{
				if (board[8] == E)
				{
					break;
				}
				else
				{
					std::cout << "Sorry, that row is full.\n";
					PlaySound(TEXT("rowfull.wav"), NULL, SND_SYNC);
					continue;
				}
			}

			
			if (choice == 2)
			{
				if (board[9] == E)
				{
					break;
				}
				else
				{
					std::cout << "Sorry, that row is full.\n";
					PlaySound(TEXT("rowfull.wav"), NULL, SND_SYNC);
					continue;
				}
			}

			
			if (choice == 3)
			{
				if (board[10] == E)
				{
					break;
				}
				else
				{
					std::cout << "Sorry, that row is full.\n";
					PlaySound(TEXT("rowfull.wav"), NULL, SND_SYNC);
					continue;
				}
			}

			
			if (choice == 4)
			{
				if (board[11] == E)
				{
					break;
				}
				else
				{
					std::cout << "Sorry, that row is full.\n";
					PlaySound(TEXT("rowfull.wav"), NULL, SND_SYNC);
					continue;
				}
			}

			
			if (choice == 5)
			{
				if (board[12] == E)
				{
					break;
				}
				else
				{
					std::cout << "Sorry, that row is full.\n";
					PlaySound(TEXT("rowfull.wav"), NULL, SND_SYNC);
					continue;
				}
			}

			
			if (choice == 6)
			{
				if (board[13] == E)
				{
					break;
				}
				else
				{
					std::cout << "Sorry, that row is full.\n";
					PlaySound(TEXT("rowfull.wav"), NULL, SND_SYNC);
					continue;
				}
			}

			
			if (choice == 7)
			{
				if (board[14] == E)
				{
					break;
				}
				else
				{
					std::cout << "Sorry, that row is full.\n";
					PlaySound(TEXT("rowfull.wav"), NULL, SND_SYNC);
					continue;
				}
			}

			
			if (choice == 8)
			{
				if (board[15] == E)
				{
					break;
				}
				else
				{
					std::cout << "Sorry, that row is full.\n";
					PlaySound(TEXT("rowfull.wav"), NULL, SND_SYNC);
					continue;
				}
			}
			break;
		}
		
	}while(true);
	return (choice - 1);
}

string changeboard(string board, int choice)
{
	
			if(choice == 0)
			{
		
				for (int i = 48; i > 7; i -= 8)
				{
					if(board[i] == E)
					{
						board[i] = turn;
						return board;
					}
				}

			}

	
			if(choice == 1)
			{
				for (int i = 49; i > 8; i -= 8)
				{
					if(board[i] == E)
					{
						board[i] = turn;
						return board;
					}
				}

			}

	
			if(choice == 2)
			{
				for (int i = 50; i > 9; i -= 8)
				{
					if(board[i] == E)
					{
						board[i] = turn;
						return board;
					}
				}

			}

	
			if(choice == 3)
			{
				for (int i = 51; i > 10; i -= 8)
				{
					if(board[i] == E)
					{
						board[i] = turn;
						return board;
					}
				}

			}

	
			if(choice == 4)
			{
				for (int i = 52; i > 11; i -= 8)
				{
					if(board[i] == E)
					{
						board[i] = turn;
						return board;
					}
				}

			}

	
			if(choice == 5)
			{
				for (int i = 53; i > 12; i -= 8)
				{
					if(board[i] == E)
					{
						board[i] = turn;
						return board;
					}
				}

			}

	
			if(choice == 6)
			{
				for (int i = 54; i > 13; i -= 8)
				{
					if(board[i] == E)
					{
						board[i] = turn;
						return board;
					}
				}

			}

	
			if(choice == 7)
			{
				for (int i = 55; i > 14; i -= 8)
				{
					if(board[i] == E)
					{
						board[i] = turn;
						return board;
					}
				}

			}
		


	
	

}

void changeturn()
{
	if (turn == 'X')
	{
		turn = 'O';
		return;
	}
	 
	if (turn == 'O')
	{
		turn = 'X';
		return;
	}

}

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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
char checkwinner()
{
	const int combs[94][4] = {    //All combinations to win
		// 30 horizontal combinations, row by row		
		{48,49,50,51},
		{49,50,51,52},
		{50,51,52,53},
		{51,52,53,54},
		{52,53,54,55},

		{8,9,10,11},
		{9,10,11,12},
		{10,11,12,13},
		{11,12,13,14},
		{12,13,14,15},
		
		{16,17,18,19},
		{17,18,19,20},
		{18,19,20,21},
		{19,20,21,22},
		{20,21,22,23},

		{24,25,26,27},
		{25,26,27,28},
		{26,27,28,29},
		{27,28,29,30},
		{28,29,30,31},

		{32,33,34,35},
		{33,34,35,36},
		{34,35,36,37},
		{35,36,37,38},
		{36,37,38,39},

		{40,41,42,43},
		{41,42,43,44},
		{42,43,44,45},
		{43,44,45,46},
		{44,45,46,47},
		// 24 vertical combinations, column by column
		{8,16,24,32},
		{16,24,32,40},
		{24,32,40,48},

		{9,17,25,33},
		{17,25,33,41},
		{25,33,41,49},
		
		{10,18,26,34},
		{18,26,34,42},
		{26,34,42,50},

		{11,18,27,35},
		{18,27,35,43},
		{27,35,43,51},

		{12,19,28,36},
		{19,28,36,44},
		{28,26,44,52},

		{13,20,29,37},
		{20,29,37,45},
		{29,37,45,53},

		{14,21,30,38},
		{21,30,38,46},
		{30,38,46,54},

		{15,22,31,39},
		{22,31,39,47},
		{31,39,47,55},

		// Diagonal combinations, slanting down to the right
		{8,17,26,35},
		{9,18,27,36},
		{10,19,28,37}, 	
		{11,20,29,38},
		{12,21,30,39},

		{16,25,34,43},
		{17,26,35,44},
		{18,27,36,45},
		{19,28,37,46},
		{20,29,38,47},

		{24,33,42,51},
		{25,34,43,52},
		{26,35,44,53},
		{27,36,45,54},
		{28,37,46,55},

		// Diagonal combinations, slanting down to the left
		{11,18,25,32},
		{12,19,26,33},
		{13,20,27,34},
		{14,21,28,35},
		{15,22,29,36},

		{19,26,33,40},
		{20,27,34,41},
		{21,28,35,42},
		{22,29,36,43},
		{23,30,37,44},

		{27,34,41,48},
		{28,35,42,49},
		{29,36,43,50},
		{30,37,44,51},
		{31,38,45,52},};

		int TOTAL_ROWS = 94;
		for(int row = 0; row < TOTAL_ROWS; ++row)
		{
			if ( (board[combs[row][0]] != E) && (board[combs[row][0]] == board[combs[row][1]]) && (board[combs[row][1]] == board[combs[row][2]]) && (board[combs[row][2]] == board[combs[row][3]]) && (board[combs[row][3]] == board[combs[row][0]]))
			{
				return turn;
			}
		}

		if (count(board.begin(), board.end(), E) == 0)
		{
			return 'T';
		}
		else
		{
			return ' ';
		}

}
void box(int newlines)
{
	WORD wOldColorAttrs;
	CONSOLE_SCREEN_BUFFER_INFO csbiInfo;

	/*
	* First save the current color information
	*/
	GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfo);
	wOldColorAttrs = csbiInfo.wAttributes;
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x09);
	clrscr();
	coutinallblue("////////////////////////////////////////////////////////////////////////////////");
	newline(newlines);
	coutinallblue("////////////////////////////////////////////////////////////////////////////////");
	gotoXY(0,0);
	cout << endl;
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),wOldColorAttrs);
	return;
}
void clrscr()
  {
  HANDLE                     hStdOut;
  CONSOLE_SCREEN_BUFFER_INFO csbi;
  DWORD                      count;
  DWORD                      cellCount;
  COORD                      homeCoords = { 0, 0 };

  hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
  if (hStdOut == INVALID_HANDLE_VALUE) return;

  /* Get the number of cells in the current buffer */
  if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
  cellCount = csbi.dwSize.X *csbi.dwSize.Y;

  /* Fill the entire buffer with spaces */
  if (!FillConsoleOutputCharacter(
    hStdOut,
    (TCHAR) ' ',
    cellCount,
    homeCoords,
    &count
    )) return;

  /* Fill the entire buffer with the current colors and attributes */
  if (!FillConsoleOutputAttribute(
    hStdOut,
    csbi.wAttributes,
    cellCount,
    homeCoords,
    &count
    )) return;

  /* Move the cursor home */
  SetConsoleCursorPosition( hStdOut, homeCoords );
  }

inline void newline(int newlines)
{
	for (int i = 0; i < newlines; ++i)
	{
		cout << endl;
	}
}

void coutinblue(char output)
{
	WORD wOldColorAttrs;
	CONSOLE_SCREEN_BUFFER_INFO csbiInfo;

	/*
	* First save the current color information
	*/
	GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfo);
	wOldColorAttrs = csbiInfo.wAttributes;
	SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 0x09);
    cout << output;
	SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),wOldColorAttrs);
	return;
}

void coutinblue(string output)
{
	WORD wOldColorAttrs;
	CONSOLE_SCREEN_BUFFER_INFO csbiInfo;

	/*
	* First save the current color information
	*/
	GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfo);
	wOldColorAttrs = csbiInfo.wAttributes;
	SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 0x09);
    cout << output;
	SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),wOldColorAttrs);
	return;
}


void coutinallblue(char output)
{
	WORD wOldColorAttrs;
	CONSOLE_SCREEN_BUFFER_INFO csbiInfo;

	/*
	* First save the current color information
	*/
	GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfo);
	wOldColorAttrs = csbiInfo.wAttributes;
	SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 0x99);
    cout << output;
	SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),wOldColorAttrs);
	return;
}

void coutinallblue(string output)
{
	WORD wOldColorAttrs;
	CONSOLE_SCREEN_BUFFER_INFO csbiInfo;

	/*
	* First save the current color information
	*/
	GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfo);
	wOldColorAttrs = csbiInfo.wAttributes;
	SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 0x99);
    cout << output;
	SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),wOldColorAttrs);
	return;
}

void ccout(string outputstring, string color)
{
	WORD wOldColorAttrs;
	CONSOLE_SCREEN_BUFFER_INFO csbiInfo;

	/*
	* First save the current color information
	*/
	GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfo);
	wOldColorAttrs = csbiInfo.wAttributes;
	if (color == "y")
	{
		SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),0x0e);
		cout << outputstring;
	}
	if (color == "r")
	{
		SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),0x04);
		cout << outputstring;
	}
	if (color == "b")
	{
		SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),0x09);
		cout << outputstring;
	}
	if (color == "g")
	{
		SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),0x02);
		cout << outputstring;
	}
	if (color == "w")
	{
		SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),0x07);
		cout << outputstring;
	}
	if (color == "b")
	{
		SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),0x00);
		cout << outputstring;
	}
	if (color == "ry")
	{
		SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),0xe4);
		cout << outputstring;
	}
	if (color == "by")
	{
		SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),0xe0);
		cout << outputstring;
	}
	if (color == "yy")
	{
		SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),0xee);
		cout << outputstring;
	}
	if (color == "bry")
	{
		SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),0xec);
		cout << outputstring;
	}
	if (color == "0")
	{
		cout << outputstring;
	}

	SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),wOldColorAttrs);
}

string ctostr(char input)
{
	string output = " ";
	output[1] = input;
	return output;

}

int handler(int type, string prompt)
{
	while (true)
	{
		cin >> type;
		if(cin.fail())
		{
			cout << prompt;
			cin.clear();
			cin.ignore(256,'\n');
			continue;
		}
		else
		{
			break;
		}
	}
	return type;
	
}
float handler(float type, string prompt)
{
	while (true)
	{
		cin >> type;
		if(cin.fail())
		{
			cout << prompt;
			cin.clear();
			cin.ignore(256,'\n');
			continue;
		}
		else
		{
			break;
		}
	}
	return type;
	
}
char handler(char type, string prompt)
{
	while (true)
	{
		cin >> type;
		if(cin.fail())
		{
			cout << prompt;
			cin.clear();
			cin.ignore(256,'\n');
			continue;
		}
		else
		{
			break;
		}
	}
	return type;
}

string inttostr(int tmp)
{
	string String = static_cast<ostringstream*>( &(ostringstream() << tmp) )->str();
    return String;


The code was too long so I had to split it up.
well at first glance you have massive amounts of code duplication. Put them in methods and call that method with relevant parameters.
Consider an OO approach as well.
ok thanks. I have done some renovation (if you can call it that). could you tell me what methods are?
I thought I was doing OOP. please tell me what I am doing wrong
Essentially, a lot of your code could benefit from common OOP practices and standards. For instance, you have a large, hardcoded look-up table of possible winning combinations. Wouldn't it be better to compute a winning combination during run-time through some algorithm? Look-up tables have their purposes, though in this context it doesn't strike me as logical.

You could also create classes to represent board pieces, and use one of the containers available in the STL to store and iterate through them.
It would also make sense to give your functions more descriptive names, following some kind of naming convention.
For instance, by looking at void dh(..., it's not self-explanatory what this function does.
Right. I see what you mean. BTW dh means Display Helper.dh2 is the same. What would I do to check combinations? Nested for loops?
Sorry if I seem like I need to be spoon fed.

Going back to the OO stuff for a second: You could try this: write a brief paragraph of what you program does (or will do). now go back over that description and underline every noun. In theory you could create a class for each of these nouns and start from there. Now i think that's a bit overkill, but i do this sometimes at the start of a project to get a feeling of the type of classes I may need.
Last edited on
I will try that. Thanks.
What are methods?
Are they functions like std::vector.push_back()?

functions for classes essentially?

Yes, that's right.
Can anyone tell me what a better way to test for a win would be? As apposed to hardcoded combinations?

Thanks
If you are keeping track of where pieces are, whether for each piece or each slot that a piece can go, you could just check for 4 in a row via a counter. A for-loop could work for that. Using indices to represent certain locations or positions, you could either pass in the location of a piece in general or even the location of any slot and then check for 4-piece combos.

Iterating through the loop and incrementing a counter everytime a piece in the correct location occurs, setting a flag or something if 4 in-a-row occur or something..?

Just some ideas. Hope it helps.
Thanks, I will try to work on that.

So far my code with the OOP aproach is:
Connect Four.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
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
#include "Connect Four.h"

using namespace std;

void clrscr()
  {
  HANDLE                     hStdOut;
  CONSOLE_SCREEN_BUFFER_INFO csbi;
  DWORD                      count;
  DWORD                      cellCount;
  COORD                      homeCoords = { 0, 0 };

  hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
  if (hStdOut == INVALID_HANDLE_VALUE) return;

  /* Get the number of cells in the current buffer */
  if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
  cellCount = csbi.dwSize.X *csbi.dwSize.Y;

  /* Fill the entire buffer with spaces */
  if (!FillConsoleOutputCharacter(
    hStdOut,
    (TCHAR) ' ',
    cellCount,
    homeCoords,
    &count
    )) return;

  /* Fill the entire buffer with the current colors and attributes */
  if (!FillConsoleOutputAttribute(
    hStdOut,
    csbi.wAttributes,
    cellCount,
    homeCoords,
    &count
    )) return;

  /* Move the cursor home */
  SetConsoleCursorPosition( hStdOut, homeCoords );
  }

void Pause()
{
	cout << "Please Press ENTER to continue.";
	cin.ignore(256,'\n'); //Or Other pause method
}

Game::Game()
{
	turn = BLACK;
	Won = false;
	Instructions();
	Loop();
	DeclareWin();
	PlayAgain();
}

Game::~Game() //Nothing to clean up, just pausing
{
	Pause();
}

Board::Board()
{
	theBoard.reserve(56); //Reserve 56 spots for theBoard
}

void Game::Loop()
{
	
	while(!Won)
	{
		ChangeTurn(); //Change the turn, 
		theBoard.Render();
		Input();
		theBoard.Add(choice, turn);
		CheckWin();
	}

	return;
}

void Game::ChangeTurn()
{
	if (turn == BLACK)
	{
		turn == RED;
	}
	if (turn == RED)
	{
		turn = BLACK;
	}
	return;
}

void Game::Input()
{
	int temp;
	do
	{
		cout << "Enter your choice 1-8: ";
		cin >> temp;
		cin.ignore(256, '\n');
		cin.clear();
	} while(!cin);
	choice = temp;
}

void Game::Instructions()
{
	std::cout << "\t Welcome to Connect Four.\n\n"; 
	std::cout << "The goal in this game is to get four in a row.\n";
	std::cout << "You select a number of a column for your piece to drop into.\n ";
	std::cout << "Let's play!\n\n";
}

void Board::Render()
{
	cout << "BOARD\n";
	Pause();
	clrscr();
}

void Board::Add(int position, WORD input)
{

}

void Game::CheckWin()
{
	Won = false;

}

void Game::PlayAgain()
{

}

void Game::DeclareWin()
{

}



int main()
{
	Game theGame;
	return 0;
}


Connect Four.h
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
#include <iostream>
#include <string>
#include <windows.h>
#include <vector>

using namespace std;

class Board
{
public:
	Board();
	void Render();
	void Empty();
	void Add(int position, WORD input);
private:
	vector<char> theBoard;

};

class Game
{
public:
	Game::Game();
	void Instructions();
	void Loop();
	void ChangeTurn();
	void Input();
	void CheckWin();
	void PlayAgain();
	void DeclareWin();
	Game::~Game();
private:
	int choice;
	Board theBoard;
	WORD turn;
	enum Turns{RED = 0xec, BLACK = 0xe0};
	bool Won;
};


Any more suggestions?
I think I may use char theBoard[6][8] instead of a vector.
Last edited on
Can you post the whole source code so I could compile and see it? I just want to see how it works and how the game is.
I did
that is all up there. Notice I am not done.
Last edited on
Any more ideas? I did post the whole code though. I am not done with it and haven't made several functions.
Topic archived. No new replies allowed.