Code:
Public Sub Perform_Calculated_Move(Compare As Integer)
'-----------------------------------------------------------------------------
'Procedure is called for when CPU is attempting to block your win or win the
'actual game itself. For calculated blocking Compare is set to 0. When the CPU
'decides that there are no wining moves, it will then attempt to block your win.
'Compare is then set to 1. Looking at all angles, rows, cols & diagonal streaks.
'-----------------------------------------------------------------------------
'//
Dim i As Long
Dim j As Long
'//
'Check diagonal \, do we have 2?
'//
If Grid_Set(0, 0) = Players_CHR(Compare) And Grid_Set(2, 2) = Players_CHR(Compare) And Grid_Set(1, 1) = 0 Then
Grid_Set(1, 1) = Players_CHR(Players_Turn)
CPU_Moved = True
Exit Sub
ElseIf Grid_Set(0, 0) = Players_CHR(Compare) And Grid_Set(1, 1) = Players_CHR(Compare) And Grid_Set(2, 2) = 0 Then
Grid_Set(2, 2) = Players_CHR(Players_Turn)
CPU_Moved = True
Exit Sub
'//
ElseIf Grid_Set(1, 1) = Players_CHR(Compare) And Grid_Set(2, 2) = Players_CHR(Compare) And Grid_Set(0, 0) = 0 Then
Grid_Set(0, 0) = Players_CHR(Players_Turn)
CPU_Moved = True
Exit Sub
'//
'Now checking diagonal /, do we have 2?
ElseIf Grid_Set(0, 2) = Players_CHR(Compare) And Grid_Set(1, 1) = Players_CHR(Compare) And Grid_Set(2, 0) = 0 Then
Grid_Set(2, 0) = Players_CHR(Players_Turn)
CPU_Moved = True
Exit Sub
ElseIf Grid_Set(0, 2) = Players_CHR(Compare) And Grid_Set(2, 0) = Players_CHR(Compare) And Grid_Set(1, 1) = 0 Then
Grid_Set(1, 1) = Players_CHR(Players_Turn)
CPU_Moved = True
Exit Sub
'//
ElseIf Grid_Set(1, 1) = Players_CHR(Compare) And Grid_Set(2, 0) = Players_CHR(Compare) And Grid_Set(0, 2) = 0 Then
Grid_Set(0, 2) = Players_CHR(Players_Turn)
CPU_Moved = True
Exit Sub
End If
'//
'Now checking rows consiting 2
If Not CPU_Moved Then
For j = 0 To 2
If Grid_Set(j, 0) = Players_CHR(Compare) And Grid_Set(j, 1) = Players_CHR(Compare) And Grid_Set(j, 2) = 0 Then
Grid_Set(j, 2) = Players_CHR(Players_Turn)
CPU_Moved = True
Exit For
'//
ElseIf Grid_Set(j, 0) = Players_CHR(Compare) And Grid_Set(j, 2) = Players_CHR(Compare) And Grid_Set(j, 1) = 0 Then
Grid_Set(j, 1) = Players_CHR(Players_Turn)
CPU_Moved = True
Exit For
'//
ElseIf Grid_Set(j, 1) = Players_CHR(Compare) And Grid_Set(j, 2) = Players_CHR(Compare) And Grid_Set(j, 0) = 0 Then
Grid_Set(j, 0) = Players_CHR(Players_Turn)
CPU_Moved = True
Exit For
'//
'Now checking cols consiting 2
ElseIf Grid_Set(0, j) = Players_CHR(Compare) And Grid_Set(1, j) = Players_CHR(Compare) And Grid_Set(2, j) = 0 Then
Grid_Set(2, j) = Players_CHR(Players_Turn)
CPU_Moved = True
Exit For
'//
ElseIf Grid_Set(0, j) = Players_CHR(Compare) And Grid_Set(2, j) = Players_CHR(Compare) And Grid_Set(1, j) = 0 Then
Grid_Set(1, j) = Players_CHR(Players_Turn)
CPU_Moved = True
Exit For
'//
ElseIf Grid_Set(1, j) = Players_CHR(Compare) And Grid_Set(2, j) = Players_CHR(Compare) And Grid_Set(0, j) = 0 Then
Grid_Set(0, j) = Players_CHR(Players_Turn)
CPU_Moved = True
Exit For
End If
Next
End If
End Sub
Bookmarks