Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Combat research - units with higher indexes win significantly more often?  (Read 2155 times)

Adonkares

  • Bay Watcher
    • View Profile

So I returned to playing Dwarf Fortress after a while, got my magma forges set up and thought about forming a military. But which weapon to choose? I stopped playing and wrote a program to research all the possible weapon combinations to find out which weapons are good against what.

I tested well over 10,000 1v1 and 10v10 fights at this point and one of the most glaring results was that units with a higher index tend to win against units with a lower index. What I mean by that is that a Dwarf numbered (5000) should win against a Dwarf with a number (1) 57.8% of the time.

I made a control with exact same weapons and armor and isolated starting positions and other variables. The bias is very clear. Units with a higher index number just win 7.8% more often. Does the game engine start moving the higher indexed units first which lets them strike first? What is happening? (Preliminary results suggest that equipment material and quality is the most important, short swords are superior vs armored targets and win with battle axes 55% of the time so the margin isn't large. The biggest factor in combat, equipment material gives a 39% better win rate over inferior material, then the higher unit index gives 7.8% win rate and better weapon type gives 5% better win rate.)

How is this possible? What am I missing? I'm going slightly crazy because this shouldn't be happening...
« Last Edit: July 23, 2022, 10:41:09 pm by Adonkares »
Logged

Schmaven

  • Bay Watcher
  • Abiding
    • View Profile

Particular weapons do differ in blunt vs sharp damage, and the type of attacks they can do, so I'm sure there is an optimal weapon to use in each specific scenario depending on opponent size and armor type.  Personally, I'd go with maces if you have to deal with a lot of undead, and axes or swords against the living.  Axes if you prefer more hauling jobs after the battle, and swords if less is preferrable.

As far as technical combat is concerned, any dwarf with legendary+5 skill with their equipped weapon will probably have a win rate in the high 99% range against anything that can feel pain, so training may be the most important factor. 
Logged

Adonkares

  • Bay Watcher
    • View Profile

I'm looking to mod a weapon system of my own and rebalance a few things if they appear too strong in testing.

So far testing has shown that if you create two identical groups of dwarves. Same skills and equipment. Then the group which was created last is going to win.

For example if you spawn the first team of 1000 full steel axe dwarves, unit numbers 1 through 1000 and a second team, unit numbers 1001 through 2000 then the second team wins 57.8% of the time based on unit numbers alone. So out of a 1000 1v1 arenas where one dwarf from each team fight, 578 wins will go to team 2. Exact same skill and equipment.

I tested this 10 times on a 1000 group so 10,000 results. I checked if the counting program I wrote is fine and it is. How is that possible?

I'm doing more testing to see if alternating unit numbers resolve this weird skew.
« Last Edit: July 24, 2022, 05:47:20 am by Adonkares »
Logged

Adonkares

  • Bay Watcher
    • View Profile

Double post :)
Logged

anewaname

  • Bay Watcher
  • The mattock... My choice for problem solving.
    • View Profile

DF seems to always start at the end of the item list and work back until an item qualifies for the search, so you are probably right that the entire second team gets to swing first (create a list of all units moving this tick, start from the end of the list and do their action). But, does the simulation start with the units adjacent to each other? And do the dwarfs have the same physical stats as well? If there was a distance to travel and if there were different physical stats, unit positions would get jumbled and then the index would matter little.
Logged
Quote from: dragdeler
There is something to be said about, if the stakes are as high, maybe reconsider your certitudes. One has to be aggressively allistic to feel entitled to be able to trust. But it won't happen to me, my bit doesn't count etc etc... Just saying, after my recent experiences I couldn't trust the public if I wanted to. People got their risk assessment neurons rotten and replaced with game theory. Folks walk around like fat turkeys taunting the world to slaughter them.

delphonso

  • Bay Watcher
  • menaces with spikes of pine
    • View Profile

The reliability of 7.8% does sound like a computing error. Are you willing to post your code for examination?

anewaname is right, specifically I think about construction orders tend to be 'last in, first out'. It wouldn't be surprising if this is a method that Toady prefers and would have to come into play when units fight too.

Adonkares

  • Bay Watcher
    • View Profile

DF seems to always start at the end of the item list and work back until an item qualifies for the search, so you are probably right that the entire second team gets to swing first (create a list of all units moving this tick, start from the end of the list and do their action). But, does the simulation start with the units adjacent to each other? And do the dwarfs have the same physical stats as well? If there was a distance to travel and if there were different physical stats, unit positions would get jumbled and then the index would matter little.
There is one tile of separation. All creatures had identical physical attributes equal to their racial average.
The reliability of 7.8% does sound like a computing error. Are you willing to post your code for examination?
My C++ version is a QT window app and I'm porting that code into a Lua script for DFHack. I'll share the Lua version when it's ready. Here's the output log with all death reports found in gamelog.txt
https://pastebin.com/4HuCEYQf
There is 1 tile of Y separation between units. Layout in the spoiler.
Spoiler: Arena layout: (click to show/hide)
You can count results using regex without a dedicated program:
Total units 2016, 1008 in each team:
"(Dwarf.*has bled to death|Dwarf.*has suffocated|Dwarf.*has been struck down)" shows 1014 total matches(deaths).
--Team 1 unit numbers from 1 to 1008
"DWARF ([1][0][0][0-8][ ]|[0-9][0-9][0-9][ ]|[0-9][0-9][ ]|[0-9][ ])" shows 542 matches for team1.
--Team 2 unit numbers from 1009 to 2016
DWARF ([1][0][0][9][ ]|[1][0][1-9][0-9][ ]|[1][1-9][0-9][0-9][ ]|[2][0][0][0-9][ ]|[2][0][1][0-6][ ]) gives 472 matches for team2.
There were 6 rooms where both units died so 6 undecided results.

There were 1002 decisive results and in 536 of those team2 won (team deaths - undecided results). This gives a 53.493% win rate.
« Last Edit: July 31, 2022, 03:52:33 am by Adonkares »
Logged

anewaname

  • Bay Watcher
  • The mattock... My choice for problem solving.
    • View Profile

I fooled around with an embark where unskilled dwarfs chased undead wildlife with axes and it was observable 5 out of 5 times, that when there was one tile empty between the opponents, the first unit to move into that empty tile did not attack, giving the opposing unit the first strike. So in your arena, it could be that the lower-index dwarfs move first, stepping into the empty tile between the dwarfs, giving the higher-index dwarf the first chance to cripple their opponent; and if the arena allows you to adjust the number of empty tiles between the dwarfs to either 0 or 2, you might see a reversal of the win/loss ratio.
Logged
Quote from: dragdeler
There is something to be said about, if the stakes are as high, maybe reconsider your certitudes. One has to be aggressively allistic to feel entitled to be able to trust. But it won't happen to me, my bit doesn't count etc etc... Just saying, after my recent experiences I couldn't trust the public if I wanted to. People got their risk assessment neurons rotten and replaced with game theory. Folks walk around like fat turkeys taunting the world to slaughter them.

Adonkares

  • Bay Watcher
    • View Profile

I fooled around with an embark where unskilled dwarfs chased undead wildlife with axes and it was observable 5 out of 5 times, that when there was one tile empty between the opponents, the first unit to move into that empty tile did not attack, giving the opposing unit the first strike. So in your arena, it could be that the lower-index dwarfs move first, stepping into the empty tile between the dwarfs, giving the higher-index dwarf the first chance to cripple their opponent; and if the arena allows you to adjust the number of empty tiles between the dwarfs to either 0 or 2, you might see a reversal of the win/loss ratio.
I followed your suggestion and checked the 0 distance and 2 tiles apart cases. It is, as you said, an issue with one group getting the first strike, or quite possibly, two first strikes off.
This changes the win ratio to 56.33% in favor of team 1.

Going back to the example with team 1 having units numbered 1 through 1000 and team 2 with units 1001 through 2000. If you look at what happens after each tick and the in-game reports are to be believed, then out of 2000 units, not even a quarter gets to move during each tick. It's a number roughly between 300 and 500.
So going tick by tick:
Tick 1: 430 Units from team 1 move. Interestingly enough the first unit to move is the last unit in team 1, so Dwarf 1000 moves first and it counts down from 1000 to 1 skipping more than half of team1.
Tick 2: Only 10 units from team 2 get to move which is plain weird. Then 290 more units from team 1 move.
Tick 3: 230 more units from team 2 and after than 200 units from team 1.

In every in-game tick except for the first one it is team 2 who moves first, so the units added last, but crucially in the first 2 ticks 60% of team 1 moves and only 1% of team 2 gets to do anything. The game somehow splits the units perfectly by their teams and the action priority goes to highest numbered units of each team. There's some randomness involved with the game trying to alternate between giving movement priority to each group.

So it's not as simple as one whole team moving first and then the other. I'm going to test team 1 with even numbers and team 2 with odd and other configurations.

Logged

delphonso

  • Bay Watcher
  • menaces with spikes of pine
    • View Profile

This is important research as the results of it should apply a 6~% adjustment to test results from the past, which is pretty significant.

Drakonis

  • Bay Watcher
    • View Profile

I can sense a review on weapons and armor effectiveness in the near future...
Logged

anewaname

  • Bay Watcher
  • The mattock... My choice for problem solving.
    • View Profile

Considerations and theorizing:
- Units in DF rarely move into the same tile unless there is no other path or they are attempting to grapple. I think this is because when a unit has decided to move into a tile, they effectively have "claimed" that tile even though it may take them a few ticks to move into it.
- When the units were placed on the map, different bits of code may have ran or not ran as part of the "initialization phase". Specifically, Team 1 dwarfs were already on the map when Team 2 dwarfs were placed, so maybe placing a unit on the map triggers observation rolls for the units already on the map but not for the unit being placed, and so Team 2 maybe needed to wait until their first tick to get observations. My theory is that at the start of Tick 1, the highest index units moved first, with units 2000 to 1001 skipping their chance to choose a "move into that middle tile" action because they didn't know there was a enemy in sight, then units 1000 to 1 claimed that middle tile.
- When a unit is attempting to take an action in DF, I suspect they choose the action they are going to take (swing weapon, move to adjacent tile, etc) and as each Tick passes, they gain points toward their intended action/move based on agility, exhaustion, encumbrance, armor constriction, etc, until they reach the needed number of points. When dwarfs are placed on the map, they probably start with enough accumulated points to move on Tick 1, but maybe a failed armor_user roll increases the number of points needed and maybe about half of Team 1 failed their armor_user rolls so they didn't get enough points to move until Tick 2. If you test with legendary or no armor_user skill, the percentage of Team 1 that moves in Tick 1 might change significantly. There must also be rolls regarding bravery, and maybe dwarfs can hesitate in combat instead of rushing forward or fleeing.
- Even in the few examples I watched, when unit A moved into the middle tile, unit B took their swing within 1 to 3 ticks. Most weapons have a ATTACK_PREPARE_AND_RECOVER value of 3 ticks to prepare an attack. I suspect most of Team 2 didn't move because instead they began preparing their attack against their chosen opponent who was currently moving into the middle tile.
- Given the above, the ten Team 2 dwarfs that did move first may have been the ones that rolled very well while their opponents rolled very poorly, so they effectively were able to gain a tick and chose to take the move into the middle tile.

« Last Edit: August 05, 2022, 04:35:58 am by anewaname »
Logged
Quote from: dragdeler
There is something to be said about, if the stakes are as high, maybe reconsider your certitudes. One has to be aggressively allistic to feel entitled to be able to trust. But it won't happen to me, my bit doesn't count etc etc... Just saying, after my recent experiences I couldn't trust the public if I wanted to. People got their risk assessment neurons rotten and replaced with game theory. Folks walk around like fat turkeys taunting the world to slaughter them.