Staredit Network > Forums > Technology & Computers > Topic: Help me program
Help me program
Dec 12 2010, 6:29 am
By: Sand Wraith  

Dec 12 2010, 6:29 am Sand Wraith Post #1



If ever I said I was any good at programming, consider the statement null and void.

I need some help with Python (3.x; 3.1.2 specifically) - using Windows 7 (and, thanks to the modules I'm using, it's only compatible with Windows).

Between style, syntax, and algorithms, my code is usually pretty horrendous. These factors do not help at all, especially for my current program.

ATM, I'm trying to program a simulator (for a zombie apocalypse? I dunno). All I've got are a map, some functions for running each turn, some functions for adding shit, terrain, and units.

My biggest problem right now is memory handling and efficiency. My units are implemented as such: their is a base unit class, and I have several (hundreds, sometimes) objects of the unit class. The class has functions for moving the units, which follow a convoluted and ridiculous pathing algorithm to determine where to move next.

I have a feeling that somewhere along the way of all of this, I'm leaking a massive fuckton of memory. My reasoning? I'm running a Windows 7 64-bit, i7-720 Quad Core, 9GB DDR3 machine and after just a few thousand turns (or something) with a few hundred people walking around, my computer gets whacked. I only noticed this just now: while I was running a test (probably a hundredth test or so), reaching into some 3000 turns with a few hundred persons on the field, my entire desktop flickered and changed to the default Windows 7 style. It only changed back after I went into the task manager and stopped multiple (several tens, at least) instances of "python.exe", each one taking some 17,000K of memory (or something).

In any case, I'd like to get some help with cleaning up my code, since, frankly, I'm too inexperienced to cut down on memory costs and leaks and shit.

The *.py files should be in the same folder. Use Python 3.x (I dunno if the specific version number will matter much; I'm using 3.1.2). Use Windows to test.
I've been testing for syntax/run-time errors using IDLE in interactive mode, writing the actual code in IDLE script mode, and also quick-testing by running the script by double-clicking "i dunno 2.py" (hurrdurr).
I've also had the "iD_mapLegend.py" file open simultanesouly.

Hope the info helps. I hope you can help (although my code is pretty terrible; I don't blame you if you tell me to clean up my style and such :P ).

http://pastebin.com/kqdVmTSY - main, "i dunno 2.py"
http://pastebin.com/dcJWUH4p - module, "iD_mapLegend.py"

Post has been edited 1 time(s), last time on Dec 12 2010, 7:49 pm by Sand Wraith.




Dec 12 2010, 7:35 pm CecilSunkure Post #2



Python should have a built in garbage collection system to prevent memory leaks. Since Python is a high level programming language, you don't get to mess with anything low-level and don't need to worry about cleaning up your memory allocation. I haven't looked at your code, but it's something else that is causing problems.



None.

Dec 13 2010, 7:52 am ShadowFlare Post #3



It is probably whatever is causing it to run more python processes. Are you running any external scripts in your code? Not just including them, but actually running it as a separate process.



None.

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[10:13 pm]
Oh_Man -- No APM in chess. Computer just outthinks the human by seeing more moves ahead and more permutations
[10:12 pm]
Oh_Man -- U reckon? Kasparov waa defeated by computer decades ago
[05:47 pm]
NimoStar -- If its any consolation, the human brain would still mop the floor with this bot if it wasn't limited by the mechanical interface
[05:34 pm]
NimoStar -- Well. The bot didn't come up with any new strategy. It just has superhuman micro. Hard to beat that. I reckon even the simplest dedicated chess engines are unbeatable for humans now.
[02:13 pm]
Oh_Man -- all g
[10:54 am]
NudeRaider -- Oh_Man
Oh_Man shouted: NudeRaider did u watch the entire video? it's not one game. it's currently dominating the ladder at number 1 position. do ur research first!
Oops, caught me there, no I haven't. :( I was imagining how the game went. Sorry for that. Watching it now. brb
[10:52 am]
NudeRaider -- NimoStar
NimoStar shouted: They were not "Unprepared" that was their fifth loss in a row against the bot. The other replays are also available
that doesn't mean he was prepared. When humans come around with new strategies it often takes weeks until the pros figure out how to shut it down. Oh_Man that's certainly a way more convincing argument for micro being "too good to beat".
[09:43 am]
DiearAnother -- wirefram
[08:35 am]
NimoStar -- Well, pros showed that long ago... half of zerg pros just ling muta rush
[08:35 am]
NimoStar -- " its shown is that you can trade 1000's of apm to make up for lack of strategy"
Please log in to shout.


Members Online: DarkenedFantasies, Symmetry