Jump to content


Photo

The Markus-is-Modding Thread


133 replies to this topic

#121 Markus Ramikin

Markus Ramikin
  • Members
  • 86 posts

Posted 14 December 2011 - 05:24 PM

Jones: Over The Top.

Thudo: Thanks! And yeah, I'm just doing this for fun. And if there's a tiny chance this'll give any good ideas to anyone who's actually authorised to mess with IDH and publish their work, that'd be a nice bonus. (Not counting on that, but since the changelog -has- been asked about... doesn't hurt.)

I'm totally looking forward to SS IDH, believe you me. When is it coming out? I thought it was meant to be a few days ago...

Edited by Markus Ramikin, 14 December 2011 - 05:52 PM.


#122 Markus Ramikin

Markus Ramikin
  • Members
  • 86 posts

Posted 16 December 2011 - 10:11 PM

New problem! This is a weird one, so my hope is someone will find it interesting. (Again, this is DC:IDH).

I've implemented four different build plans (Chimera rush = awesome), however the computer keeps choosing the same one if I restart a game. DaemonhuntBuildBaseStrategy:ChooseBuildProgram() is correctly written, pretty much the same as any other race's. I've determined through the use of print() that this line...
local iRandom = math.random(1, 100)
... actually keeps coughing up the same number whenever I restart a game. Except this only happens for IDH race, not for other races.

For instance I set up an AI vs AI game with four players: IDH, Chaos, IDH, Chaos. I then inserted a print into their respective ChooseBuildProgram functions to show me what the random number is.

First game:
Chaos: 88
IDH: 5
Chaos: 67
IDH: 85

I restarted, here's what I got second game:
Chaos: 23
IDH: 5
Chaos: 2
IDH: 85

And third game:
Chaos: 58
IDH: 6
Chaos: 37
IDH: 86

So somehow the random number generator works for Chaos but not for IDH? Well there seems to be some nonrandomness to the Chaos results as well... they differ from each other by the same amount every time. But at least they don't sit at the same choice all the time.

Also it's the same with vanilla IDH, so it's not anything I did. One has to wonder about the chicken and egg problem: did this originally go unnoticed because IDH only had one buildplan anyway, or is it the other way around, IDH only had one buildplan because they couldn't get the random chooser to work.

Anyway. Anyone got any hints as to what could be causing this, and how I could get IDH to choose strategies randomly like every other race?

#123 thudo

thudo

    Wacko AI Guy!

  • Division Leaders
  • 12,164 posts
  • Location:Lemonville North, Canada
  • Projects:DoW AI Scripting Project
  • Division:DoW
  • Job:Division Leader

Posted 16 December 2011 - 10:16 PM

Hmm no clue.. it does work for other mod factions bro.. I should know: we have 3 different branches for Dark Angels and they get randomly played. Heck, we even have a random HERO generator for a certain branch that chooses 1 of 3 HEROES only once and its randomly chosen so..
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#124 Markus Ramikin

Markus Ramikin
  • Members
  • 86 posts

Posted 17 December 2011 - 10:13 AM

I just checked on Soulstorm, both IDH and vanilla/dowai. It works -slightly- differently, IDH is as "random" as anything else, and I also checked vanilla/dowai to be sure. Here are the results from 3 Chaos AI players:

Game 1:
30
29
27

Game 2:
53
52
50

Game 3:
67
65
64

So in a 1v1 game you wouldn't notice anything, you get "random" strategies, but in multiple AI games you get these regularities.

I found the culprit. It's in Core. Specifically, CpuManager:__init( cpu_player_id ):
math.randomseed(math.mod(os.time(), 10000) + (self.player_id - 1000) * 1000)
This re-seeds the random number generator every time a race is initialised, with a values that are "different", but different in a regular way that defeats Lua's godawful RNG.

I commented this line out and started getting this:

16
67
3

12
64
12

67
47
84

However, I then asked myself why this line was added in the first place, and I discovered that if I restart the game, I'll get the same sequence every time:

Game 1:
90
10
38

Game 2:
47
58
35

I restarted the game a second time and I got the above numbers again. However, if after the first game I use the "restart" option rather than exit, go back to main menu, choose Skirmish etc, I'll start getting real random numbers. Arrghhhhhhh, this is so idiotic...

SOLUTION!
Or at least a proposal of one.

The problem lies in the fact that os.time() doesn't return miliseconds, just seconds. Instead, I used os.clock(), which returns the amount of CPU time used up by the script, and while it's in seconds as well, it's a fraction, a typical os.clock() looks like 135.72800001236. So the miliseconds can be extracted.

I changed the piece of code in cpu_manager.ai above to:
--math.randomseed(math.mod(os.time(), 10000) + (self.player_id - 1000) * 1000)
	local osclock = os.clock()*1000
	local miliseconds = math.mod(osclock,1000)
	print("os.clock = "..tostring(osclock).." , miliseconds = "..tostring(miliseconds))
	math.randomseed(miliseconds)
The above is what you want to use for testing, the final version is:
local miliseconds = math.mod(os.clock()*1000,1000)
	math.randomseed(miliseconds)

I've tested this and I keep getting random numbers and random strategies, no matter if I restart Soulstorm or go back to main menu or just use the "restart game" option. So it seems to work for me.

Something to test and think about for Dawn of Skirmish 3.21? Since it's a Core issue, and based on posts in this forum not everyone is about 1v1, a lot of people like bigger games...

Edited by Markus Ramikin, 17 December 2011 - 10:23 AM.


#125 thudo

thudo

    Wacko AI Guy!

  • Division Leaders
  • 12,164 posts
  • Location:Lemonville North, Canada
  • Projects:DoW AI Scripting Project
  • Division:DoW
  • Job:Division Leader

Posted 17 December 2011 - 01:29 PM

Err.. why? Random strats works natively in Adv SS AI 3.20. I have absolutely no clue why it doesn't for you. Sorry.
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#126 Markus Ramikin

Markus Ramikin
  • Members
  • 86 posts

Posted 17 December 2011 - 02:37 PM

Are you sure you understood what the problem is? DoWAI 3.20 has it all right, but it's more subtle than "random strats don't work" (that only happens for my DC:IDH and that is NOT what I'm talking about in that last post).

Sure, it's not a problem a lot of players will notice, especially those who don't play games with multiple AIs, but it's still a case of code not doing what it was written to do. DoWAI code that is, vanilla AIs don't have this (and therefore have a different, slightly less subtle type of strat problem which the quoted line of code was intended to solve).

Edited by Markus Ramikin, 17 December 2011 - 02:41 PM.


#127 thudo

thudo

    Wacko AI Guy!

  • Division Leaders
  • 12,164 posts
  • Location:Lemonville North, Canada
  • Projects:DoW AI Scripting Project
  • Division:DoW
  • Job:Division Leader

Posted 17 December 2011 - 04:44 PM

I'm confused: you modding AI for DC or SS? We only deal with SS since Mar'08.

I do like your LUA solution though. Well done Markus!
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#128 Markus Ramikin

Markus Ramikin
  • Members
  • 86 posts

Posted 17 December 2011 - 05:10 PM

Thank you!

I'm confused: you modding AI for DC or SS?


Sorry if I confused you. My first post on the subject was my noticing a problem with DC:IDH, but notice that my second post on the topic starts this way:

I just checked on Soulstorm, both IDH and vanilla/dowai.

Because I wanted us to be able to talk about the same code. But I can see I wasn't very clear.

So all that data in the second post is about SS DoWAI 3.20. And yes, you get fake "random" strats and if you're playing 1v1 you'll never notice anything amiss, but if you play multiple AI games (such as 2v2 with 1 ally), you'll keep getting combinations of strats in patterns, not like you'd get from a proper RNG. This is particularly easy to notice if you edit the ChooseBuildProgram functions to print out the exact numbers used to determine which strat to choose.

For instance, recent data from restarting a game involving me and 3 Chaos AI:
	dice roll	strategy chosen

Game 1
	81		3
	62		2
	71		3

Game 2
	20		1
	1		1
	10		1

Game 3
	41		2
	22		1
	31		1
Notice how each time the dice rolls are n, n-19, n-10? So you see you keep getting patterns, and in this particular instance of Soulstorm running I'd never see the AI choose strats like 1 2 3 or 3 1 1.

So this is far from a HUGE problem - you still get different strats most of the time and 99% of players will never notice anything wrong - but either way, it's code not working as intended and yet fixable...

Edited by Markus Ramikin, 17 December 2011 - 05:31 PM.


#129 thudo

thudo

    Wacko AI Guy!

  • Division Leaders
  • 12,164 posts
  • Location:Lemonville North, Canada
  • Projects:DoW AI Scripting Project
  • Division:DoW
  • Job:Division Leader

Posted 17 December 2011 - 05:14 PM

Uhmmm but its still "technically" random.. Give me 10 strategies to choose from then show me a pattern and I bet you it'll see be largely random. In other words.. we got far more important things to work on then worry about randomization. It works "as designed" in SS.
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#130 Markus Ramikin

Markus Ramikin
  • Members
  • 86 posts

Posted 17 December 2011 - 05:36 PM

Meh, I hate things staying imperfect. But fair enough.

One question though, would you be able to tell me who exactly rewrote cpu_manager for DoWAI? Arkhan? Larkin?

#131 thudo

thudo

    Wacko AI Guy!

  • Division Leaders
  • 12,164 posts
  • Location:Lemonville North, Canada
  • Projects:DoW AI Scripting Project
  • Division:DoW
  • Job:Division Leader

Posted 17 December 2011 - 05:43 PM

One question though, would you be able to tell me who exactly rewrote cpu_manager for DoWAI? Arkhan? Larkin?

Arkhan... ;)
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#132 Markus Ramikin

Markus Ramikin
  • Members
  • 86 posts

Posted 17 December 2011 - 05:57 PM

Thank you.

#133 Markus Ramikin

Markus Ramikin
  • Members
  • 86 posts

Posted 17 December 2011 - 10:55 PM

Hahaha, Oh. My. Cthulhu. I figured out why I was getting such a severe version of this problem with my IDH. (And also why with DoWAI, using the same race for all AIs - like all Chaos - tended to give the most predictable "patterns" of strats.)

OK, first you have to know that the RNG used in DC and I think SS too is horribad. It's prone to awful regularities; if you feed it a similar seed, it's going to give you a similar output. Do this:
for counter = 1,100 do
		math.randomseed(counter)
		print(tostring(math.random(100)))
	end
You're going to get a string of 1s and near the end 2s.

Good random number generators shouldn't behave like that.

BUT, even a bad RNG like this one is going to show much-desired divergence if each seed is iterated a number of times.

This is my IDH's squadlimits:

SquadLimits = 
		{
			standard =
			{
				inquisition_squad_archivist = 0,
				inquisition_squad_servitor_maintenance = 3,
				inquisition_squad_bodyguard = 1,
				inquisition_squad_shock_troops = 4,
				inquisition_squad_scholars = 1,
				inquisition_squad_death_cultist = 2,
				inquisition_squad_grey_knights = 3,
				inquisition_squad_grey_knights_terminator = 1,
				inquisition_squad_grey_knight_hero = 1,
				inquisition_squad_inquisitor_lord = 1,
				inquisition_squad_rhino = 4,
				inquisition_squad_chimera_transport = 5,
				inquisition_squad_dreadnought_assault = 2,
				inquisition_squad_dreadnought_support = 3,
				inquisition_squad_land_raider = 1,
				inquisition_squad_land_raider_crusader = 1,
			}
		},
Notice something unusual? No "math.random ( 2,3 )" type stuff like you have in all the other races.

Why does this affect anything? Because apparently a race's StrategyInfo gets imported after the randomiser seeding in cpu_manager, but before BuildBaseStrategy. So normally, StrategyInfo uses the random number generator a bunch of times due to calculating squad limits, and then by the time the AI is in BuildBaseStrategy and choosing a strategy, the RNG has been iterated a bunch of times and will give divergent results as long as the seeds are somewhat meaningfully different (as provided by my os.clock solution). But if the strategy choice is the first usage of the RNG after the seeding, then you'll see complete crap like what I've been getting.

This is beyond stupid.
Posted Image
This is also why using the same race for multiple AI games led to most predictable patterns - because different races call math.random different numbers of times in their squadlimits definitions.

Well, I don't feel like adding fake random squadlimits to my IDH tweaks, the race doesn't really need them. But if iterating is what the rng needs, iterating is what it'll get:

--Markus Ramikins fix for the fake randomness
	local miliseconds = math.mod(os.clock()*1000,1000)
	math.randomseed(miliseconds)	
	--iterate the RNG to get better random values
	for counter = 1,10 do
		dummy = math.random(2)
	end
That was surreal.

EDIT: before Thudo's "dowai on the brain" syndrome kicks in ;) I'd like to make it clear I was not laughing at dowai, but at the in-built RNG, which isn't dowai's fault, and at the accident of how dowai design unintentionally alleviated and concealed the problem.

Edited by Markus Ramikin, 18 December 2011 - 07:44 AM.


#134 Markus Ramikin

Markus Ramikin
  • Members
  • 86 posts

Posted 03 January 2012 - 12:56 PM

Aaand the above fix (or actually an improved version) is now part of DoWPro. :D

For Shodar and whoever else might be interested: next version changelog!

Almost forgot, but I moved two versions ahead a while ago and it seems I'm done, so I might as well post the final version for whoever is still interested:
http://dl.dropbox.co..._IDH_DC_137.txt

Most important changes:

1. Introduction of 4 different strategies

2. Fixing Vehicle balance. I didn't realize just how powerful Chimeras were until I wrote an AI that rushed to them AND refrained from using the inferior "upgrades" (multilasers rule).
The problems with it were twofold:

- Chimeras were too cheap for their effectiveness: fast, high health, and multilasers are a universal counter with decent damage and good range. Just compare them to IG chimeras - the cost's almost the same, while the effectiveness is about doubled. I fixed that primarily by increasing the cost (mostly energy), plus other minor changes.

- You didn't need a new vehicle building in Tier 2 to start spamming out Chimeras, so it was actually hard to prevent the rush. And having the rush interrupted didn't present the usual opportunity cost as would happen for, say, Space Marines, because you need the same buildings for all strats. I fixed that by making vehicles require Librarium (in addition to the other reqs), so an enemy can interrupt the vehicle rush by destroying the comparably fragile Librarium.

Also, Rhino anti-vehicle missiles were too powerful and at the same time their damage against buildings was too low.

And some minor crap. Among others, I stole the idea to change maintenance servitor armor type.

And now I'm waiting for SS IDH so I can see all my work become irrelevant ;).

Edited by Markus Ramikin, 04 January 2012 - 07:40 AM.




Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users