Hi Ian, thank you! These libraries I put together for this demo were originally intended for multi-material multi-robot 3D printing. So you’re right – there were probably much easier way to achieve this haha.
As for the random first move, I encode each square of the game board as number 0-8 as follows
In Python, I used the random library to generate the first move.
import random
move = random.randint(0, 8)
You are correct in saying this is a psuedorandom number. However, Python uses the current system time to generate the seed of the random module, so it’s seemingly random. For example, I have included the output of five separate runs of the code below:
import random
nums = [random.randint(0, 8) for i in range(20)]
print(nums)
# it1: [2, 8, 1, 2, 8, 0, 6, 3, 4, 2, 8, 8, 3, 0, 3, 6, 4, 8, 2, 6]
# it2: [1, 1, 7, 4, 8, 0, 7, 3, 1, 4, 8, 0, 6, 7, 2, 4, 5, 1, 6, 8]
# it3: [4, 0, 1, 3, 2, 2, 0, 6, 5, 4, 3, 8, 5, 1, 1, 8, 6, 4, 8, 5]
# it4: [5, 4, 4, 8, 1, 8, 3, 5, 0, 6, 5, 5, 8, 3, 4, 2, 8, 2, 2, 1]
# it5: [5, 8, 3, 4, 2, 1, 7, 3, 8, 4, 3, 3, 1, 1, 7, 4, 1, 2, 0, 6]
Thanks for your interest! The tic-tac-toe specific portion of the code is relatively simple and can be found here.