I have a game tree with an arbitrary number of possible moves for me and my opponent with an arbitrary sequence of moves. I want to get an overview of all 'sets of moves I can make' and corresponding info. In this example I narrowed my problem down. Each move I can choose max 2 moves ('1' or '2'). And my opponent can choose max 2 moves ('a' or 'b'). In this example there are 5 possible 'sets of moves I can make'. How do I produce this outcome in a way that it will work with a larger game tree as well?
input = {'1': {'a': {'1': {'a': 'some_info_1'},
'2': {'a': 'some_info_2'}},
'b': {'1': {'a': {'1': {'a': 'some_info_3'},
'2': {'a': 'some_info_4'}}
}
},
},
'2': {'a': 'some_info_5'}
}
output = {
1: {'1': {'a': {'1': {'a': 'some_info_1'}},
'b': {'1': {'a': {'1': {'a': 'some_info_3'}}}}}},
2: {'1': {'a': {'2': {'a': 'some_info_2'}},
'b': {'1': {'a': {'1': {'a': 'some_info_3'}}}}}},
3: {'1': {'a': {'1': {'a': 'some_info_1'}},
'b': {'1': {'a': {'2': {'a': 'some_info_4'}}}}}},
4: {'1': {'a': {'2': {'a': 'some_info_2'}},
'b': {'1': {'a': {'2': {'a': 'some_info_4'}}}}}},
5: {'2': {'a': 'some_info_5'}}
}
I searched for the answer on this and other sites. This thread comes close: Combination of nested dictionaries with arbitrary lengths in python
I also tried for loops
, itertools
and cartesian products
. But I can't get it to work. It's really frustrating. I hope someone can help.