From 7c2d2df9dda95c64a546c571b3657829f9190245 Mon Sep 17 00:00:00 2001 From: Enzo De Carvalho Bittencourt <ezdecarvalho@gmail.com> Date: Fri, 16 Jun 2023 00:11:53 -0700 Subject: [PATCH] revamped - not finished (but playable state) --- DARE.py | 330 +++++++++++++++++-------------- __pycache__/dice.cpython-311.pyc | Bin 4805 -> 4798 bytes 2 files changed, 178 insertions(+), 152 deletions(-) diff --git a/DARE.py b/DARE.py index 4e4f87e..90ad2d6 100755 --- a/DARE.py +++ b/DARE.py @@ -6,27 +6,16 @@ import dice import codecs import copy -""" -import threading - -class KeyboardThread(threading.Thread): - def __init__(self, input_cbk = None, name='keyboard-input-thread'): - self.input_cbk = input_cbk - super(KeyboardThread, self).__init__(name=name) - self.start() - - def run(self): - while True: - self.input_cbk(input()) #waits to get input + Return -""" - +#####################---INIT AND UTILS---######################### abc = "abcdefghijklmnopqrstuvwxyz" +##Inherit Dice, adds name support and latency (count) class SpecialDice(dice.Dice): def __init__(self, n, name): """init a special dice""" super().__init__(n) self.name=str(name) + self.count=0 #number of time this dice was rerolled return None def __str__(self): @@ -41,66 +30,37 @@ class SpecialDice(dice.Dice): def __lt__(self, otherdice): return self.n <= otherdice.n + def softReset(self): + self.reset(); + return None + + # I guess this is what u get when u don't do proper code dev lol + # But hey, overriding is the future, right Java ? + def HardReset(self): + self.reset(); + self.count = 0; + return None + class LatencyQueue(): def __init__(self): """init the Latency Queue""" - self.oneQueue = [] - self.twoQueue = [] + self.queue = [] - def add(self, elt, index): + def add(self, elt): """put elt in the indexQueue""" - if index == 1: - self.oneQueue.append(elt) - return None - elif index == 2: - self.twoQueue.append(elt) - return None - else: - return None + self.queue.append(elt) def move(self): - ret = self.oneQueue - self.oneQueue = self.twoQueue - self.twoQueue = [] + ret = "TODO" return ret def __str__(self): - return "2:"+str(self.twoQueue)+"1:"+str(self.oneQueue) + return "TODO" def __repr__(self): return "Latency Queue Object :"+str(self) -def logo(): - print( -""" -\033[38;5;195m -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣶⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣦⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⢴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠢⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⣼⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⡀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣿⣿⠽⠿⢛⢻⢟⡽⣛⣿⢿⣿⣿⣿⠿⣿⣿⣿⣿⣿⣟⣻⠿⣿⣻⣙⠛⠾⣄⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⢀⣽⡈⡋⠠⠀⡀⣈⢚⣥⢽⢫⢦⣷⣾⢋⣺⣷⣻⣿⠫⢿⣿⣿⣿⣖⡸⣿⣝⠿⣧⣘⡷⡀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⢿⣶⣾⣿⣿⣁⣣⣾⡞⠚⢂⡤⠂⠃⡗⢾⢿⣯⡾⢿⣿⣿⣿⣶⣿⡿⣿⡟⣓⢧⣛⡗⢹⣿⣿⣷⡀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠙⣿⠋⡿⠉⢩⣿⢟⣀⡍⠀⠀⠘⣿⣬⣶⣷⣿⣿⣿⣿⣝⣿⠇⠣⠿⣿⣶⠋⡽⢽⠽⢣⣿⣧⠑⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⢻⡀⠅⠀⢹⠟⠿⠊⢉⢀⢘⣮⣿⣿⣿⣿⣿⣏⡈⢙⣽⣛⡄⡇⠂⠘⢾⢟⡓⠒⠿⡁⢉⣿⡦⣇\033[38;5;193m - ██████ █████ ██████ ███████ - ██ ██ ██ ██ ██ ██ ██ - ██ ██ ███████ ██████ █████ - ██ ██ ██ ██ ██ ██ ██ - ██████ ██ ██ ██ ██ ███████⠀⠀⠀\033[38;5;214m ⠀⠀⠀⠀ -⠀ Dice As REssources (v0.1)⠀⠀⠀⠀⠀⠀\033[38;5;195m ⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠐⠐⠲⣦⣀⣄⡀⠀⡀⢀⢀⣠⣀⢆⡒⡀⢢⣶⣶⣶⠖⣴⠤⣆⣲⢖⣆⣶⣦⣤⣐⠒⠀⠀⠠⠠⣤⢶⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠂⠡⣿⣿⠦⣄⣒⣿⡁⢠⣍⡳⠈⢸⣼⣿⣽⣹⣿⡽⠉⢾⣷⣸⠙⢞⣝⡿⠲⣒⣀⠔⠋⢀⠃⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⢋⣦⡀⠀⠋⠁⠀⠀⠥⠀⠀⠁⢀⡀⡸⣿⣼⣳⢴⡻⡣⣄⡌⣿⣏⣶⠾⢓⠾⠶⠁⣁⣤⡤⠁⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠨⠿⣷⠀⠀⢀⠀⠀⠀⠄⠀⣴⡟⠻⣿⡊⡦⢮⢁⡅⠀⠁⠈⠁⠀⠀⣀⣤⣤⣶⣿⣿⠟⠁⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠁⠀⠀⢀⣀⣉⣉⡭⡻⢇⠀⢀⢠⣀⣤⣤⣶⣾⣾⣷⣿⣿⣿⣿⠟⠋⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠁⠀⠐⣦⣶⣚⠻⢿⣿⣿⣷⣗⣤⠊⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠟⣺⡟⡾⣯⣛⣿⣿⣿⣚⣛⣛⣿⡿⣛⠿⠛⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠛⠛⠓⠒⠋⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -\033[0m -""" - ) - +#Prints the main art def art(): f = codecs.open("art", "r", encoding="utf-8") art = f.read() @@ -118,12 +78,14 @@ def art(): ) return None +#Prints a line def line(): print("\033[38;5;240m"+50*"-"+"\033[0m") return None ask_history=[] +#Asks the player which actions does he wants to do def ask(symbol): out = input("\033[38;5;217m"+symbol+">\033[0m") return out @@ -139,28 +101,35 @@ if __name__=="__main__": S.PSIdicepool = [] S.PDiceTray = dice.DiceTray() #PHI DiceTray S.pDiceTray = dice.DiceTray() #pSI DiceTray - S.Latency = LatencyQueue() - S.PHIqueue = []#SpecialDice(2,"Ψ"),SpecialDice(6,"Ψ")] - S.PSIqueue = []#SpecialDice(2,"Ψ"),SpecialDice(6,"Ψ")] + S.Latency = LatencyQueue() S.thro = [] S.name = "" S.inroll = False - + + #Namespace where S object can be at any moments reverted to its old self Undoable = SimpleNamespace() Undoable.S = S Undoable.OldS = S Undoable.RedoS = S - #S.PDiceTray.add(SpecialDice(2,"Ψ")) + +#DEPRECATED + ##S.PHIqueue = []#SpecialDice(2,"Ψ"),SpecialDice(6,"Ψ")] + ##S.PSIqueue = []#SpecialDice(2,"Ψ"),SpecialDice(6,"Ψ")] +# + + #S.PDiceTray.add(SpecialDice(2,"Ψ")) ##INIT CLI art() +#Badly prints mlist i think def stupidPrint(mlist): out = "" for e in mlist: out += str(e)+" " return out - + +#Print the actual dice tray. def printDiceTray(): #This function crash if more than 26 dice are thrown #This won't ever happen, right ? @@ -181,32 +150,27 @@ if __name__=="__main__": sump += e.value sumpMax += e.n print("\033[0m") - print("Sum of\033[38;5;10m PHI\033[0m dice is :\033[38;5;217m "+str(sumP)+(" > " if sumP > sumPMax/2 else " <= ")+str(int(sumPMax/2)),end="\033[0m.\n") - print("Sum of\033[38;5;159m PSI\033[0m dice is :\033[38;5;217m "+str(sump)+(" > " if sump > sumpMax/2 else " <= ")+str(int(sumpMax/2)),end="\033[0m.\n") + print("Sum of\033[38;5;10m PHI\033[0m dice is :\033[38;5;217m "+str(sumP)+"\033[0m.") + print("Sum of\033[38;5;159m PSI\033[0m dice is :\033[38;5;217m "+str(sump)+"\033[0m.") #Todo : number of same dice + print("\n") def printallstat(S, ShowDiceTray=False): print("\033[38;5;214m PHI \033[38;5;10m [ "+stupidPrint(S.PHIdicepool)+"]\033[0m " ,end="") - if not S.PHIqueue: print("") #list is empty - else: - print("\033[38;5;64m < "+str(S.PHIqueue[0])+"\033[38;5;242m "+stupidPrint(S.PHIqueue[1:])+"< \033[0m " ) print("\033[38;5;214m PSI \033[38;5;159m [ "+stupidPrint(S.PSIdicepool)+"]\033[0m " ,end="") - if not S.PSIqueue: print("") - else: - print("\033[38;5;67m < "+str(S.PSIqueue[0])+"\033[38;5;242m "+stupidPrint(S.PSIqueue[1:])+"< \033[0m" ) - if S.Latency.oneQueue or S.Latency.twoQueue: # not empty - print("\033[38;5;202m LAT \033[38;5;242m 1[ "+stupidPrint(S.Latency.oneQueue)+"] 2[ "+stupidPrint(S.Latency.twoQueue)+"]") - + if ShowDiceTray: - print("\033[38;5;214m ROLL ") + print("\n\033[38;5;214m ROLL ") printDiceTray() if ShowDiceTray and S.thro: print("\033[38;5;242m DEL [ "+stupidPrint(S.thro)+"]\033[0m") +# +##HELP def helpDARE(args,S): """ USAGE : help [command name] @@ -232,40 +196,21 @@ on a specific command""" No command found '"""+str(args[0])+"""'""" ) return None - + +# +##MOVE def move(args,S): """ USAGE : move GM-purposed command. -move the LAT, PSI and PHI queue by one.""" +move the LAT queue, update pools.""" availDice = S.Latency.move() - #PHI dice update - if len(S.PHIqueue) == 1:#one dice control - mainly to not get shenaningans with next "elif" - S.PHIdicepool.append(S.PHIqueue.pop()) - elif S.PHIqueue:#List not empty - if S.PHIqueue[0].n+S.PHIqueue[1].n <= 8: #two first dice are d4 - S.PHIdicepool.append(S.PHIqueue.pop(0)) - S.PHIdicepool.append(S.PHIqueue.pop(0)) - else: - S.PHIdicepool.append(S.PHIqueue.pop(0)) - - #PSI dice update - if len(S.PSIqueue) == 1: - S.PSIdicepool.append(S.PSIqueue.pop(0)) - elif S.PSIqueue: - if S.PSIqueue[0].n+S.PSIqueue[1].n <= 8: #two first dice are d4 - S.PSIdicepool.append(S.PSIqueue.pop(0)) - S.PSIdicepool.append(S.PSIqueue.pop(0)) - else: - S.PSIdicepool.append(S.PSIqueue.pop()) - - #Update queues + #Update pools for e in availDice: if e.name == "Ψ": - S.PSIqueue.append(e) + S.PSIdicepool.append(e) else: - S.PHIqueue.append(e) - + S.PHIdicepool.append(e) S.PSIdicepool.sort() S.PHIdicepool.sort() return None @@ -273,6 +218,9 @@ move the LAT, PSI and PHI queue by one.""" def Nothing(args,S): return None + +# +##REDO def redo(args,S): """ USAGE : redo @@ -290,6 +238,8 @@ Nothing to revert !""" Undoable.S = Undoable.RedoS return None +# +##UNDO def undo(args,S): """ USAGE : undo @@ -305,10 +255,10 @@ Nothing to revert !""" else: Undoable.RedoS = deepcopy(Undoable.S) Undoable.S = Undoable.OldS - ##print("Undoable.S =",end="")##DEBUG - ##print(Undoable.S) return None +# +##EXITDARE def exitDARE(args,S): """ USAGE : exit @@ -323,7 +273,75 @@ all info about the current state.""" print(S.name+": ") printallstat(S, S.inroll) return None - +# +##ADD + def select(args,S,fromQueue=False): + """ + Selects dice, and removes them from dicepools, return selected dice. + Apply this to S.Queue if fromQueue is true + """ + #check for valid input first + if len(args) == 0: + print("At least one dice is expected.") + return None + + for d in args: + if d[0] != "p" and d[0] != "P": + print("Unknown dice '"+str(d)+"' !") + return None + try: + int(d[1:]) + except ValueError: + print("Unknown dice '"+str(d)+"' !") + return None + + # our input are valid !!! + PselectedDice=[] + pselectedDice = [] + + if not fromQueue: + first = S.PSIdicepool + second = S.PHIdicepool + else: + first = S.Latency.queue + second = S.Latency.queue + for d in args: #rem from pools + if d[0] == "p": + found=False + for e in S.PSIdicepool: + if e.n == int(d[1:]): + S.pDiceTray.add(e) + pselectedDice.append(e) + first.remove(e) + found = True + break + + if not found: #valid dices, but not in pool + print("Not enough Ψ"+str(d[1:])+" !") + first = first + pselectedDice + second = second + PselectedDice + return None + + elif d[0] == "P": + found=False + for e in S.PHIdicepool: + if e.n == int(d[1:]): + S.PDiceTray.add(e) + PselectedDice.append(e) + second.remove(e) + found = True + break + + if not found: + print("Not enough Φ"+str(d[1:])+" !") + second = second + PselectedDice + first = first + pselectedDice + return None + + return pselectedDice+PselectedDice + +# +##ADD def add(args,S): """add dice into tray""" #check for valid input first @@ -382,7 +400,9 @@ all info about the current state.""" S.PDiceTray.tray = [] return None return addedDice - + +# +##DEEPCOPY def deepcopy(S): SCopy = copy.deepcopy(S) SCopy.PHIdicepool = copy.deepcopy(S.PHIdicepool) @@ -390,14 +410,12 @@ all info about the current state.""" SCopy.PDiceTray = copy.deepcopy(S.PDiceTray) SCopy.pDiceTray = copy.deepcopy(S.pDiceTray) SCopy.Latency = copy.deepcopy(S.Latency) - SCopy.PHIqueue = copy.deepcopy(S.PHIqueue) - SCopy.PSIqueue = copy.deepcopy(S.PSIqueue) SCopy.thro = copy.deepcopy(S.thro) SCopy.inroll = S.inroll - ##DEBUG##print("Copy :",end="") - ##print(SCopy) return SCopy +# +##ROLL def roll(args,S): """ USAGE : roll [dices] @@ -438,6 +456,8 @@ updated.""" printallstat(S, S.inroll) return None +# +##REROLL def reroll(args, S): """ USAGE : reroll [dice] [throw [dice]] [add [dice]] @@ -458,19 +478,19 @@ Sum of PHI dice is : 4 <= 5. Sum of PSI dice is : 7 > 5. One could then type : -reroll ac throw b add p4 +reroll ac remove b add p4 This would : reroll a and c dice, -throw the b dice +remove the b dice add a psi4 dice into the final roll if you only want to add or throw dice, you can type -reroll add ... -reroll throw ... -reroll throw add... +reroll ... add ... +reroll ... remove ... +reroll ... remove ... add ... The ordering of the keywords doesn't matter.""" #UNDO MGMT @@ -488,36 +508,51 @@ more info""" doAdd = False doThrow = False + + #which index are dice to be added in our args list addIndex = -1 + #which index are dice to be trashed in our arglist throwIndex = -1 + + #List of dice to add addList = [] + #List of dice to trash throwList = [] + + #Remaining dice to reroll rerollList = args + #error checking if args.count("add") > 1: print("Too much 'add' keyword. see \033[1m help reroll\033[0m to see\n correct formatting") return None - if args.count("throw") > 1: - print("Too much 'throw' keyword. see \033[1m help reroll\033[0m to see\ n correct formatting") + if args.count("remove") > 1: + print("Too much 'remove' keyword. see \033[1m help reroll\033[0m to see\n correct formatting") return None - + + #Populate addList accordingly and update rerollList if "add" in args: doAdd = True addIndex=args.index("add") addList=args[addIndex+1:] - rerollList=rerollList[:addIndex] - if "throw" in args: + rerollList=rerollList[:addIndex] + + #Populate throwList accordingly and update rerollList + if "remove" in args: doThrow = True throwIndex=args.index("throw") throwList=args[throwIndex+1:] rerollList=rerollList[:throwIndex] + ##After these two if, rerollList is OK, ##But it is certain that either "throw" or "add" appears in each other. + ##This is a hacky way to patch a stupid bug and idc doing it better : ) if "add" in throwList: throwList=throwList[:throwList.index("add")] if "throw" in addList: addList=addList[:addList.index("throw")] + #Indexing dice with abc index = 0 diceDict = {} for e in S.PDiceTray.tray: @@ -529,9 +564,11 @@ more info""" if doAdd and addList: addedDice = add(addList,S) - if not addedDice: + if not addedDice:#This shouldn't happen I think... + print("Argshs something awfully wrong happened qwq") return None + #Dice to remove allstrThrow = "" if len(throwList) > 1: for letters in throwList: @@ -550,18 +587,7 @@ more info""" if not(c in diceDict): print("no dice of index'"+c+"' !") return None - - numDice = len(S.PDiceTray.tray) + len(S.pDiceTray.tray) - if len(allstr) > numDice:#Should never happen - print(""" -Cannot reroll this much dice ! -You can at most reroll half of your dice. -Here, it would mean at most """+str(numDice//2)+""" dice.""" - ) - return None - - ##TODO Moar checking - ##Now, everything should be okay ! + ##Now, everything should be okay ! if doThrow: for l in allstrThrow: S.thro.append(diceDict[l]) @@ -579,11 +605,11 @@ Here, it would mean at most """+str(numDice//2)+""" dice.""" print(S.name+" rerolls !") printallstat(S, True) - - print("the roll is over.") - cont("[žInvokedFromRR]",S) + return None +# +##CONT def cont(args,S): """ USAGE : cont @@ -598,16 +624,9 @@ said roll is finished.""" all = S.pDiceTray.tray + S.PDiceTray.tray + S.thro all.sort() for e in all: - e.reset() - if e.n < 5: - if e.name == "Ψ": - S.PSIqueue.append(e) - else: - S.PHIqueue.append(e) - elif e.n < 10: - S.Latency.add(e,1) - else: - S.Latency.add(e,2) + e.Softreset() + S.Latency.add(e) + S.pDiceTray.tray = [] S.PDiceTray.tray = [] S.thro = [] @@ -616,17 +635,25 @@ said roll is finished.""" printallstat(S) return None +# +##TRASH def trash(args,S): """ USAGE : trash [dice] GM-purposed command. Trash dice as if they were rolled""" Undoable.OldS = deepcopy(Undoable.S) - add(args,S) - cont(["žInvokedFromTrash"],S) + selected = select(args,S) + if select == None: + print("No dice found !") + return None + for dice in selected: + ##print(SCopy) + S.Latency.add(dice) return None +##COMMAND LIST## COMMAND_LIST = { "exit" : exitDARE, "quit" : exitDARE, @@ -697,8 +724,7 @@ To get an explanation of a command""" print( """ No command found '"""+str(args[0])+"""' -try \033[1mhelp\033[0m to see command list."""#+str(Undoable.SOld.PHIdicepool) +try \033[1mhelp\033[0m to see command list.""" ) - line() diff --git a/__pycache__/dice.cpython-311.pyc b/__pycache__/dice.cpython-311.pyc index 3f4d4a1e549c1204f989db7a8bb600e25f4d0ce9..bd66aa5f770f06cb98d4abd2db56f06329a1f4dd 100644 GIT binary patch delta 36 scmX@Ax=)pRIWI340|NuY3WlDI+(k@`DwFG&Bv@P=gIqT+WKt0T0IGxu0ssI2 delta 43 zcmdm|dQ_ErIWI340|NuY<QbM5xr>+>wI|mxNpPoRCa1<1<>%z27Hyuzq#^(S2B8e0 -- GitLab