Customize luck settings - Sauron's mod for 1.6.4

Discussion of all aspects of multiplayer development: unit balancing, map development, server development, and so forth.

Moderators: Forum Moderators, Developers

Sauron
Posts: 221
Joined: January 11th, 2006, 8:51 am
Location: Barad-Dur, Mordor
Contact:

Customize luck settings - Sauron's mod for 1.6.4

Post by Sauron » August 26th, 2009, 12:14 am

NOTE: This thread is not a place for discussing luck and personal likes. It is intended as mod/fork development thread, with major focus on bugfixes/development issues. Thank you in advance for keeping it clean.
With the launch of Yogibear's Experimental Corner and his fork continuation of this mod is no longer needed. The thread remains useful as source of information on the mod - and the luck-reduction mechanism. If you're interested in helping out - the Yogibear's mod is the right place to go.

WARNING: If you're new to Battle for Wesnoth the mod is not recommended - you should first learn standard game tactics and game concepts. I recommend reading The "How to play..." Series. I intend the mod rather for medium and advanced player willing to experiment with something new.

This mod reduces or eliminates (according to settings you pick) the divergence of damage inflicted from expected value. Most enjoyable for multiplayer on small maps (Isar's Cross, Morituri and alike). Recommended multiplayer settings:
split of damage: 0%
normalize damage: 7, 9 or 11
Of course you're free to experiment with whatever settings you like.
________________________________________________________________

Files [last updated 20:17 GMT 29.08.2009]:

Wesnoth 1.6.4
The mod is fully compatibile with standard Wesnoth 1.6.4, no need to switch to official version to play standard game.
svnpatch_1_6_4_0.txt
Modified source files [zip] (Note: If you're compilling on Windows you might need to add this line (do it only if you're facing problems compiling the source):#define DISABLE_POOL_ALLOC at the top of the files: poolalloc.c, game.cpp)
Executable for windows 2000/XP/Vista [x86] (Instructions: simply unpack the file wesnoth164.exe from the archive into game's folder containing wesnoth.exe - and whole installation is done. Run wesnoth164.exe to launch mod. )


Other links (screenshots available):
Project's homepage http://saurons-mod.zor.org/
Old mod's thread
How to compile Wesnoth with CDT Eclipse and MinGW (includes link to pack of libraries required for compilation)
SVN/CVS plugin for Eclipse

Older solutions to the 'luck problem' (implemented, many not maintained any more - did I omit something? -Please PM me.)
[WML] My old era (oldest attempt I am aware of).
[C++] My mod for 1.0.* branch
[C++] New RNG to preventing exceptional luck (F.v.d.Essen <akuu>).
[WML] Zookeeper's Less Luck era
[C++] Damage System MOD(or Less Luck MOD) by A&J

Brief about how the mod works
Yogibear wrote:Unless things have changed it is not "you either use traditional random wesnoth or you discard randomness with this mod". As sauron already stated (but not elaborated upon, so i will do it here): Traditional wesnoth is a special case of his mod. In fact, the mod allows to determine, which percentage of a hit is deterministic and which is subject to randomness. So having 100% deterministic and 0% random is discarding randomness completely. 0% deterministic and 100% random is traditional wesnoth. Anything between is possible as well. That's why he said he is not changing the system. Instead he enlarges it.
I would like to add that beside the split damage option the mod also allows 'damage-smoothing' - one can set the output damage to be an effect of 1 roll or average of more rolls - up to 99 per one strike. Of course to make special attacks work not 100% times it is necessary to adjust the hit/miss condition - and it is done. Not every strike slows/poisons/stones - only if in series of rolls more 'virtual blows' (i.e. >=) than expected landed on target.
Why mod Wesnoth?
The mod was created in order to cope with excessive influence of the random number generator on the result of the game.
Modded game allows users to pick the amount of damage they intend to inflict for sure or change the distribution of damage (to make it more concentrated around Expected Value) thus making game more strategy-like rather than lottery-like.
What is the approach of the community to the mod?
Long time ago there was a poll. The results were not that discouraging one might expect (see http://www.wesnoth.org/forum/viewtopic.php?t=14794).

Found mod a welcome feature? - Your help in developing and maintaining it would be greatly appreciated
Should you find the mod interesting upgrade for games features - and should you be willing to help me maintaining and developing the mod - please contact me via pm or at sauron.wesnoth@gmail.com. I no longer have time to rewrite mod for every version of wesnoth - and I think the mod should be developed/improved independently anyway.
Should you be interested in participation in developement of the mod, please take a look at 1st post in thread linked below- it contains some remarks that explain the proposed formula as well as some unimplemented ideas.
http://www.wesnoth.org/forum/viewtopic. ... 06&start=0
I also prepared short guide on how to compile Wesnoth with CDT Eclipse and MinGW - please check http://www.wesnoth.org/forum/viewtopic. ... 71&start=0. I think CDT Eclipse is an IDE worth learning - especially due to Eclipse's wide range of supported languages - PHP, Java and anything you want.

What is needed?
If the project is supposed to be successful we will need:
1. SVN server (http://svn.gna.org ?) - the best solution would be a branch in official trunk ... but I do not hope much for it to happen.
2. IDE with SVN support - CDT Eclipse allows many plugins for this purpose. I suggest installing subclipse
3. Documentation and training - I did not document the code well - but every modification was contained within <SAURON></SAURON> tags or is preceeded with <SAURON change="description" /> tag. So it is easy to find all code changes I did . I can share my knowledge about wesnoth's mechanics - though my knowledge is far from complete.
4. 'True' project's webpage?

What might be the mod' evolution path
Possible directions (note- key assumption is mod/fork can cooperate with standard/official wesnoth client):
1. Extend statistics.
2. Make scouting depth adjustable by user.
3. Rewrite game to use floating-point values to store hitpoints - this will allow more interesting damage formulas and wipe out rounding problems.
4. Develop alternative 'less luck' ladder - in cooperation with current ladder coders
5. Address security gaps like sending unit positions to the opponent (famous save-and-sneek-peek method) and control the random number sequence - to assure it matches the sequence indicated by seed. At the moment, according to my knowledge you can discard random numbers generated by the server till you get one that suits you ...
6. Many, many other ideas ...

In the course of development of the mod many useful patches/code optimizations for original game might be created - and submitted to 'official' version. The mod is not meant as aggression into world of wesnoth. It is meant as citizen's initiative to adress problems/implement features that for some reasons did not receive approval into official version.

How the damage calculation is changed is clear if you analyze the code:

Code: Select all

void adjustDamage(	bool &hits, //standard wesnoth roll result
					bool &temp_results_hits, //adjusted roll result
					int &ran_num,//for storing randoms
					const float&split_ratio,//part of damage inflicted for sure
					const int &stats_chance_to_hit_target,//original cth
					int &stats_damage_target_takes,//effective inflicted damage
					const int & temp_stats_damage_target_takes,//original unit's damage per hit
					const int &smooth_distribution)//amount of randoms to generate result
{
	float temp_smooth_distribution_damage=0;
	int  temp_smooth_distribution_hits=0;

	if(split_ratio)
	{
		stats_damage_target_takes=ceil((split_ratio* stats_chance_to_hit_target*temp_stats_damage_target_takes)/100.0);
		if (hits)
		{
				temp_smooth_distribution_damage+=(1-split_ratio)*temp_stats_damage_target_takes;
				temp_smooth_distribution_hits++;
		}
		for(int i=1;i<smooth_distribution;i++)
		{
			ran_num = get_random();

			hits = (ran_num%100) < stats_chance_to_hit_target;
			if (hits)
			{
				temp_smooth_distribution_damage+=(1-split_ratio)*temp_stats_damage_target_takes;
				temp_smooth_distribution_hits++;
			}
		}

		stats_damage_target_takes+=floor(	temp_smooth_distribution_damage/(float)smooth_distribution);
		temp_results_hits=((temp_smooth_distribution_hits/(float)smooth_distribution)>=(stats_chance_to_hit_target/100.0));
		hits=1;
		resources::state_of_game->set_variable("damage_inflicted",
					 str_cast<int>(stats_damage_target_takes));
	}
	else if(smooth_distribution>1)
	{
		if (hits)
		{
				temp_smooth_distribution_damage+=temp_stats_damage_target_takes;
				temp_smooth_distribution_hits++;
		}
		for(int i=1;i<smooth_distribution;i++)
		{
			ran_num = get_random();

			hits = (ran_num%100) < stats_chance_to_hit_target;
			if (hits)
			{
				temp_smooth_distribution_damage+=temp_stats_damage_target_takes;
				temp_smooth_distribution_hits++;
			}

		}
		stats_damage_target_takes=round__(	temp_smooth_distribution_damage/(float)smooth_distribution);
		temp_results_hits=((temp_smooth_distribution_hits/(float)smooth_distribution)>=(stats_chance_to_hit_target/100.0));
		hits=1;
		resources::state_of_game->set_variable("damage_inflicted",
					 str_cast<int>(stats_damage_target_takes));
	}
	else //standard Wesnoth formula
	{
		temp_results_hits=hits;
		if(hits) {
			stats_damage_target_takes = temp_stats_damage_target_takes;
			resources::state_of_game->set_variable("damage_inflicted",
						 str_cast<int>(stats_damage_target_takes));
		} else {
			stats_damage_target_takes = 0;
		}
	}
}
Latest news:
________________________________________________________________

11:01 GMT 03.09.2009
A bug causing OOS in standard games with standard client was removed. Problem caused by not updating damage inflicted if unit got slowed - till end of fight.

________________________________________________________________

09:45 GMT 29.08.2009
A bug causing OOS after switching from mod to standard detected and corrected. All mod files updated.

________________________________________________________________

16:53 GMT 28.08.2009
Fixed problem with statistics (the damage inflicted was being overestimated). Project files updated.
________________________________________________________________

03:56 26.08.2009
I added svnpatch.txt as attachment to this post. I will update the file if I introduce any changes. Thanks to Soliton for dragging my attention to this matter and his help.
________________________________________________________________

11:35 26.08.2009
Another bug was detected - incompatibility with standard game. Usage of old version will lead to OOS errors. The problem was fixed, new sources and executable are available for download.
________________________________________________________________

08:44 26.08.2009
A bug was detected - incompatibility with standard game. The problem was fixed, new sources and executables are available for download.
________________________________________________________________

02:10 26.08.2009

I have completed initial phase of restoration of my mod. It contains most of features it used to, except for extended stats.
Last edited by Sauron on May 22nd, 2010, 3:28 pm, edited 76 times in total.
Sauron
Customize yourself random factor in game:
GET my mod [available as C++ sourcecode and compiled Windows executable] for wesnoth 1.6.4
at http://saurons-mod.zor.org/
Mod thread
http://www.wesnoth.org/forum/viewtopic.php?t=26803

User avatar
A Guy
Posts: 790
Joined: May 24th, 2008, 1:55 am

Re: Sauron's mod for 1.7.3 released

Post by A Guy » August 26th, 2009, 3:20 am

Wow, I never thought that you would bring your mod to the newer versions of Wesnoth - thank you very much. Unfortunately, my knowledge of C++ is limited, so I can't help you...
I'm just... a guy...
I'm back for now, I might get started on some work again.

forbiddian
Posts: 29
Joined: August 14th, 2009, 9:36 pm

Re: Sauron's mod for 1.7.3 released

Post by forbiddian » August 26th, 2009, 5:50 am

Hmm, I'm not really following how lowering the standard deviation surrounding the damage would actually decrease the amount of luck in BfW, assuming that you don't want to make everything deterministic. I think everyone can agree that determinism is bad. I love chess, but to play a good, competitive game takes at least two or three hours for 40 single-unit moves. Imagine how much brute force calculation would go into a deterministic Wesnoth, when players could meticulously calculate? "No wait, if I attack in this pattern, then my Elvish Fighter ends up with 6 more hitpoints and it only costs my Elvish Archer 3 hitpoints. No wait, but then my opponent might attack with these three pieces, leaving my Elvish Archer at -2 hitpoints, so I'd better balance out the damage more and ensure that my Archer lives. No wait, then he could just attack the Fighter, hold on, let me calculate...."


But anyway, onto my point: Say you have a guy attacking a wounded enemy. The enemy has just 1 hp left and you have three attacks to make the kill. In classic Wesnoth, you'd have, say, a 90% chance to make the kill.

In Sauron Wesnoth, you'd have a 98% chance to make the kill.

If you do get struck by lightning and roll in the bottom 2%, in Sauron Wesnoth, you have much less room to recover. You have fewer pieces and pieces do damage more consistently. If your opponent plays well, it'll likely be extremely difficult to recover from a piece deficit. In regular Wesnoth, you still have the chance, even after a bad luck streak, to regroup, recover, and fight on. If you're hit with bad luck, basically, there's a built in way to get back in: Good luck.

If you're hit with bad luck in Sauron Wesnoth, there's less recourse. If you get down a piece through bad luck, you'll probably lose.


Bad luck might happen less often. Unlike Classic Wesnoth, you might go an entire game without the underdog side ever winning a roll. But when the unexpectedly low result happens, it's going to be proportionately more disastrous and less expected.

Sauron
Posts: 221
Joined: January 11th, 2006, 8:51 am
Location: Barad-Dur, Mordor
Contact:

Re: Sauron's mod for 1.7.3 released

Post by Sauron » August 26th, 2009, 8:09 am

forbiddian wrote:...
The mod is not about retaining chances to hit unchanged. The mod is to make outcome more concentrated around EV. If much higher probability of killing 1hp unit - an obvious result of inflicting damage closer to EV - is in the case something wrong or unexpected - I have no comments.
In Wesnoth the divergence from EV within some band is manageable, the width of the band of divergence depends on particular game and players' skills. The mod does reduce the chance of extreme results exactly to extent you're willing. If in Wesnoth in every 3rd/4th game you deal with extreme unmanageable divergences - in the mod you can face such situations less frequently - and the frequency is determined by smooth_ damage slider setting. I don't mind if 1 game in 10-20 is decided by extreme divergence. I do if every 3rd is.
forbiddian wrote:(...)Bad luck might happen less often. Unlike Classic Wesnoth, you might go an entire game without the underdog side ever winning a roll. But when the unexpectedly low result happens, it's going to be proportionately more disastrous and less expected.
I do not understand a thing of what you mean by this. It is obvious you did not play mod game - yet you already know what will be the result. Mabye time to back it up with some experience?
Last edited by Sauron on August 26th, 2009, 8:26 am, edited 1 time in total.
Sauron
Customize yourself random factor in game:
GET my mod [available as C++ sourcecode and compiled Windows executable] for wesnoth 1.6.4
at http://saurons-mod.zor.org/
Mod thread
http://www.wesnoth.org/forum/viewtopic.php?t=26803

Yogibear
Retired Developer
Posts: 1086
Joined: September 16th, 2005, 5:44 am
Location: Hamburg, Germany

Re: Sauron's mod for 1.7.3 released

Post by Yogibear » August 26th, 2009, 8:23 am

With all respect (i hope i speak in the name of sauron here, if not, just ignore me :wink: ):

This thread is about developing the mod, it is not about discussing if the mode is better/worse and why. There is some remarks i could contribute to that but they better should go in a separate thread (if sauron is even willing to discuss that, as there have been many of those in the past).

Congrats for the new mod, i appreciate this work :) .
Smart persons learn out of their mistakes, wise persons learn out of others mistakes!

Sauron
Posts: 221
Joined: January 11th, 2006, 8:51 am
Location: Barad-Dur, Mordor
Contact:

Re: Sauron's mod for 1.7.3 released

Post by Sauron » August 26th, 2009, 8:54 am

Thank you Yogi. I really want this thread to be developement only. Should anybody feel like creating 'bash sauron's mod thread' or 'why no mods are needed' - I am ok with that.
Sauron
Customize yourself random factor in game:
GET my mod [available as C++ sourcecode and compiled Windows executable] for wesnoth 1.6.4
at http://saurons-mod.zor.org/
Mod thread
http://www.wesnoth.org/forum/viewtopic.php?t=26803

lmelior
Posts: 116
Joined: June 16th, 2009, 3:30 am

Re: Sauron's mod for 1.7.3 released

Post by lmelior » August 26th, 2009, 11:09 pm

I'll be sure to give this one a shot.

Are there any plans to update the expected battle results? I took a brief look at the attack_prediction code but I'd have to study it a heck of a lot more before I knew how difficult the update would be.

The round__ kludge you put in there is a bit ugly. You could either use floor(x+0.5) since the result is always positive, or you could use round_double provided in util.hpp. Actually, actions.cpp does not include util.hpp directly but still uses at least one other function (round_damage) from there. The round_double function returns an int though. Is there a reason you made the function return a long? It doesn't appear to be necessary, though I admit I could be missing something.

EDIT:
Also, were you getting errors with poolalloc? I noticed that is completely disabled in your mod.

Sauron
Posts: 221
Joined: January 11th, 2006, 8:51 am
Location: Barad-Dur, Mordor
Contact:

Re: Sauron's mod for 1.7.3 released

Post by Sauron » August 27th, 2009, 7:03 am

lmelior wrote:Are there any plans to update the expected battle results? I took a brief look at the attack_prediction code but I'd have to study it a heck of a lot more before I knew how difficult the update would be.

The round__ kludge you put in there is a bit ugly. You could either use floor(x+0.5) since the result is always positive, or you could use round_double provided in util.hpp. Actually, actions.cpp does not include util.hpp directly but still uses at least one other function (round_damage) from there. The round_double function returns an int though. Is there a reason you made the function return a long? It doesn't appear to be necessary, though I admit I could be missing something.

EDIT:
Also, were you getting errors with poolalloc? I noticed that is completely disabled in your mod.
No changes to attack prediction code were made. I am not going to do it myself though. Should you be willing to address the thing - it is very welcome. The floor(x+0,5) is good enough. Poolalloc was library I did not want to build locally. It is not used for official windows build either. Of course enabling it on linux box does not hurt. This reminds me to mark changes in poolalloc.c and game.cpp -forgot to do it.
Sauron
Customize yourself random factor in game:
GET my mod [available as C++ sourcecode and compiled Windows executable] for wesnoth 1.6.4
at http://saurons-mod.zor.org/
Mod thread
http://www.wesnoth.org/forum/viewtopic.php?t=26803

Soliton
Site Administrator
Posts: 1594
Joined: April 5th, 2005, 3:25 pm
Location: #wesnoth-mp

Re: Sauron's mod for 1.7.3 released

Post by Soliton » August 27th, 2009, 7:43 am

So am I seeing that right that all the randomness reduction options alter the amount of damage a strike does?
"If gameplay requires it, they can be made to live on Venus." -- scott

Sauron
Posts: 221
Joined: January 11th, 2006, 8:51 am
Location: Barad-Dur, Mordor
Contact:

Re: Sauron's mod for 1.7.3 released

Post by Sauron » August 27th, 2009, 7:53 am

@Soliton: nothing more is needed.
Sauron
Customize yourself random factor in game:
GET my mod [available as C++ sourcecode and compiled Windows executable] for wesnoth 1.6.4
at http://saurons-mod.zor.org/
Mod thread
http://www.wesnoth.org/forum/viewtopic.php?t=26803

Soliton
Site Administrator
Posts: 1594
Joined: April 5th, 2005, 3:25 pm
Location: #wesnoth-mp

Re: Sauron's mod for 1.7.3 released

Post by Soliton » August 27th, 2009, 8:14 am

Sauron wrote:@Soliton: nothing more is needed.
Well, I'd say that is the worst way to reduce randomness by introducing another random factor. But I guess that'd be irrational.
"If gameplay requires it, they can be made to live on Venus." -- scott

User avatar
grzywacz
Inactive Developer
Posts: 303
Joined: January 29th, 2005, 9:03 pm
Location: Krakow, Poland
Contact:

Re: Sauron's mod for 1.7.3 released

Post by grzywacz » August 27th, 2009, 9:23 am

Naming of variables could be improved. Why call a variable:

Code: Select all

stats_damage_target_takes
only to comment it with:

Code: Select all

//effective inflicted damage
instead of naming it:

Code: Select all

effective_inflicted_damage
to begin with? This post feels like a poem :?

Sauron
Posts: 221
Joined: January 11th, 2006, 8:51 am
Location: Barad-Dur, Mordor
Contact:

Re: Sauron's mod for 1.7.3 released

Post by Sauron » August 27th, 2009, 9:27 am

Soliton wrote:
Sauron wrote:@Soliton: nothing more is needed.
Well, I'd say that is the worst way to reduce randomness by introducing another random factor. But I guess that'd be irrational.
Well, I put it like this: if "normalize damage"is set to > 1, the result damage is the average of n "trial" hits, where n==value of "normalize damage" setting. So random factor is in fact involved.
Sauron
Customize yourself random factor in game:
GET my mod [available as C++ sourcecode and compiled Windows executable] for wesnoth 1.6.4
at http://saurons-mod.zor.org/
Mod thread
http://www.wesnoth.org/forum/viewtopic.php?t=26803

lmelior
Posts: 116
Joined: June 16th, 2009, 3:30 am

Re: Sauron's mod for 1.7.3 released

Post by lmelior » August 27th, 2009, 9:00 pm

Sauron, I posted this in the users' forum thread that got locked:
This brings up a good point, Sauron...I wonder if the patch would be more acceptable without the "split damage" modification? I don't see nearly as much discussion about that part of it as I see regarding what you call distribution smoothing. This would also have the very pleasant side-effect of making the update to the expected battle result calculation much, much easier (sorry to harp on this in your threads, but personally I consider it essential if this is to be merged into mainline).
However, after reading Soliton's post I see now that that portion of it alters the damage as well (don't know how I missed that before). Perhaps the expected battle result calculation will still be difficult, but I still think separating the two ideas makes a patch more acceptable. Thoughts?

Sauron
Posts: 221
Joined: January 11th, 2006, 8:51 am
Location: Barad-Dur, Mordor
Contact:

Re: Sauron's mod for 1.7.3 released

Post by Sauron » August 28th, 2009, 1:35 am

lmelior wrote:However, after reading Soliton's post I see now that that portion of it alters the damage as well (don't know how I missed that before). Perhaps the expected battle result calculation will still be difficult, but I still think separating the two ideas makes a patch more acceptable. Thoughts?
Everything can be adjusted and changed. Please consider my contribution as starting point. I do not intend to stick to my ideas. I think setting of smooth damage over 10 makes little sense. The split damage option is implementation of completely different idea, proposed by someone else (they wanted fully deterministic option and defense working plainly as damage-diminisher). I wrote the function above to allow mixing both approaches.
Sauron
Customize yourself random factor in game:
GET my mod [available as C++ sourcecode and compiled Windows executable] for wesnoth 1.6.4
at http://saurons-mod.zor.org/
Mod thread
http://www.wesnoth.org/forum/viewtopic.php?t=26803

Post Reply