i did not test all the possiblities, but this should be close
edited last at - 7PM CDT 10/13/2008
Code:'Square reference '1 2 3 '4 5 6 '7 8 9 'as array coord. '00 01 02 '10 11 12 '20 21 22 Dim xoS As String(,) = New String(2, 2) {}, winAs As String Private Sub StartGame() 'init array - start of game / application For x As Integer = 0 To xoS.GetUpperBound(0) For y As Integer = 0 To xoS.GetUpperBound(1) xoS(x, y) = "NONE" 'set all elements Next Next End Sub Private Function MarkSquare(ByVal theSq As Integer, ByVal XorO As String) As Boolean Dim r As Integer 'row r = (theSq - 1) \ 3 'calc the row Dim c As Integer 'column c = (theSq - (r * 3)) - 1 'calc the column If xoS(r, c) <> "NONE" Then Return False 'already picked!!! should not happen xoS(r, c) = XorO 'set the square End Function 'check each row 'check each col 'check (0,0) (1,1) (2,2) 'check (0,2) (1,1) (2,0) Private Function checkwin() As Boolean Dim OorX() As String = New String() {"X", "O"} Dim inArow As Integer For y As Integer = 0 To OorX.Length - 1 'odd balls - see square reference above If OorX(y) = xoS(0, 0) AndAlso OorX(y) = xoS(1, 1) AndAlso OorX(y) = xoS(2, 2) Then winAs = "ODD" Return True End If If OorX(y) = xoS(0, 2) AndAlso OorX(y) = xoS(1, 1) AndAlso OorX(y) = xoS(2, 0) Then winAs = "ODD" Return True End If winAs = "ROWS" For r As Integer = 0 To 2 'check by rows inArow = 0 For c As Integer = 0 To 2 If OorX(y) = xoS(r, c) Then inArow += 1 End If Next If inArow = 3 Then Return True Next winAs = "COLS" For c As Integer = 0 To 2 'check by cols inArow = 0 For r As Integer = 0 To 2 If OorX(y) = xoS(r, c) Then inArow += 1 End If Next If inArow = 3 Then Return True Next Next winAs = "" Return False End Function




Reply With Quote