Im writing a Network version of Othello (sometimes called Reversi)
but im having trouble with the function that checks your move.

A screen shot of my app:

[img]http://homepages.picknowl.com.au/craig_sharon/othello2.gif[/img]

Basically each Square is a PictureBox, Player 1 (White) goes first, so if for example they click the picturebox (F,5) which incidentally is named "F5" i want it to pass the name F5 to my checking Function (which isnt complete because i couldnt get the first few lines of code to execute). The checking function needs to first check if the box above it is Black, then if it is it needs to go to the square above and check if it's black (it continues to do this untill A it reaches the last square or it runs into B a blank square (in this case it needs to check the diagonal(s)) or C a White square (where it then needs to "flip" all the squares in between and then continue to check the diagonals)).

Any way...

Here is My code for the box F5:

Private Sub F5_Click()
If HostTurn = True Then CheckPossibilities "F5"
End Sub

Here is my function code:

Function CheckPossibilities(Square As String)
Dim Num As Integer
Dim Square2 As PictureBox
Num = Right$(Square, 1)
If Num >= 2 Then
   Num = Num - 1
   If HostTurn Then
      Square2 = Left$(Square, 1) & Num 'This is the      Problem Line!
      If Square2.Picture = White.Picture Then  'This is the white "control" picture
      Goto APieceOfCodeNotYetWritten
      Else
         If Num >= 2 Then
            Num = Num - 1
            Square2 = Left$(Square, 1) & Num
            if Square2.Picture = White.Picture Then
                Goto APieceOfCodeNotYetWritten
            End If
         End If
      End If
   End If
End If
End Function

The Problem line: Square2 = Left$(Square, 1) & Num

The error message i get is: [img]http://homepages.picknowl.com.au/craig_sharon/error.jpg[/img]

Basically i need to know how i can do this ^ so that i can use variables to go through each square and test it before sending the "updated" square values to the other player

If you have any questions please post them, i really want this to work and any help i receive will be greatly appreciated.

Thankyou.

Member Avatar for AlanC

Hi

You might want to use a control array for your picture boxes. In effect, they all have the same name 'pictBoard' or whatever name you choose, however each has an index number that is unique. When any of the boxes is clicked, the same event fires (pictBoard_click to use this example), but the index number corresponding the control clicked is passed to the event. You then simply use the index parameter to determine which box was clicked.

It occurs to me that you could think of the control index number as a binary number whose high 3 bits tell you the column and low 3 bits tell you the row; in this way you can work out the picture box that was clicked. So for example, the board is clicked and the index of the particular picture box control passed is 25; this is 011001 in binary which represents column 3 row 1.

This is a cool project and it's worth some complication in order to make it work well.

Happy to do you a demo project to illustrate the points made above if you wish.

Regards
AlanC

Thanks, Ill try that, Ive had a little experience with control arrays since the winsock control needs them to work properly. Ill just arrange them from 0 to 63 top left to bottom right.

that would be because num is an integer not a string.
use str(num) and it won't error out.

Oh well, ive already converted my project to using control arrays and its coming along nicely

Its nearly finished, I think i've basically finished debugging it and ive added Instant Messaging, i just need to finish the function that forces passing and the function to work out who wins!

Member Avatar for AlanC

Go for it!!

I never won any game I played against my wife. She's obviously far more logical than I am (and she's watching me write this too)! Sorry, going off topic.

AlanC

the trick with othello is to capture edges and corners, btw - By The Way - i finnished the Pass function, im sure ive got all the bugs now i just need to work out who wins... easy as Pi when its finished ill post it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.