i implemented the tabular q-learning algorithm for 3x3 tictactoe multiple times and everytime the number of entries in the q-table is 16,167. I wanna know how to calculate the number of 16,167. what is the formula to calculate it. the q-learning-algorithm also uses all symmetries. 0,90,180,270 degree rotations, horizontal, vertical, diagonal, antidiagonal.
i know that a 3x3 Tic-Tac-Toe board can be in any combination of three states (empty, X, O) across 9 positions which means that it has 3⁹=19,683 possible configurations
can anybody please help me get the formula to calculate it?
1st EDIT: An example entry of my q-table:
('_XXX_O_OO', 6): 0.9024999999999993
2nd EDIT:
"('_________', 2)": 0.06166253080818989,
"('_________', 8)": 0.06166253080818989,
"('_________', 0)": 0.06166253080818989,
"('_________', 6)": 0.06166253080818989,
"('_________', 3)": 0.030324239570976224,
"('_________', 7)": 0.030324239570976224,
"('_________', 5)": 0.030324239570976224,
"('_________', 1)": 0.030324239570976224,
"('_________', 4)": 0.15534933785554575,
I save the board and all of its symmetries inside the q-table.
3rd EDIT:
my update_q_table function:
def update_q_table(
board,
action,
reward,
new_board,
alpha,
gamma,
future_value,
):
global Q_TABLE_DICT
symmetric_states_and_actions = generate_symmetric_states_and_actions(board, action)
old_value = Q_TABLE_DICT.get((board, action), 0)
if game_over(new_board):
# If it's a terminal state, there are no future rewards to consider
next_max = 0
else:
next_max = future_value
temporal_difference = reward + (gamma * next_max) - old_value
new_q_value = old_value + (alpha * temporal_difference)
# print(new_q_value)
# Update the Q-value for the current state-action pair and its symmetric states
for symmetric_state, symmetric_action in symmetric_states_and_actions:
Q_TABLE_DICT[(symmetric_state, symmetric_action)] = new_q_value
return new_q_value
_________
and agent is selecting actions in $[0,8]$, the agent could play actions 1, 3, 5 or 7 which all result in the "same" board. How is that resolved? I.e. how is the canonical next state decided out of_X_______
,___X_____
,_____X___
and_______X_
? $\endgroup$