Hey there, im currently working on a connect 4 game, the issue with this is sometimes it returns true sometimes it returns false, even though the player has won
CheckForWin(Team: string) : logic =
# team one is yellow, team two is red
Board:[][]int = array{
array{Row1_6, Row2_6, Row3_6, Row4_6, Row5_6, Row6_6, Row7_6},
array{Row1_5, Row2_5, Row3_5, Row4_5, Row5_5, Row6_5, Row7_5},
array{Row1_4, Row2_4, Row3_4, Row4_4, Row5_4, Row6_4, Row7_4},
array{Row1_3, Row2_3, Row3_3, Row4_3, Row5_3, Row6_3, Row7_3},
array{Row1_2, Row2_2, Row3_2, Row4_2, Row5_2, Row6_2, Row7_2},
array{Row1_1, Row2_1, Row3_1, Row4_1, Row5_1, Row6_1, Row7_1}
}
var current_coin : int = 0
if (Team = "Yellow"):
set current_coin = 1
if (Team = "Red"):
set current_coin = 2
for (C := 0..4):
for (R := 0..6):
if (Board[R][C] = current_coin and Board[R][C + 1] = current_coin and Board[R][C + 2] = current_coin and Board[R][C + 3] = current_coin):
return true
for (C := 0..7):
for (R := 0..3):
if (Board[R][C] = current_coin and Board[R + 1][C] = current_coin and Board[R + 2][C] = current_coin and Board[R +3][C] = current_coin):
return true
for (C := 0..4):
for (R := 0..3):
if (Board[R][C] = current_coin and Board[R + 1][C + 1] = current_coin and Board[R + 2][C + 2] = current_coin and Board[R +3][C + 3] = current_coin):
return true
for (C := 0..4):
for (R := 3..6):
if (Board[R][C] = current_coin and Board[R - 1][C + 1] = current_coin and Board[R - 2][C + 2] = current_coin and Board[R - 3][C + 3] = current_coin):
return true
return false```