checking for valid moves (othello/reversi)

Posted on 2009-04-19
Last Modified: 2013-11-27

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


            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


                                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


                        End If





    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



    End Sub

End Class

Open in new window

Question by:Mutsop
    LVL 48

    Expert Comment

    by:Ryan Chong
    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:
    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.
    LVL 3

    Accepted Solution


    I finally found out the problem :)

    Instead of 'exit for' I just had to use 'continue for'

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Introduction In a recent article ( 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…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now