Basically my game is part of a school project and I was wondering if the way I'm doing is long-winded and theres an esier way which I'm missing or if the way i've done it is ok.
The board acts as a (7,9) array and I at the moment I've basically worked it out in steps, so vertically, horizontally, diagonally. The way i've gone about doing it is by for example horizontally
Check (y+1) and (y-1) for same colour piece, if both true check
if either (y+2) or (y-2) are same colour
else check (y+1) only, if colour check (y+2)(y+3)
else check (y-1) only, if colour check (y-2)(y-3)
'Basically when coding this, I get three If statemetns which I then apply a corresponding x or y boundary.
The coding for the first part is below, I don't want to post all my coding but just to show you what I'm doing.
Function checkwin(ByVal x As Integer, ByVal y As Integer) As Boolean Dim Player As String If marker = True Then Player = "Player" Else Player = "CPU" End If 'Horizontal check for win 'THIS IS ONLY THE FIRST LINE of the Pseudo code above. If (3 <= y And y <= 7) Then If board(x, (y + 1)).Image.Tag = Player And board(x, (y - 1)).Image.Tag = Player Then If board(x, (y + 2)).Image.Tag = Player Or board(x, (y - 2)).Image.Tag = Player Then Return True End If End If End If
So basically is the way I'm doing it now effective? I end up with 12 If statements to check all possible wins or is it long winded??
I don't know if there is an algorithm out there which can be used, but basically I wanted to make it as much of my own code as possible, so I'm trying to refrain from looking at other peoples coding for connect4.