14
    Here's my best_move procedure. My comments should help you to follow it.
    
    to best_move
      make "best_score -100  ; make it very low to start with
      everyone [  ; we have to try every square
        if shape = "blank [  ; check if square is empty
          setvalue 1  ; pretend to make the move
          make "t total  ; score it & keep the result
          setvalue 0  ; undo the move
          if :t > :best_score [  ; best score so far?
            make "best_score :t  ; yes - keep it and
            make "best_turtle who  ; remember which turtle
          ]
        ]
      ]
      if :best_score > -100 [  ; check if we found an empty square
        talkto :best_turtle
        do_nought
      ]
    end
    
    
and that's it!



Download my project.
HOME table of contents previous