Why use dynamic arrays?

Creating arrays on the heap allows for automatic resizing. Therefore, instead of vectors which allocate the storage beforehand, arrays can expand to accommodate for the new container needed to hold the characters on the board. This saves alot of memory although it might now be so efficient for lookups and deleting elements.

Connect 4 Board components

The board is represented as an object that holds the dynamic arrays. The main structure in the code is "m_data" and it is a dynamic array of size 4. Each container of m_data points to another array to make up the rows of the board. The row size is determined by the size of m_data and the column size is determined by the size of the arrays m_data points at. M_data and the arrays can expand past the original dimensions of 5x4 if a piece goes out of bounds.

Expansion

What happens when the traditional connect four board gets filled without a winner? The game has to restart. However, this new project is designed so that game can continue. All a player needs to do is place a piece outside of the orignal dimensions, either above or below and the board will accomodate for that.

Issues

Using the heap for "dynamic arrays" can pose potential problems. Ensuring that the old dynamic arrays are deleted from the heap when expanding proved to be quite the challenge. When working with memory, ensure that everything that you won't be using gets deleted. Addtionally, attempting to access an array index that is out of bounds will provide a handful of errors. Valgrind and GDB helps locate the problem easily.

VICTORY!

As each player inserts a chip onto the board, once they have 4 in a row/column, they have won the game and the program will terminate. If there is no winner, the game will continously loop until a winner has been established. For now, the game will only check horizontal and vertical wins, with the diagonal win update coming soon.

Phone

(917) 399-2618

Address

110 8th St
Troy, NY 12180
United States of America