2019-03-14 20:53:48

So I have some time now, so I went and played around with some Python code, that writes a list of values to a file.
The code takes a starting value, and a multiplier. Then, it reduces the value in such a way so that the value reduces the most at first but gradually slows down.
I'm interested in this kind of thing.
Any guesses?

Code:
import time, sys
sys.stdout=open("data.txt", "w")
class enemy:
def __init__(self, defense=10):
  self.defense=defense
def reduce_value(self, val, m=2):
  lst=range(self.defense)
  mul=val*m
  if mul==1:
   mul=m
  if val<=val*mul:
   val+=val/10
  for i in lst:
   if mul==1.0:
    mul=1.1
   print("{0}, {1}".format(val, mul))
   val-=val/mul
   print(val)
   mul+=0.5
  return val
tst=enemy(10)
print(tst.reduce_value(10, 1))

2019-03-14 23:29:50

well, the equation might be something like this:

(movedammage/5)+str/magicattacak-enemydefense/magicdefense+stab if aplicable.
Probably more things but there's some starts.
----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-03-15 02:41:43 (edited by Ethin 2019-03-15 02:42:24)

I am confused on why you are overriding sys.stdout. I have never encountered a python program where someone has deliberately override any of the standard IO streams and frankly don't see why you'd ever want to when you can just invoke the write() function on the file and then close it at the end. (Always close open files or file descriptors. You never know if your OS will clean them up for you. Or use context handlers, which follow a form of RAII.)

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2019-03-16 20:05:20

Heh, it was what I did when I wanted to print all the data out.
Since the print() function is like calling file.write, but it also uses str() on the object if it's one which I like.
Anyway, sometimes, I don't wanna convert all the print() statements to writes.
It's a quick and dirty thing I guess you can say.