Solved

# checking for valid moves (othello/reversi)

Posted on 2009-04-19
667 Views
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
Question by:Mutsop

LVL 48

Expert Comment

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

LVL 3

Author Comment

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

LVL 3

Accepted Solution

Hey,

I finally found out the problem :)

0

## Featured Post

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…