[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

checking for valid moves (othello/reversi)

Posted on 2009-04-19
3
Medium Priority
?
899 Views
Last Modified: 2013-11-27
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

Open in new window

0
Comment
Question by:Mutsop
  • 2
3 Comments
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 24181431
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

by:Mutsop
ID: 24183852
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

by:
Mutsop earned 0 total points
ID: 24222211
Hey,

I finally found out the problem :)

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

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

834 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