Skip to content

Instantly share code, notes, and snippets.

@fredvol
Last active July 30, 2022 11:48
Show Gist options
  • Save fredvol/69219d6a47e56a2414dfb28756d1b686 to your computer and use it in GitHub Desktop.
Save fredvol/69219d6a47e56a2414dfb28756d1b686 to your computer and use it in GitHub Desktop.
problem instance de class python
#%% simplify problem
from typing import List
list_action = ['SPEED' , 'SLOW', 'JUMP', 'UP', 'DOWN']
credit_initial =1 # to limite the expansion
class Node:
def __init__(
self,
n: int,
cred: int,
action: str,
adresse: List[str] = [],
):
self.n = n
self.credit = cred
self.action = action
self.childs = []
self.adresse = adresse
self.adresse.append(action)
def __repr__(self) -> str:
return f"n:{self.n } , credit:{self.credit } , adresse:{self.adresse} , nb_child :{len(self.childs)} " #child :{self.childs}
def expand(self):
for action in list_action :
New_node = Node(self.n+1, self.credit - 1, action, self.adresse)
if self.credit >0:
self.childs.append(New_node)
#%%
root= Node(0,credit_initial,'INIT')
root.expand()
# %% Normaement l'adree de root devrait etre ['INIT] et Uniquement ça mais non ! a la place j'ai : ['SPEED', 'SPEED', 'SLOW', 'JUMP', 'UP', 'DOWN']
root.adresse
#et ces enfant devrait avoir
# ['INIT', 'SPEED']
# ['INIT', 'SLOW',
# ['INIT', 'JUMP',
# ....
# ??????????????
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment