1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Age of Sigmar Battle Simulator Development thread

Discussion in 'General Hobby/Tabletop Chat' started by ravagekitteh, Apr 21, 2019.

  1. ravagekitteh
    Skink Chief

    ravagekitteh Well-Known Member

    Messages:
    1,577
    Likes Received:
    2,874
    Trophy Points:
    113
    Calling all programming nerds!

    For a while now I’ve been working on an Age of Sigmar Battle simulator. You input the units, how strong they are, what they are equipped with etc, and it simulates a battle with randomised dice rolls, result modifiers, special abilities etc. It’s fairly rudimentary, and there aren’t many units on it yet, but I thought it might be a nice thing to share on here.

    However, as nice and trustworthy as I know you all are, I’d rather not just leave a copy on here free for all of you to mess with.The problem is though, in order to change the unit, you have to actually edit the program itself. Ideally I want some way of putting the file on here, and locking it down such that you can edit the specific parts you need to, but can’t touch anything. However, if there is an alternative method that allows you to do it from within the program without editing it, that would be fantastic.

    So I need any programming experts here’s advice if possible! I will list some of the key details below:

    Because my programming skills are pretty poor, the program is made with python. It is very haphazard, as my technique is more to go with what works, rather than necessarily the cleanest, most efficient route. However, if you have any suggestions that involve overhauling the program completely (eg transporting it over to another programming language) I may politely tell you to f*** off. Without wanting to cause offense, I do not have the will to learn a new language at this stage, and I have spent to long with the existing method to be willing to change it dramatically. I’m happy to add in features, but not if they are too all encompassing or require a complete change in how the program works. This is supposed to be for fun, I’d rather not have this turn into a full blown project! :)

    In terms of how it works, in order to supply the data for each unit, you go onto a certain section of the program and edit some of the functions. Each unit has a function (eg Saurus_Warriors(“attack”)), and to change it you simply have to change the prefix (eg Skinks(“attack”)). You do the same for defending, and then you jus swap them around to simulate their retaliation. The problem is, this requires actually going into the code and manually changing it, and I’ve not been able to find a way around that. My only though would be to have an input/if statement section that lists out all possible combinations (attacker = input(which unit is attacking?), if attacker == Saurus Warriors etc), but that would take up a lot of space so I’d prefer if there was another way. Alternatively, if there was a way to lock down the entire code with the exception of the areas that you’d need to change, that would be ideal. And most importantly, I’d need to know how best to actually post the program onto the forum in the first place, ideally in an edit locked way that I can still update it nobody else can (again, sorry for lack of trust but better to be safe than sorry)!

    I’d really appreciate if anyone skilled at programming could help in any way. It might not be the most polished program, but it would at least be a nice tool for the community to use, and would give it a purpose outside of my own personal use!
     
  2. Aginor
    Slann

    Aginor Fifth Spawning Staff Member

    Messages:
    12,249
    Likes Received:
    20,130
    Trophy Points:
    113
    You could read the variables from a CSV file.
    IIRC python comes with easy ways to parse CSV.
    XML could work as well.
     
  3. ravagekitteh
    Skink Chief

    ravagekitteh Well-Known Member

    Messages:
    1,577
    Likes Received:
    2,874
    Trophy Points:
    113
    Perhaps I overstated my programming abilities. Basically, within Python I am moderately skilled, at least in terms of what the simulator requires. However, outside of that, I think you can basically assume I know jack squat about anything! :oops::D I’ll try not to act like too much of a technophobe, but some broader guides might be in order. I apologise for my inevitable future incompetence!
     
  4. Aginor
    Slann

    Aginor Fifth Spawning Staff Member

    Messages:
    12,249
    Likes Received:
    20,130
    Trophy Points:
    113
    Ok, no problem.
    There are several ways to do this.
    It has been a while since I used Python, but I remembered something and just looked it up on Stackoverflow. :D
    You can call functions from within a list, like this:


    def one():
    print "1"

    def two():
    print "2"

    def three():
    print "3"

    l = [one, two, three]

    for item in l:
    item()


    The above code should print:
    1
    2
    3



    That way you can just "program" the sequence and call all your functions after one another.
     
    Paradoxical Pacifism likes this.
  5. ravagekitteh
    Skink Chief

    ravagekitteh Well-Known Member

    Messages:
    1,577
    Likes Received:
    2,874
    Trophy Points:
    113
    That seems pretty good, thanks. I’ll see what I can do with it.

    In the mean time, how would you recommend getting the program onto the website?
     
  6. Lord Agragax of Lunaxoatl
    Slann

    Lord Agragax of Lunaxoatl Eleventh Spawning

    Messages:
    8,892
    Likes Received:
    19,884
    Trophy Points:
    113
    If you want to load it to the forum so everyone can use it, the only way I can see would be to zip all your files up into a single compressed package and attach it as a file to the post (just checked that and zip files can be added). Luckily Python files don't take up that much space even when they aren't zipped so should be within the 7.9MB limit
     
    Last edited: Apr 22, 2019
  7. Lord Agragax of Lunaxoatl
    Slann

    Lord Agragax of Lunaxoatl Eleventh Spawning

    Messages:
    8,892
    Likes Received:
    19,884
    Trophy Points:
    113
    I agree here - saving everything to file and reuploading everything from the file every time it's called would make things easier.

    In fact I've been working with both XML and CSV at the moment on my Third Year Project - here's some helpful pages I've found:
    https://docs.python.org/3/library/xml.etree.elementtree.html
    https://realpython.com/python-csv/

    Just a question - does your program have a GUI as part of its functionality? Because if so you could add a separate page that would allow the user to input new unit stats and save them to the file at UI level rather than having to edit the program, and on the battle page you could have two dropdown lists that load all the unit names from the file, allowing you can use to choose the two units who are going to fight each other quickly.

    I know you've already probably got it sussed, just seeing how I can help here.
     
  8. Aginor
    Slann

    Aginor Fifth Spawning Staff Member

    Messages:
    12,249
    Likes Received:
    20,130
    Trophy Points:
    113
    EDiT: sniped!!

    To make it usable by others you would either have to provide an interface to use the program (like a web server calling the python script in the background) although that would of course require hosting it.

    Or just put the program in a zip file to download.

    Since you don't want to give everyone the source code, you have to change the program in a way that it reads all the required parameters from a configuration file, such as an XML or CSV.

    Then you should be able to provide the compiled bytecode that everyone can run, they just have to build their own configuration file(s).

    Here is a tutorial about reading a CSV file in python.
    https://www.programiz.com/python-programming/reading-csv-files

    So what you have to do is:
    At the beginning of the program, read in the file(s).
    You could have one file for unit definitions (weapon stat lines and special abilities like extra attacks or rerolls) and another one for the simulation sequence.

    The program now has its parameters, so it knows who attacks and when.


    One final note: If you are not going to try and sell the program to anyone, you might consider making it open source and put it on GitHub.
    That way people can contribute, and you can keep track if your issues, versions and so on.
    Please don't take this as an offence, but if you are a beginner then what you wrote isn't that special, so it is unlikely that someone will steal it and get rich using it. Until it reaches a certain complexity it is probably easy to code a very similar program, at least for anyone with a background in software development.
    So from that point of view it really doesn't make much sense to be very protective of your software.
     
  9. ravagekitteh
    Skink Chief

    ravagekitteh Well-Known Member

    Messages:
    1,577
    Likes Received:
    2,874
    Trophy Points:
    113
    I think I might have it. Just to check, there's no way you guys can edit the source code or follow it back to the origin through a zip file is there? (you can never be too careful - I'm not protective of the code from a sale's perspective, just don't want any roaming trolls to inadvertently f*** it up and I'd rather I didn't have anyone rummaging around in my personal files!)
     
  10. Aginor
    Slann

    Aginor Fifth Spawning Staff Member

    Messages:
    12,249
    Likes Received:
    20,130
    Trophy Points:
    113
    Well... I am not sure how well you can decompile Python byte code. I haven't tried that yet.
    But normally I'd say if it is all compiled and you didn't include sensible stuff you should be fine.
     
  11. ravagekitteh
    Skink Chief

    ravagekitteh Well-Known Member

    Messages:
    1,577
    Likes Received:
    2,874
    Trophy Points:
    113
    Well, in that case, here goes...

    It's very bare bones, no GUI or anything. Just type in the two units you want (You have to do sizes before the actual unit I'm afraid - changing that would mess it up), and watch them do battle. Some abbreviations for weapons are allowed (eg cb for clubs and boltspitters)

    Currently supported:
    Skinks
    Saurus Warriors
    Saurus Guard
    Saurus Sunblood
    Bloodletters
    Liberators
    Namarti Thralls
    Namarti Reavers
    Lotann
    Ishlaen Guard
    Dryads

    Let me know if A: it works and B: what you think!
     

    Attached Files:

  12. ravagekitteh
    Skink Chief

    ravagekitteh Well-Known Member

    Messages:
    1,577
    Likes Received:
    2,874
    Trophy Points:
    113
    Added in the Bastiladon. Assuming you guys think this is good enough, I'll probably make a separate thread for it to take requests and usage questions and leave this one for the development side of things. Which sub-forum do you think would be best?
     

    Attached Files:

  13. Canas
    Slann

    Canas Ninth Spawning

    Messages:
    6,800
    Likes Received:
    10,462
    Trophy Points:
    113
    There are tools for decompiling. Though I have no idea how good those are and how much spagethi you'l end up getting. Usually the thing "preventing" people from doing it is that the license says you can't (and more importantly the threat of being sued if you do).

    I'l have a look at it later, though I can't say I'm a fan of python so the amount of advice I can give is limited.
     
  14. ravagekitteh
    Skink Chief

    ravagekitteh Well-Known Member

    Messages:
    1,577
    Likes Received:
    2,874
    Trophy Points:
    113
    It’s not so much people getting hold of the code and editing it that I don’t want. By the looks of things the file I’ve posted is now independent of the version I have in my own personal files, so at worse case I can just replace it if needs be. It’s more people somehow managing to get inside my own personal files through it that would concern me, but once again, it seems to be independent, and I haven’t knowingly included anything that would allow that, so I’m hoping it should be fine.

    I’m probably going to stick the main thread for in in the Seraphon discussion forum, but I wasn’t sure if it might warrant a pin? I just think it would be a nice tool for the community, and it would be a shame if people missed out on it because it was buried under a hundred other threads
     
  15. Canas
    Slann

    Canas Ninth Spawning

    Messages:
    6,800
    Likes Received:
    10,462
    Trophy Points:
    113
    Noone's going to screw with your personal files as long as you upload it like this unless you upload some really weird stuff. It'd be a genuine achievement if you managed to upload this in such a manner they'd screw with your own personal stuff :p. Worst case they'l make their own weird version of it and use that to spam others with it.

    As others suggested, a git repo could be a great idea, if you set it up right others can alter the code and then ask you to review it and see if you want their alterations included in your own code (and git will manage al the merging and whatnot for you). That does require a bit of understanding of coding though so given your claims of being an absolute novice that might be a bit much for now. Even if a more experienced programmer helping with cleaning up the code might be beneficial.

    As a general remark, try splitting up your code over multiple files in a sensible manner. A single 2000+ line file is horror to maintain :p
     
  16. Aginor
    Slann

    Aginor Fifth Spawning Staff Member

    Messages:
    12,249
    Likes Received:
    20,130
    Trophy Points:
    113
    I haven't had the chance to run it yet (haven't been near a PC with python) but I did have a look at your code.

    I haven't coded in Python in quite a while, but as far as I can see your code has two main problems I think.
    One is scalability. It isn't possible to add new units without touching quite a lot of lines.
    You also seem to have quite a bit of redundancy in there that you could avoid.
    And you have a lot of variables and hard coded values. I am a bit blurry with the details but I think you should be able to use arrays to get rid of some of those.
    You also use a lot of globals, in fact I think all your variables are globals. That is a bit dangerous and might lead to problems in the future.

    Hope this helps. :)
     
  17. ravagekitteh
    Skink Chief

    ravagekitteh Well-Known Member

    Messages:
    1,577
    Likes Received:
    2,874
    Trophy Points:
    113
    In terms of sharing the code, I’m more than happy to do so, but I don’t think I’d want to make the core project itself collaborative. Lots of the changes won’t necessarily be clear and it would be difficult to coordinate who’s doing what, changing what, etc. If you want to have a go at doing your own thing with it by all means go ahead, but the main thing itself would be too much work to get others onboard and able to help. Splitting up my code probably would have been a good idea, but I think it’s a bit late now to start changing that side of things!
    Scalability I haven’t encountered any real problems with yet, other than that the program is massive! There is also a fair bit of redundancy, much of it left over from major changes. If I get round to it, I may get rid of it, but right now I’d rather err on the side of caution and leave it in case I ditch something important! I’m probably going to start making the move to arrays with keywords and such - at some point I may add the “support” role in for aura effects and other stuff, so that will be useful. As for globals, I’m not really sure how to get rid of them! My function based technique and use of multiple variables across it makes it unavoidable as far as I’m aware.

    Thank you both for your feedback though! :)
     
    Canas likes this.
  18. Canas
    Slann

    Canas Ninth Spawning

    Messages:
    6,800
    Likes Received:
    10,462
    Trophy Points:
    113
    And this is why IT projects go 50 times over budget :p
     
    Aginor likes this.
  19. The Red Devil
    Stegadon

    The Red Devil Defender of Hexoatl Staff Member

    Messages:
    986
    Likes Received:
    1,500
    Trophy Points:
    93
    Development is about learning new things, in this job/genre you are never fully taught.

    Python has great file parsing capabilities, though I would most probably recommend JSON over CSV as its easier to add structure to it allowing you to easily handle complex cases and differences without having to resort to XML (which is just so last decade ;).

    With development refactor is a step you bearly avoid :bookworm:, especially these days with Agile development process. The best way to look at it is that Refactoring makes you into a better developer.

    I don't know if you develop purely for fun, or if you are learning it as a profession. Not that it matters, other than how deeply you want to dig into the theory.

    I have only dabbled some in Python for fun in the past, but I installed PyCharm and took a look at the source code.

    What I can see right away is that there is a lot of code duplication, what can really save you time is switching to classes. If you are serious about development, take a look at "design patterns" as well.


    After I installed PyCharm, I noticed an old file I had written. I believe this is from right after AoS came out, and the idea was to make a system to generate point values for the units. I then abandoned doing this in Python and moved to C#, though I can't find the source code atm. for that, though I should have a working version somewhere, just abandoned as I could not figure out a valid algorithm to base the points from. Note. The Python code cant be run in its current state, as it's not more than an hour or two of work laying down the idea of how it would behave.

    Now the reason I am mentioning this, and adding the file is that the file contains 151 lines of code, and with a loop added and the Unit class extended with a few more methods, let's say perhaps another 100 lines of code, it is able to load all Lizardmen units and handle their behavior. It would also be able to handle any other races/combinations if they are entered into a tuple variable.

    In short, you would loop over the tuple, and for each that should be used, you would initiate a Unit object. Then when you do the simulation, the different unit objects would be fighting against each other.

    As you can see, it could be worth the time looking into refactoring your code to do this since it would make the software easier to manage, and makes adding other units, or make change to units easier.

    You can take a look at this for a brief introduction to OO (Object Oriented) programming.
    https://www.makeuseof.com/tag/object-oriented-programming-explained/
     

    Attached Files:

    Aginor likes this.
  20. Canas
    Slann

    Canas Ninth Spawning

    Messages:
    6,800
    Likes Received:
    10,462
    Trophy Points:
    113
    God I wish people had less issues with using "old" stuff. The amount of things that get changed just cuz it's the new hip thing and google or something uses it so it must be genius, despite the old option working perfectly fine if not better at times, is astonishing in this industry.
     

Share This Page