Shuffle based randomness in battle

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Message
Author
Mitten.O
Programmer
Posts: 255
Joined: Sun Apr 06, 2014 4:15 pm

Shuffle based randomness in battle

#1 Post by Mitten.O »

This patch takes a small step towards addressing this thread:
viewtopic.php?f=6&t=8761

It makes battles shuffle based.
What that means that all participants are put in a random order
and then everyone gets a round.
This is repeated three times.

I chose to call one shuffle a "bout", since the words turn and round were taken.
Events are displayed as bout.round in the combat log.

Does this seem beneficial?
Attachments

[The extension patch has been deactivated and can no longer be displayed.]

Any code by me in this post is released under GPL 2.0 or later.

User avatar
MatGB
Creative Contributor
Posts: 3310
Joined: Fri Jun 28, 2013 11:45 pm

Re: Shuffle based randomness in battle

#2 Post by MatGB »

I like this plan. It'd almost certainly be better than the current system while still allowing the chance of the smalle rside pulling things off, I vote try it and revert if we dislike too much, or improve (I can't compile else I'd do so immediately).
Mat Bowles

Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Shuffle based randomness in battle

#3 Post by Geoff the Medio »

I get a client crash with the patch applied when moving an aggressive human player fleet into a system with a monster...

Call stack:

Code: Select all

 	FreeOrion.exe!std::_Uninit_copy<MapWnd::MovementLineData::Vertex *,MapWnd::MovementLineData::Vertex *,std::allocator<MapWnd::MovementLineData::Vertex> >(MapWnd::MovementLineData::Vertex * _First, MapWnd::MovementLineData::Vertex * _Last, MapWnd::MovementLineData::Vertex * _Dest, std::allocator<MapWnd::MovementLineData::Vertex> & _Al, std::_Nonscalar_ptr_iterator_tag __formal)  Line 431 + 0x11 bytes	C++
 	FreeOrion.exe!std::vector<AttackEvent,std::allocator<AttackEvent> >::_Ucopy<AttackEvent *>(AttackEvent * _First, AttackEvent * _Last, AttackEvent * _Ptr)  Line 1318 + 0x19 bytes	C++
 	FreeOrion.exe!std::vector<AttackEvent,std::allocator<AttackEvent> >::operator=(const std::vector<AttackEvent,std::allocator<AttackEvent> > & _Right)  Line 739 + 0x11 bytes	C++
 	FreeOrion.exe!CombatLog::operator=(const CombatLog & __that)  + 0xbd bytes	C++
>	FreeOrion.exe!CombatLogManager::SetLog(int log_id, const CombatLog & log)  Line 77 + 0x17 bytes	C++
 	FreeOrion.exe!CombatLogManager::serialize<boost::archive::binary_iarchive>(boost::archive::binary_iarchive & ar, const unsigned int version)  Line 97 + 0xf bytes	C++
End of log:

Code: Select all

2014-05-30 16:33:05,932 DEBUG Client : MapWnd::MidTurnUpdate
2014-05-30 16:33:05,932 DEBUG Client : MapWnd::InitTurnRendering
2014-05-30 16:33:05,979 DEBUG Client : MapWnd::InitSystemRenderingBuffers
2014-05-30 16:33:05,984 DEBUG Client : MapWnd::InitSystemRenderingBuffers time: 5
2014-05-30 16:33:05,984 DEBUG Client : MapWnd::InitStarlaneRenderingBuffers
2014-05-30 16:33:05,990 DEBUG Client : MapWnd::InitTurnRendering time: 58
2014-05-30 16:33:05,991 DEBUG Client : MapWnd::MidTurnUpdate time: 59
2014-05-30 16:33:06,017 DEBUG Client : (HumanClientFSM) PlayingGame.TurnProgress
2014-05-30 16:33:06,055 DEBUG Client : (HumanClientFSM) PlayingGame.TurnProgress
2014-05-30 16:33:06,306 DEBUG Client : (HumanClientFSM) PlayingGame.TurnProgress
2014-05-30 16:33:06,331 DEBUG Client : (HumanClientFSM) PlayingGame.TurnUpdate

Mitten.O
Programmer
Posts: 255
Joined: Sun Apr 06, 2014 4:15 pm

Re: Shuffle based randomness in battle

#4 Post by Mitten.O »

I was unable to reproduce your error.

The stacktrace is odd.
It jumps from trying to copy an AttackEvent to copying a MapWnd::MovementLineData::Vertex,
which has no relationship to it.
Was this a fresh game? Could there be some serialization mismatch?

I did find problem in my code:
the default constructor of an AttackEvent did
not initialize bout. Fixed that in this version.
Could conceivably help.
Attachments

[The extension patch has been deactivated and can no longer be displayed.]

Any code by me in this post is released under GPL 2.0 or later.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Shuffle based randomness in battle

#5 Post by Geoff the Medio »

Could have been a serialization issue... doing full rebuilds is problematic for me right now.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Shuffle based randomness in battle

#6 Post by Geoff the Medio »

After rebuilding, seems to work fine. Committed.

User avatar
MatGB
Creative Contributor
Posts: 3310
Joined: Fri Jun 28, 2013 11:45 pm

Re: Shuffle based randomness in battle

#7 Post by MatGB »

Had enough battles now with this patch applied that I can safely say I like it a lot, makes actions more predictable but still gives an element of randomness allowing for a lesser side a chance to survive, etc.

However, it's still not quite pyrrhic enough for my tastes. Just finished a major fleet action in which there were 25 ships involved, 13 of mine to 12 enemy, mine outclassed them but not by a huge amount.

It was a bit of a pyrrhic victory, more than half my fleet needs to withdraw to a drydock, but I didn't lose a single ship which given the size of the fight seems a bit off. How hard would it be to set a targetting priority when a ship fires? I'd say a default of "hit the enemy ship with the lowest current structure" or even better "hit the enemy ship that's taken the most damage" would increase the crunchiness of combat and make major fleet actions damaging to the winner (as, I think, it should be).
Mat Bowles

Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Shuffle based randomness in battle

#8 Post by Geoff the Medio »

Even with shuffle ordering, it should still be possible to destroy enemy ships before they get a chance to actually attack each round, so you could get lucky and tend to concentrate firing on the next ship that would have attacked. The next step I've proposed, moving to simultaneous actions of all ships, would reduce this type of result further.

Vegavis
Space Squid
Posts: 71
Joined: Sun Jan 12, 2014 7:04 am

Re: Shuffle based randomness in battle

#9 Post by Vegavis »

MatGB wrote:It was a bit of a pyrrhic victory, more than half my fleet needs to withdraw to a drydock, but I didn't lose a single ship which given the size of the fight seems a bit off.
Weren't you just lucky? Sometimes the damage is spread evenly, so all your ships are damaged and none lost; sometimes it's uneven, and you lose several ships while the rest are unscathed. ISTM the amount of random variation is reasonable (now; it was too much before the shuffle patch).

User avatar
MatGB
Creative Contributor
Posts: 3310
Joined: Fri Jun 28, 2013 11:45 pm

Re: Shuffle based randomness in battle

#10 Post by MatGB »

Not really, no, I've since fought several more large actions and the slightly larger/better side still has too much of an edge in terms of actually dead ships—I haven't done maths to see if the edge is there in damage taken, but let's face it damage taken is something you can largely discount with the current repair mechanics (and I'm playing without my 3/4 finished patch for that anyway).

Luck would be for a one off fight, but over multiple iterations I'm still rarely if ever losing ships, and when I do it's because they're outdated and planetary defences are one shotting them in the first round.
Mat Bowles

Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Shuffle based randomness in battle

#11 Post by Geoff the Medio »

The biggest impact of switching to shuffling combat ordering is probably for small combats. I'm not surprised that larger combats, where randomness will be generally more averaged out / away, aren't much affected...

That said, if you're consistently seeing no ships lost, maybe these fleets aren't so evenly matched? Various tipping points can exist, where doing slightly more damage means a kill in (for example) two instead of three hits, which can have an impact on results disproportionate to size of the increment... Have a look at the combat log?

And if damage is so easily discounted, perhaps having repair function should be more difficult / require some specific action to enable? viewtopic.php?p=68090#p6809

User avatar
MatGB
Creative Contributor
Posts: 3310
Joined: Fri Jun 28, 2013 11:45 pm

Re: Shuffle based randomness in battle

#12 Post by MatGB »

Geoff the Medio wrote:The biggest impact of switching to shuffling combat ordering is probably for small combats. I'm not surprised that larger combats, where randomness will be generally more averaged out / away, aren't much affected...
Oh, definitely, you can now send in smaller groups to take on sentries and stuff, but know you'll need repairs, before you needed overkill and would sometimes lose far more than was sane due to unlucky strikes.
And if damage is so easily discounted, perhaps having repair function should be more difficult / require some specific action to enable? viewtopic.php?p=68090#p6809
You don't need to persuade me of that one, I've basically got my Damage Control techs patch done, just need to redo costings, and it's a lower priority to the ship hulls balancing that I'm working on.

For starters, no damage control should work on the turn of the fight, which I've now got working.
Mat Bowles

Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Vegavis
Space Squid
Posts: 71
Joined: Sun Jan 12, 2014 7:04 am

Re: Shuffle based randomness in battle

#13 Post by Vegavis »

OK, MatGB is right. I just had a battle where a slightly stronger force killed 18 ships and lost none. That's too safe.

One way to increase death rates is to make ships concentrate their fire, perhaps by preferring fragile targets, or simply by having all ships shoot at one target.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Shuffle based randomness in battle

#14 Post by Geoff the Medio »

Vegavis wrote:OK, MatGB is right. I just had a battle where a slightly stronger force killed 18 ships and lost none. That's too safe.
Define "slightly stronger" and the actual fleet sizes / compositions, and maybe post the combat log?

Vegavis
Space Squid
Posts: 71
Joined: Sun Jan 12, 2014 7:04 am

Re: Shuffle based randomness in battle

#15 Post by Vegavis »

The fleets were:

Mine: total 280/520 weapons/structure
  • 5x Robotic III (Robotic Hull, 2x Laser 4, 2x Zortrium): 22/52
  • 5x Robotic III (Robotic Hull, 2x Laser 4, 2x Zortrium) with a +50% species: 34/52
Theirs: total ~113/564 (plus Organic Growth, minus damage from a previous battle)
  • 14x Griffon 1z-4 (Organic Hull, 1x MD4, 2x Zortrium): 6/32
  • 2x Griffon 1z-6 (Organic Hull, 1x Laser 2, 2x Zortrium): 7/32
  • 2 unarmed ships: 0/17
  • 2 planets with defense 10 and 5 (so they serve mostly as decoys)
So actually I had something like a 2.5:1 advantage, and winning with no losses is not so surprising.

Combat log (attacks by or on planets aren't logged, so I added them manually):

Code: Select all

AutoResolveCombat at Xocotl
AttackShipShip: attacker: Willow damage: 17  target: Mulu-lizi shield: 0 structure: 32
AttackShipShip: attacker: Willow damage: 17  target: Tenrec shield: 0 structure: 32
[Royal Demesne Xocotl II attacks Happiness for 10]
[Happiness attacks Royal Demesne Xocotl II for 17]
AttackShipShip: attacker: Happiness damage: 17  target: Vance shield: 0 structure: 27.6
AttackShipShip: attacker: Facade damage: 6  target: Dhanishta shield: 0 structure: 52
AttackShipShip: attacker: Alchibah damage: 17  target: Spallanzani shield: 0 structure: 29.6
AttackShipShip: attacker: Alchibah damage: 17  target: Muscida shield: 0 structure: 27
AttackShipShip: attacker: Chinchilla damage: 11  target: Tenrec shield: 0 structure: 15
AttackShipShip: attacker: Chinchilla damage: 11  target: Betelgeuse shield: 0 structure: 30.4
AttackShipShip: attacker: Burroughs damage: 6  target: Chinchilla shield: 0 structure: 52
AttackShipShip: attacker: Dhanishta damage: 17  target: Spallanzani shield: 0 structure: 12.6
AttackShipShip: attacker: Dhanishta damage: 17  target: Burroughs shield: 0 structure: 32
[Xocotl I attacks Alchibah for 5]
AttackShipShip: attacker: Surprise damage: 11  target: Eridanus shield: 0 structure: 31.2
AttackShipShip: attacker: Surprise damage: 11  target: Bhargava shield: 0 structure: 2
AttackShipShip: attacker: Pronghorn damage: 6  target: Alchibah shield: 0 structure: 47
AttackShipShip: attacker: Eridanus damage: 6  target: Chinchilla shield: 0 structure: 46
AttackShipShip: attacker: Enif damage: 6  target: Cypress shield: 0 structure: 52
AttackShipShip: attacker: Vance damage: 6  target: Fairness shield: 0 structure: 52
AttackShipShip: attacker: Cypress damage: 11  target: Burroughs shield: 0 structure: 15
AttackShipShip: attacker: Cypress damage: 11  target: Betelgeuse shield: 0 structure: 19.4
AttackShipShip: attacker: Armadillo damage: 6  target: Chinchilla shield: 0 structure: 40
AttackShipShip: attacker: Schedar damage: 6  target: Klee shield: 0 structure: 52
AttackShipShip: attacker: Mulu-lizi damage: 6  target: Alchibah shield: 0 structure: 41
AttackShipShip: attacker: Oppenheimer damage: 7  target: Cheleb shield: 0 structure: 52
AttackShipShip: attacker: Arch damage: 6  target: Happiness shield: 0 structure: 42
AttackShipShip: attacker: Muscida damage: 7  target: Cypress shield: 0 structure: 46
AttackShipShip: attacker: Tenrec damage: 6  target: Willow shield: 0 structure: 52
AttackShipShip: attacker: Klee damage: 11  target: Mulu-lizi shield: 0 structure: 15
AttackShipShip: attacker: Klee damage: 11  target: Balsa shield: 0 structure: 6.6
Attacker Spallanzani could not attack.
AttackShipShip: attacker: Chagall damage: 6  target: Happiness shield: 0 structure: 36
AttackShipShip: attacker: Cheleb damage: 17  target: Eridanus shield: 0 structure: 20.2
AttackShipShip: attacker: Cheleb damage: 17  target: Oppenheimer shield: 0 structure: 27.4
AttackShipShip: attacker: Betelgeuse damage: 6  target: Dhanishta shield: 0 structure: 46
AttackShipShip: attacker: Fairness damage: 11  target: Oppenheimer shield: 0 structure: 10.4
AttackShipShip: attacker: Fairness damage: 11  target: Pronghorn shield: 0 structure: 30.6
AttackShipShip: attacker: Cypress damage: 11  target: Enif shield: 0 structure: 30
AttackShipShip: attacker: Cypress damage: 11  target: Enif shield: 0 structure: 19
AttackShipShip: attacker: Alchibah damage: 17  target: Enif shield: 0 structure: 8
[Alchibah attacks Xocotl I for 17, eliminating its defences]
AttackShipShip: attacker: Surprise damage: 11  target: Burroughs shield: 0 structure: 4
AttackShipShip: attacker: Surprise damage: 11  target: Muscida shield: 0 structure: 10
AttackShipShip: attacker: Eridanus damage: 6  target: Alchibah shield: 0 structure: 35
AttackShipShip: attacker: Cheleb damage: 17  target: Vance shield: 0 structure: 10.6
AttackShipShip: attacker: Cheleb damage: 17  target: Arch shield: 0 structure: 32
AttackShipShip: attacker: Facade damage: 6  target: Surprise shield: 0 structure: 52
AttackShipShip: attacker: Klee damage: 11  target: Facade shield: 0 structure: 28.2
AttackShipShip: attacker: Klee damage: 11  target: Pronghorn shield: 0 structure: 19.6
Attacker Xocotl I could not attack.
AttackShipShip: attacker: Betelgeuse damage: 6  target: Klee shield: 0 structure: 46
AttackShipShip: attacker: Mulu-lizi damage: 6  target: Surprise shield: 0 structure: 46
AttackShipShip: attacker: Fairness damage: 11  target: Armadillo shield: 0 structure: 31
AttackShipShip: attacker: Fairness damage: 11  target: Mulu-lizi shield: 0 structure: 4
[Royal Demesne Xocotl II attacks Klee for 3]
AttackShipShip: attacker: Arch damage: 6  target: Cheleb shield: 0 structure: 45
Attacker Muscida could not attack.
Attacker Vance could not attack.
AttackShipShip: attacker: Pronghorn damage: 6  target: Alchibah shield: 0 structure: 29
Attacker Enif could not attack.
AttackShipShip: attacker: Happiness damage: 17  target: Pronghorn shield: 0 structure: 8.6
AttackShipShip: attacker: Happiness damage: 17  target: Tenrec shield: 0 structure: 4
Attacker Burroughs could not attack.
Attacker Tenrec could not attack.
AttackShipShip: attacker: Dhanishta damage: 17  target: Betelgeuse shield: 0 structure: 8.4
AttackShipShip: attacker: Dhanishta damage: 17  target: Facade shield: 0 structure: 17.2
AttackShipShip: attacker: Chinchilla damage: 11  target: Schedar shield: 0 structure: 31.8
AttackShipShip: attacker: Chinchilla damage: 11  target: Arch shield: 0 structure: 15
AttackShipShip: attacker: Armadillo damage: 6  target: Happiness shield: 0 structure: 30
AttackShipShip: attacker: Willow damage: 17  target: Arch shield: 0 structure: 4
AttackShipShip: attacker: Willow damage: 17  target: Facade shield: 0 structure: 0.200001
AttackShipShip: attacker: Chagall damage: 6  target: Dhanishta shield: 0 structure: 40
AttackShipShip: attacker: Schedar damage: 6  target: Surprise shield: 0 structure: 40
AttackShipShip: attacker: Alchibah damage: 17  target: Chagall shield: 0 structure: 28
AttackShipShip: attacker: Alchibah damage: 17  target: Schedar shield: 0 structure: 20.8
AttackShipShip: attacker: Cypress damage: 11  target: Chagall shield: 0 structure: 11
AttackShipShip: attacker: Cypress damage: 11  target: Schedar shield: 0 structure: 3.8
AttackShipShip: attacker: Eridanus damage: 6  target: Alchibah shield: 0 structure: 23
AttackShipShip: attacker: Fairness damage: 11  target: Eridanus shield: 0 structure: 3.2
Attacker Royal Demesne Xocotl II could not attack.
[Fairness attacks Royal Demesne Xocotl II for 11, eliminating its defences]
[Surprise attacks Royal Demesne Xocotl II for 11]
AttackShipShip: attacker: Surprise damage: 11  target: Armadillo shield: 0 structure: 20
AttackShipShip: attacker: Armadillo damage: 6  target: Alchibah shield: 0 structure: 17
AttackShipShip: attacker: Cheleb damage: 17  target: Armadillo shield: 0 structure: 9
Attacker Schedar could not attack.
Attacker Chagall could not attack.
My fleet ended up with 11+24+34+34+34+39+39+40+46+46=347/520 structure — one ship heavily damaged but none destroyed, despite losing a third of their total structure.

Post Reply