AI – Artificial Intelligence – PBP Challenge For The Fittest


Results 1 to 21 of 21

Threaded View

  1. #8
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post VB Source Portion A

    I can't paste the entire source - (500,000 chrs in length) - So I'll instead post the 3 main procedures of the protocol.

    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
    Last edited by T.Jackson; - 5th May 2007 at 09:27.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts