Connect 4 in C++

Soldato
Joined
4 Mar 2006
Posts
3,712
Location
Wales
Hi,

I have to code a connect 4 game in c++. The game should be played on a 7x6 (7 across 6 up) grid, which should be stored as a 2D array.

This is being done as a console application (in DOS box basically), so windows programming is unneccessary. The pieces can be displayed as different letters, eg. R and B.

I also need to program AI to play against. The AI must be able to make smart decisions, such as blocking pieces, and attempting to win etc.

I don't need to include diagonals in the winning criteria, however if I do there is the potential for very large bonus marks.



If anyone could give me advice on what I need to look at using, perhaps a bit of help on the AI etc it would be extremely useful :) It's just I've sat here for 2 hours and all I've managed to do is initialised the array as follows.

Code:
#include "stdafx.h"
#include <iostream.h>

int main(int argc, char* argv[])
{
	int gridWidth = 7 ; int gridHeight = 6 ;	
	int gridArray[gridWidth][gridHeight] ;

	for (i = 0 ; i < gridHeight ; i++)
	{
		for (j = 0 ; j < gridWidth ; j++)
			gridArray[i][j] = 0 ;
	}

	


	return 0;
}

As you see, not much for 2 hours :(
 
rudimentary AI won't be that hard to do, check all the valid moves, see how many in a tow each one gives and choose the highest sort of thing. TBH if it's taken you two hours to write that you probably need to set your sights a little lower unless it's a long term project.

Ah that took two hours because I spent a long time trying to work out how I'd go about doing this program. The actual code there took a couple of minutes to bang out, what I meant was 2 hours after picking up the problem to work on, that was all I've got :p



And yeah, basically it's first year programming, we've done classes, references, pointers and just recently done some inheritence. No matrices as yet.
So pretty basic :(
 
Back
Top Bottom