12
|
|
to clear
everyone [setshape "blank]
everyone [setvalue 0]
end
|
to ox
if shape = "blank [
do_cross
best_move
]
end
|
to do_nought
setshape "nought
setvalue 1
end
|
to do_cross
setshape "cross
setvalue 4
end
|
Let's think a little bit about best_move.
The turtle needs to try each empty square and work out the score if that square is played.
It needs to decide which move gives the best score and then do_nought
in that square.
In the next part, we'll concentrate on working out the score for any board.
Let me remind you of the process. Take row 2 for example. We need to get the
values for squares 4, 5 and 6 and add them together.
For example, XOX would give 4 + 1 + 4 = 9. You would then look up category 9
and get its score.
This process is repeated for all rows, columns and diagonals to give a total score.
Give it your best shot before proceeding.
|