detecting metal spots

detecting metal spots

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

detecting metal spots

Post by knorke »

What is a good way to detect metal spots?
Obviously scanning the map blabla but it is not so trivial to decide where the spots really are.

So I tried this thing: "Metal Spot Finder" by Niobium
http://widgets.springrts.de/springinfo/index.php#183

Sometimes works good, sometimes thinks it is on a metal map even if it is not and returns no spots. :?

Seems this:

Code: Select all

			elseif stripStart then
				if mx - gridSize - stripStart > extractorRadius then
					Spring.Echo('<WG.metalSpots> Mass metal detected. Disabling.')
					return {}
is the detection for it.
So I could just take that out or make less strict but maybe somebody has already done testing with that and has something better?
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: detecting metal spots

Post by Forboding Angel »

check evo, there is a spot indexer thingy

https://code.google.com/p/evolutionrts/ ... finder.lua
User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2702
Joined: 25 Aug 2004, 13:31

Re: detecting metal spots

Post by bobthedinosaur »

do trace amounts set off nobium's detector? like if a mapper didnt delete some metal completely or placed some on very lightly.
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: detecting metal spots

Post by Niobium »

knorke wrote:Sometimes works good, sometimes thinks it is on a metal map even if it is not and returns no spots. :?
...
So I could just take that out or make less strict but maybe somebody has already done testing with that and has something better?
Out of interest, what map is it that you are getting that on? I've got an update (later today) which fixes the uncappable detection so that might fix it.
bobthedinosaur wrote:do trace amounts set off nobium's detector? like if a mapper didnt delete some metal completely or placed some on very lightly.
>0 = metal. I haven't seen any maps with 'trace' amounts other than the cloud metal ones like small divide, which my widget intentionally doesn't work with.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: detecting metal spots

Post by knorke »

Forb:
thanks but without info if it works better or worse, it is not much use.
tbh I am just looking for something that works reliable ;)

Niob:
happens on ie "Barren"
the spots are a bit fuzzy there but still clearly spots.

Noticed that just converting the canceling into a warning (http://springrts.com/phpbb/viewtopic.ph ... 8&start=62) seems to work well.
I thought it would place millions of metalspots or get caught in an endless loop or something but even on "Speedballs 16 way" it works. It puts one spot right in the middle of the map, which makes sense. :-)
But I did not test much and if you can make it even better, that is by all means good.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: detecting metal spots

Post by Forboding Angel »

It works better. Much better. It is what defines the mex spots for easymetal in evo. If it doesn't do it's job right, than evo won't play.

It also does a nice job with making metal maps sort of playable.

Give it a shot, it's quite good.
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: detecting metal spots

Post by Niobium »

Updated to v1.1.
Changelog:
- Removed mid-search exiting
- Fixed valid extractor positions calculation

Rather than changing the high-metal error to a warning I just removed the check altogether, including the messages. So now it will always run the full search and return the positions it found (which for metal maps would be 1 spot the size of the entire map). Note that the widget actually runs the fastest on high metal maps, so this 'early exit on high metal' wasn't required at all.

I figured it should be up to the widgets that make use of the metal spot data to decide what makes sense*, rather than the finder making those decisions itself.

Also the valid positions calculation fix is fairly important, so definitely update just on that alone.

* i.e. if #WG.metalSpots < 5 then exit
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: detecting metal spots

Post by FLOZi »

User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: detecting metal spots

Post by knorke »

easymetal has some unrelated stuff in it, cba to take it apart ;)
Niobiums thing with the fixes is perfect.
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: detecting metal spots

Post by Google_Frog »

Here is a standalone file with the easymetal algorithm.

http://code.google.com/p/zero-k/source/ ... finder.lua
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: detecting metal spots

Post by Niobium »

FLOZi wrote:easymetal algorithm gets my vote.
Speed test on Dworld_V1:
Easymetal: 4.828 seconds
Niobiums: 0.131 seconds

Speed test on SpeedBall_10x10:
Easymetal: 13.441 seconds
Niobiums: 0.017 seconds
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: detecting metal spots

Post by zwzsg »

I do it like that:

Code: Select all

        local SpotList = {}
        local MinSpotDist = math.max(Game.extractorRadius,112)
        local minmetal, maxmetal = nil, nil
        for x = 16,Game.mapSizeX,32 do
            for z = 16,Game.mapSizeZ,32 do
                local _,m = Spring.GetGroundInfo(x,z)
                if not minmetal or m<minmetal then
                    minmetal = m
                end
                if not maxmetal or m>maxmetal then
                    maxmetal = m
                end
            end
        end
        local mediummetal = (maxmetal - minmetal)/2
        Spring.Echo("Metal: ["..maxmetal.."-"..minmetal.."]")
        if maxmetal == minmetal then -- Special case for metal map, or no metal map
            local MinSpotDist = math.sqrt(Game.mapSizeX*Game.mapSizeZ/(4*#Spring.GetTeamList()))
            for x = MinSpotDist/2,Game.mapSizeX,MinSpotDist do
                for z = MinSpotDist/2,Game.mapSizeZ,MinSpotDist do
                    table.insert(SpotList, {x=x, y=Spring.GetGroundHeight(x,z), z=z})
                end
            end
        else
            for x = 16,Game.mapSizeX,32 do
                for z = 16,Game.mapSizeZ,32 do
                    local _,m = Spring.GetGroundInfo(x,z)
                    if m >= mediummetal then
                        local newSpot=true
                        for _,g in ipairs(SpotList) do
                            if math.sqrt((x-g.x)*(x-g.x) + (z-g.z)*(z-g.z)) < MinSpotDist then
                                newSpot = false
                                break
                            end
                        end
                        if newSpot then
                            Spring.Echo("Insert!")
                            table.insert(SpotList, {x=x, y=Spring.GetGroundHeight(x,z), z=z})
                        end
                    end
                end
            end
        end
        for _,g in ipairs(SpotList) do
            Spring.CreateFeature("geovent", g.x, g.y, g.z)
        end
Not sure if optimised. On metal maps, put about four spots per team.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: detecting metal spots

Post by CarRepairer »

I updated the easymetal algo in evo so it's slightly better optimized than the one in zk (which I first wrote a hundred years ago).

Easymetal is intended to work with any metalmap, including those large blob metal spots.

This link, not the one forb linked...

https://code.google.com/p/evolutionrts/ ... ymetal.lua#
User avatar
Cheesecan
Posts: 1571
Joined: 07 Feb 2005, 21:30

Re: detecting metal spots

Post by Cheesecan »

Niobium wrote:
FLOZi wrote:easymetal algorithm gets my vote.
Speed test on Dworld_V1:
Easymetal: 4.828 seconds
Niobiums: 0.131 seconds

Speed test on SpeedBall_10x10:
Easymetal: 13.441 seconds
Niobiums: 0.017 seconds
Lol pwned.
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: detecting metal spots

Post by Niobium »

CarRepairer wrote:I updated the easymetal algo in evo so it's slightly better optimized than the one in zk

This link, not the one forb linked...

https://code.google.com/p/evolutionrts/ ... ymetal.lua#
Well I used the one that YOU linked, not forb... but anyway I retested using the 'better optimized' evo version:

Speed test on Dworld_V1:
Niobums: 0.131 seconds
Easymetal (ZK): 4.737 seconds
Easymetal (Evo): 6.002 seconds

'better optimized' == 'even slower'. Interesting.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: detecting metal spots

Post by CarRepairer »

Easymetal
Image

Niobium's
Image

Easymetal
Image

Niobium's
Image
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: detecting metal spots

Post by Forboding Angel »

Cheesecan wrote:
Niobium wrote:
FLOZi wrote:easymetal algorithm gets my vote.
Speed test on Dworld_V1:
Easymetal: 4.828 seconds
Niobiums: 0.131 seconds

Speed test on SpeedBall_10x10:
Easymetal: 13.441 seconds
Niobiums: 0.017 seconds
Lol pwned.
NOU.

And that, ladies and gentlemen, is why easymetal reigns supreme. Hurrah!
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: detecting metal spots

Post by knorke »

they have different goals.
User avatar
SinbadEV
Posts: 6475
Joined: 02 May 2005, 03:56

Re: detecting metal spots

Post by SinbadEV »

Obviously I'm not anything like a map lua coder but... couldn't you include both (or more) algorithms... make some kind of cursory analysis of the metal map (including extractor radius... one would assume a tiny extractor radius implies a ota style metal placement strategy) and then run the appropriate algorithm?

edit: Categories of metal placement
Core Prime (whole map is metal)
TotalA (metal spots smaller then the extractor radius)
Clouds (metal spots larger then the extractor radius or spread out and diffuse metal)
Jerk (metal map intentionally designed to screw up metal placement algorithms)
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: detecting metal spots

Post by CarRepairer »

knorke wrote:they have different goals.
Yes. My silly algo is years old, sat in ca's repo unloved and unused. Its original purpose was not to find places to put your mexes, but to replace the whole metalmap concept and work with all exisiting spring maps. It's indeed slow and if you don't care about the 3% of maps with stupid metal, use Nio's code by all means. I hate those maps anyway.
Post Reply

Return to “Lua Scripts”