Currently Online

Latest Posts

Topic: Soldier auto-fighter in webassembly

leklachu
Avatar
Topic Opener
Joined: 2021-12-08, 20:21
Posts: 8
Ranking
Pry about Widelands
Posted at: 2021-12-11, 21:27

Hi, I was browsing things about soldier balance, and thought about a program to simulate fights to see the balance between tribes.

Turns out einstein13 has already done that, but I fancied the idea for a hobby project anyway, and I now have the first vaguely-meaningful draft.

Mine's written in Rust, and I got it to work on the web! So it should run fast but accessible to all. (Currently I get a total refresh in 1s; seemed to take about 4s from fully cold start.) The current version very simply pits 100,000 of each tribe, max level against each other tribe, half the battles being first-hit by each tribe, then chucks those results in a table. Underneath, the code is also calculating the % remaining health of each team and the mean/stdev of individual soldiers' remaining healths. (But I haven't wired that up to the html display yet.) I have a few more ideas planned too, such as soldiers in a line: fight the soldiers one by one keeping the survivor to fight with his remaining health.

First beginnings at:

https://wide-fighter.netlify.app/
and source at https://github.com/leklachu/wide-fighter

einstein13's python script

https://github.com/einstein13/wl_soldiers
https://github.com/einstein13/wl_soldiers_exact

Some relevant forum threads,

https://www.widelands.org/forum/topic/4351/
https://www.widelands.org/forum/topic/1937/?page=2#post-16589
https://www.widelands.org/forum/topic/2910/

It's an irregular hobby...

...but if anyone finds it fun/useful I'll do my best to get it to a sort of v1, at least with customisable fields and some more results. I'll try anyway, but time for me is quite unpredictable.

And if anyone wants to help with layout/styling (even just a css file) I can hopefully wire that into the program. (It's built with https://yew.rs/ for the web framework)


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2726
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2021-12-11, 21:50

nice work. It is very fast for doing 100000 rounds. However if you swap the first hit after half of the fights the results table would be symmetric (with infintie fights) to make it more meaningful I would prefer to not swap the hit and have the values for a defending soldier and an attacking soldier.
Furthermore an interface to edit the values of each soldier would be nice.


Top Quote
leklachu
Avatar
Topic Opener
Joined: 2021-12-08, 20:21
Posts: 8
Ranking
Pry about Widelands
Posted at: 2021-12-11, 21:56

Thanks

Furthermore an interface to edit the values of each soldier would be nice.

Yep, if I don't get stuck on how to do html input I'll hope to have that soon-ish

to make it more meaningful I would prefer to not swap the hit and have the values for a defending soldier and an attacking soldier.

underneath the simulation is also calculating that already, so once I wire up making lots of tables on the UI, I should be able to get that in easily. Just might become a long page to scroll with everything! until I learn how to do multiple pages or something...


Top Quote
leklachu
Avatar
Topic Opener
Joined: 2021-12-08, 20:21
Posts: 8
Ranking
Pry about Widelands
Posted at: 2021-12-12, 02:18

to make it more meaningful I would prefer to not swap the hit and have the values for a defending soldier and an attacking soldier.

Done.

v0.2 is here!

https://wide-fighter.netlify.app/

That's now displaying all the results my simulator gives - I hope I put everything in the right place!

v0.3 will focus on allowing user input to customise stats and levels


Top Quote
kaputtnik
Avatar
Joined: 2013-02-18, 20:48
Posts: 2535
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2021-12-12, 10:47

Very nice!

You know the wikipage about Soldierlevels?

Maybe we can integrate this in our website?

  • The easiest solution would be to make the output additionally available as Wikisyntax and copy paste the output to our wiki.
  • Another, probably better, solution would be to create a django app which can be a part of our website source. But i don't know much about rust, or if it works on our server.

Top Quote
leklachu
Avatar
Topic Opener
Joined: 2021-12-08, 20:21
Posts: 8
Ranking
Pry about Widelands
Posted at: 2021-12-16, 14:58

Thanks face-smile.png

You know the wikipage about SoldierLevels?
Maybe we can integrate this in our website?

Sounds great! For wiki syntax, which seems to be Markdown, it shouldn't be too hard for me to get the results output either to a console or even on the web page as tables that can be copy-paste into the wiki. There's no point overwhelming the wiki with stats though, so maybe someone should decide what's actually helpful to have there - then have a link to the app for the rest.

The app itself is just a skeleton html file, loading some javascript glue, loading a webassembly module. I think in principle I can set the the app to load into a particular html <div>, rather than the whole page, and then if someone can put the js and webasm modules on the server and put the necessary html line in the wiki page (I didn't see a way for raw html in the wiki syntax* - probably good for security reasons), the app could be loaded into the wiki. That could turn out easy or hard.

I'm afraid I haven't got much time at the moment though.


I also hit problems getting user input to customise the soldier stats, and it might have to wait some time now till I'm able to get that sorted. I'm happy to give pointers to anyone who wants to try fixing it themselves (and the source is on Github), and I'll get to it myself sometime... no promises when though.


* huh, looks like this forum might allow putting raw html into messages. I wonder how well that's sanitised... face-upset.png


Top Quote
kaputtnik
Avatar
Joined: 2013-02-18, 20:48
Posts: 2535
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2021-12-16, 16:06

leklachu wrote:

* huh, looks like this forum might allow putting raw html into messages. I wonder how well that's sanitised... face-upset.png

We allow only minimal tags and attributes


Top Quote
mxb2001
Avatar
Joined: 2019-05-20, 18:49
Posts: 280
OS: Linux
Version: 1.2
Ranking
Tribe Member
Location: The land of the thirsty spider
Posted at: 2021-12-20, 06:04

Poor Empire! Those legionaires aren't a match for anyone.


--
To Boldly Go Where No Man Has Gone Before

Top Quote
leklachu
Avatar
Topic Opener
Joined: 2021-12-08, 20:21
Posts: 8
Ranking
Pry about Widelands
Posted at: 2021-12-24, 22:33

We allow only minimal tags and attributes

Ah great.

v0.3 is here

As promised, some customisation. Forgive the terribly clunky interface, I can't make sense of input in yew-rs, but at least buttons work so I used those. This means actually customising the numbers within levels is still out of reach - but you can set up your fighting arena with standard soldiers of any training level now!

https://wide-fighter.netlify.app/

Bugs expected in the UI; the core simulator should still be sound. You can report bugs here in this thread or on the app's github: https://github.com/leklachu/wide-fighter

Future development

  • I'm still hoping to get fully-customised fields working... one day.
  • some more ideas... might happen
  • maybe we can come up with some workable idea re: widelands wiki integration

Happy Christmas everyone. This is apparently how I recover from COVID on Christmas Eve face-wink.png


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2726
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2021-12-25, 01:20

Hey great work.
merry christmas as well from my side and I wish you full recovery soon .


Top Quote