Well, it just happened and I won playing X.
Here's the game-transcript.
---
CL-USER 22 > (play-game 'X *initial-board* 'human 'rand-player)Perhaps I shouldn't get too excited: here's my opponent - noting that ...
Next to play: X
0 | 1 | 2
3 | 4 | 5
6 | 7 | 8
"Please enter an available number: " 8
0 | 1 | 2
3 | 4 | 5
6 | 7 | X
--- Computer playing O now moves ---
O | 1 | 2
3 | 4 | 5
6 | 7 | X
"Please enter an available number: " 6
O | 1 | 2
3 | 4 | 5
X | 7 | X
--- Computer playing O now moves ---
O | 1 | 2
3 | 4 | 5
X | O | X
"Please enter an available number: " 2
O | 1 | X
3 | 4 | 5
X | O | X
--- Computer playing O now moves ---
O | 1 | X
O | 4 | 5
X | O | X
"Please enter an available number: " 1
O | X | X
O | 4 | 5
X | O | X
--- Computer playing O now moves ---
O | X | X
O | 4 | O
X | O | X
"Please enter an available number: " 4
Win for X
O | X | X
O | X | O
X | O | X
- the parameter m is the 'mark' - X or O;
- b is the evolving board, eg: '(X 1 O O 4 5 X 7 X).
(defun rand-player (m b)
(let* ((remaining-numbers (remove 'O (remove 'X b)))
(n (length remaining-numbers))
(random-index (random n)) )
(nth random-index remaining-numbers)) )
The considerably more difficult task of getting the tree-search system debugged I'll leave for tomorrow!
---
You may have noticed my poor fourth move. OK, I was toying with it.
---
Update Wednesday 18th January.
To Roy's comment below: yes, it's random. I used it to test the game-playing framework and user interface. It is rather spooky and apparently cunning to play against - hard to second-guess 😏.
Today I've been working on the tree-generation algorithm and minimax. Probably a session or two away from the first capable AI player.
So the machine was using Random play?
ReplyDeleteI wonder whether the ideal here is to (generally) lose rather than win. In that case you have made a system better than you...