top of page

CONNECT-4

A relatively simple program:
Connect-4 utilises object-oriented programming principles in Python as to compartmentalise each entity's functionality.

Bit-wise operations have been used in order to calculate whether a token is placed at a certain location, whether a token can be placed in a selected column and if any of the players have won.

GALLERY

DESCRIPTION

The board is represented by a single array of unsigned 8-bit integer values and each column is an element of this array. The value contains switched bits which denote token positions and when a player places a token in a column, the the first least-significant bit that is off is the next available token position. N is the element of the array and 2^X is the state bit-position X where X is between 1 and 6.

N

​

2^X

With regards to the checking the winner becomes a little more complex but for each direction there is an algorithm that checks for each possible win-state.

For example, a horizontal win requires 2^X to be on for each N where X can be 1-6 and initial N value can be anything 1-4.

bottom of page