Connect 4 in C++ Essay

4616 Words Feb 26th, 2011 19 Pages
Course Title…FD COMPUTING 1ST YR

Module Code…CO1451.

Module Title… Programming in C++
Module Tutor Harvey Long

Assignment Title/Number……No.1…
……………………………

Student Name……Stephen Allen

Student ID No… All09109979

I confirm that this piece of work which I have submitted is all my own work and that all references and quotations from both primary and secondary sources have been fully identified and properly acknowledged in footnotes and bibliography.

Signature of student.........ste allen..............................................................

Introduction
The game of connect 4 consists of two players that take alternate turns to drop counters into a grid. There are two styles of counter so that
…show more content…
I feel that I can visualise the program better and not get mixed up with the algorithm if the grid is stored this way. Other ways to store the grid would be to have seven separate 1D arrays, one 49 element array or even 49 separate variables. When first presented with the assignment I immediately envisaged writing a program that consisted of a 49 element array of type bool where player 1 would choose elements and those elements would be designated true and player 2 chose elements to be false. The possible combinations and sets of element number that could contain a line of 4 made writing the algorithm for this difficult for me to understand. Using the x and y co-ordinates to explain the relative position of the elements made for a much easier way to approach the assignment. Choosing the elements to be of type char was decided to be the most suitable variable. The x and y co-ordinates for each element are shown in the following table:- 0,6 | 1,6 | 2,6 | 3,6 | 4,6 | 5,6 | 6,6 | 0,5 | 1,5 | 2,5 | 3,5 | 4,5 | 5,5 | 6,5 | 0,4 | 1,4 | 2,4 | 3,4 | 4,4 | 5,4 | 6,4 | 0,3 | 1,3 | 2,3 | 3,3 | 4,3 | 5,3 | 6,3 | 0,2 | 1,2 | 2,2 | 3,2 | 4,2 | 5,2 | 6,2 | 0,1 | 1,1 | 2,1 | 3,1 | 4,1 | 5,1 | 6,1 | 0,0 | 0,1 | 0,2 | 0,3 | 0,4 | 0,5 | 0,6 |
This equates to a 2D array which will be called cell[row][column] where row is the x co-ordinate and column is the y co-ordinate.
The array will be initialised in the following

More about Connect 4 in C++ Essay

Open Document