• Status: Solved
• Priority: Medium
• Security: Public
• Views: 972

# checking for valid moves (othello/reversi)

Hi

I've been busy with programming a game for a week almost (beginner) and am now trying to check for all valid moves for the game of othello/reversi. When a valid move is detected it will be shown as a dot or question mark (in the array) So I'm checking for each empty place for an opponent token, if there is one I'll go check in the same direction for any other, till I have a token I own.

But for some reason not all valid places are shown. to be a bit more exact only the verticals and diagonal (under) are shown.

``````Public Shared Sub ShowIsValid(ByVal isTurn As Byte, ByRef isValid As Byte)
Dim opponent As Char
Dim player As Char
If isTurn = 0 Then
opponent = "o"c
player = "x"c
Else
opponent = "x"c
player = "o"c
End If
For row As Integer = 0 To 7
For col As Integer = 0 To 7
'is het veld niet leeg, For lus overslaan
If Board.boardArray(row, col) <> " "c Then Exit For
For rowDirection As Integer = -1 To 1
For colDirection As Integer = -1 To 1
If row + rowDirection < 0 Or _
row + rowDirection >= 7 Or _
col + colDirection < 0 Or _
col + colDirection >= 7 Or _
(rowDirection = 0 AndAlso colDirection = 0) Then Exit For

If Board.boardArray(row + rowDirection, col + colDirection) = opponent Then
x = row + rowDirection
y = col + colDirection
Do
x += rowDirection
y += colDirection
If x < 0 Or x >= 7 Or y < 0 Or y >= 7 Then Exit Do
If Board.boardArray(x, y) = " "c Then Exit Do
If Board.boardArray(x, y) = player Then
Board.boardArray(row, col) = "."c
isValid += 1
Exit Do
End If
Loop
End If
Next
Next
Next
Next
End Sub
Public Shared Sub resetShowValid()
For i As Integer = 0 To 7
For j As Integer = 0 To 7
If Board.boardArray(i, j) = "." Then
Board.boardArray(i, j) = " "
End If
Next
Next
End Sub
End Class
``````
0
Mutsop
• 2
1 Solution

Commented:
I did a othello/reversi during my college time, but unfortunately due to some disasters all the source codes written (in vb6) are gone...

However, I still have the compiled executable (but not the latest), which think you can download and then refer to:

http://www34.brinkster.com/yshub/dl.asp?id=1
0

Author Commented:
File aint accesable...

But does anyone here see a problem within the code?
I mean I've been checking the valid steps one by one for almost two dyas now but can't seem to find anything.
0

Author Commented:
Hey,

I finally found out the problem :)