As mentioned by others, it isn't too hard to create the whole trie.
Player $A$ is green and Player $B$ is orange:
For reference purposes, here's the corresponding Python code. It uses networkx and graphviz:
import networkx as nx
from networkx.drawing.nx_agraph import to_agraph
def is_prime(n):
if n == 2:
return True
if n < 2 or n % 2 == 0:
return False
for d in range(3, int(n**0.5) + 1, 2):
if n % d == 0:
return False
return True
def add_prime_leaves_recursively(current_number=0, current_representation='',
base=10, graph=nx.DiGraph(), level=0,
colors=['#FF851B', '#2E8B57']):
graph.add_node(current_number,
label=current_representation,
color=colors[level % 2])
for next_digit in range(base):
next_number = current_number * base + next_digit
if is_prime(next_number):
graph.add_edge(current_number, next_number)
add_prime_leaves_recursively(
next_number,
current_representation + '0123456789ABCDEFGHIJ'[next_digit],
base, graph, level + 1)
return graph
G = add_prime_leaves_recursively(base=10)
G.nodes[0]['color'] = 'black'
A = to_agraph(G)
A.draw('prime_number_construction_game.png', prog='dot')
This code can generate the diagram for any base below 20. The game is boring in base 3: