wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 12-10-2009, 06:29 AM   #31
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

Okay, it's been updated with everything requested of it. It appears to still work as listed, too.
__________________
Rising_Dusk is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 12-10-2009, 06:52 AM   #32
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

OK, I'm going to approve this now, and graveyard Pyro's Pools library since this deprecates it.
grim001 is offline   Reply With Quote
Old 01-19-2010, 03:17 AM   #33
Ammorth
I blink, therefore I am.
 
Ammorth's Avatar
 
Join Date: Sep 2006
Posts: 1,812

Submissions (10)

Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)

Default

Found some errors:

Collapse JASS:
method getWeight takes integer entry returns real
        return .Weights[LoadInteger(ht, integer(this), entry)]
    endmethod
    method getChance takes integer entry returns real
        if .WeightTotal > 0. then
            return .Weights[LoadInteger(ht, integer(this), entry)]/.WeightTotal
        endif
        return 0.
    endmethod

Highlighted periods are missing.
__________________
Ammorth is offline   Reply With Quote
Old 01-19-2010, 04:21 AM   #34
YourName
User
 
Join Date: Jan 2007
Posts: 101

YourName has little to show at this moment (7)

Default

You don't need the periods with the newest version of JassHelper. (However I dislike not using them)
__________________
--YourNameHere
YourName is offline   Reply With Quote
Old 01-19-2010, 06:13 AM   #35
Ammorth
I blink, therefore I am.
 
Ammorth's Avatar
 
Join Date: Sep 2006
Posts: 1,812

Submissions (10)

Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)

Default

ahh, then the jassnewgenpack doesn't have the newest version it seems (atleast a couple of weeks ago, when I snatched it).
__________________
Ammorth is offline   Reply With Quote
Old 01-19-2010, 06:21 AM   #36
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

Yeah, I don't think it does. I know the library works, though, I verified it with some testmap I never posted.
__________________
Rising_Dusk is offline   Reply With Quote
Old 01-21-2010, 04:11 AM   #37
DioD
obey
 
DioD's Avatar
 
Join Date: Feb 2006
Posts: 1,532

Submissions (4)

DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)

Send a message via ICQ to DioD
Default

removal function is broken since you do not update hashtable value on switching toremove value with last value.
DioD is offline   Reply With Quote
Old 01-26-2010, 04:10 PM   #38
Iron_Doors
User
 
Join Date: Aug 2007
Posts: 50

Submissions (1)

Iron_Doors will become famous soon enough (31)Iron_Doors will become famous soon enough (31)

Default

You got two bugs in Pool:
1. As DioD mentioned, when removing an entry, the index the hashtable holds for the last element which is moved into the removed ones place is not corrected.
2. The "child" hashtable associated with an intpool isn't flushed when the pool is destroyed.

Here's a library I used to test Pool:
Expand PoolTest:
Iron_Doors is offline   Reply With Quote
Old 07-03-2010, 06:08 PM   #39
Mr.Malte
User
 
Mr.Malte's Avatar
 
Join Date: Apr 2008
Posts: 286

Submissions (2)

Mr.Malte is on a distinguished road (11)

Default

Please fix this, I am struggling with that problem atm.

Code:
    method pickBuilding takes player p, integer buildingType returns Building
        local integer i = 0
        local intpool pool = intpool.create()
        local Building temp
        
        static if DEBUG then
            call Debug(" ========================= ")
            call Debug("Picking Building.")
            call Debug("    --- Count: "+I2S(.buildingCount))
        endif
        
        if buildingType == BUILDING_TYPE_ANY then
            set buildingType = GetRandomInt(0,MAX_BUILDING_TYPES)
        endif
        loop
            set i = i + 1
            exitwhen i > .buildingCount
            set temp = .Buildings[Index2D(i,buildingType)]
            call Debug(" ========================= ")
                static if DEBUG then
                    call Debug("Gold Cost: "+I2S(temp.Data.gold))
                    if temp.Data.gold < AI_GetPlayerGold(p) then
                        call Debug(" ==> passed")
                        call Debug("    Lumber Cost: "+I2S(temp.Data.lumber))
                        if temp.Data.lumber < AI_GetPlayerLumber(p) then
                            call Debug("    ==> passed")
                            call Debug("        Limit: "+I2S(temp.limit))
                            if AI_CountUnits(p,temp.id) < temp.limit then
                                call Debug("        ==> passed.")
                                if temp.req.fulfilled(p) then
                                    call Debug("        Requirements")
                                    call Debug("        ==> passed. Added to list.")
                                endif
                            else
                                call Debug("Not passed")
                            endif
                        else
                            call Debug(" ==> Not passed")
                        endif
                    else
                        call Debug(" ==> Not passed")
                    endif
                endif
            
            if temp.Data.gold < AI_GetPlayerGold(p) and temp.Data.lumber < AI_GetPlayerLumber(p) then
                if AI_CountUnits(p,temp.id) < temp.limit then
                    if temp.req != 0 then
                        if temp.req.fulfilled(p) then
                            call pool.addInt(temp,temp.weight)
                        endif
                    endif
                endif
            endif
        endloop
        set i = pool.getRandomInt()
        call pool.destroy()
        call Debug("i: "+I2S(i))
        return i
    endmethod

This only works the first time the function is used.
If I remove the destroy pool command, it works like six times.
Mr.Malte is offline   Reply With Quote
Old 09-14-2010, 12:47 AM   #40
SanKakU
User
 
Join Date: Jan 2009
Posts: 136

SanKakU has a little shameless behaviour in the past (-2)

Send a message via AIM to SanKakU Send a message via MSN to SanKakU Send a message via Yahoo to SanKakU
Default

sounds like i'll be using this.

edit: i've started to use this, but i need global pools in addition to local pools. please update the resource to include using global pools. i'm getting error messages when i try using them with this system. it might not be well known but using global unit pools or item pools is probably most of the time much more effective than using local unit and item pools. this is because you do not have to keep remaking the pools but just need to use them if they're global. perhaps others like me thought that units/items in a pool are a finite resource, but they are not, so there is no reason to repeatedly create the same pools over and over again, unless you want the contents to change all the time, which i would imagine most of the time is not desirable.

i will bump this thread if i don't hear back from the original poster in a reasonable period of time as i've just private messaged him today about the matter.

Last edited by SanKakU : 02-25-2011 at 06:25 PM.
SanKakU is offline   Reply With Quote
Old 03-03-2011, 05:26 PM   #41
SanKakU
User
 
Join Date: Jan 2009
Posts: 136

SanKakU has a little shameless behaviour in the past (-2)

Send a message via AIM to SanKakU Send a message via MSN to SanKakU Send a message via Yahoo to SanKakU
Default

bump http://www.wc3c.net/showpost.php?p=1127603&postcount=40
edit:
ok, the script seems to work ok with global intpool.
Collapse JASS:
//i simply wasn't doing this:

globals
    intpool variablename
endglobals

//and then later, this:
set variablename=intpool.create()
//i was trying to do this:
globals
    intpool variablename=intpool.create()
endglobals
//which failed miserably

Last edited by SanKakU : 03-03-2011 at 05:53 PM.
SanKakU is offline   Reply With Quote
Old 10-23-2013, 01:43 AM   #42
MoCo
User
 
MoCo's Avatar
 
Join Date: Feb 2006
Posts: 85

MoCo is on a distinguished road (14)

Send a message via ICQ to MoCo
Default

Below is a fixed version of the pool library with a properly working removeInt method as well as a flush method (which I felt was kinda missing).

Collapse JASS:
library Pool
//******************************************************************************
//* BY: Rising_Dusk
//* 
//* This script gives the user access to general integer pools. A pool is a data
//* structure that allows you to give entries to it a weight. This weight
//* essentially scales how likely certain random accesses to the pool will be
//* returned by the internal .getRandomInt method. Pools can be useful in any
//* number of ways, such as item drops, randomizing enemy encounters, randomly
//* selecting rects weighted by area, and so forth.
//* 
//* Updated/fixed by Moco [2013-10-23]:
//*   - Fixed a critical issue with the RemoveInt function not properly updating the hashtable
//*   - Added a flush method to clear the whole pool
//*
//******************************************************************************
//* 
//* Example usage:
//*    local intpool ip = intpool.create()
//*    call ip.addInt(1, 1.0)
//*    call ip.addInt(2, 0.5)
//*    call ip.getRandomInt()
//*    call ip.getChance(2)
//*    call ip.getWeight(2)
//*    call ip.removeInt(1)
//*    call ip.flush()
//* 
//* You will first need to create an intpool as shown above. Once you've done
//* that, you may use the .addInt method to add an entry to the pool with a
//* specific weight. The example above adds 2 integers, one twice as likely to
//* be randomly selected as the other. That means for the above example, the
//* .getRandomInt method will 66% of the time return 1 and 33% of the time
//* return 2. If you want to remove an entry from an intpool, the .removeInt
//* method is what you will want to use. If you would like to update an entry's
//* weight after already adding it, simply use .addInt again with the new
//* weight.
//* 
//* The .getChance and .getWeight methods are there for convenience. If you are
//* interested in the exact chance of the intpool returning a specific entry,
//* then you should use .getChance to obtain the decimal chance out of 1. If you
//* want to know the weight input for a specific entry, .getWeight will return
//* that for you.
//* 
//* When adding an entry to the intpool with .addInt, the actual magnitude of
//* the weight doesn't matter. What matters is its magnitude relative to the
//* magnitudes of all other entries in the intpool. This means that it is ok to
//* use very large or very small weights and is done at the user's discretion.
//* 
//* It is worth noting that if you use .getRandomInt on an intpool with no
//* entries, the function will return INTPOOL_NO_ENTRIES, which is about as
//* random an integer as possible so as to avoid people accidentally using it.
//* 
globals
    //These constants can be changed
    private constant integer MAX_INSTANCES         = 8191
    private constant integer MAX_ENTRIES           = 256
            constant integer INTPOOL_NO_ENTRIES    = 0x672819
            
    //Don't change the following global declaration
    private hashtable ht = InitHashtable()
endglobals

struct intpool[MAX_INSTANCES]
    private integer Cnt         = 0
    private real    WeightTotal = 0.
    private integer array Entries[MAX_ENTRIES]
    private real    array Weights[MAX_ENTRIES]
    
    method getWeight takes integer entry returns real
        return Weights[LoadInteger(ht, integer(this), entry)]
    endmethod
    
    method getChance takes integer entry returns real
        if WeightTotal > 0. then
            return Weights[LoadInteger(ht, integer(this), entry)]/WeightTotal
        endif
        return 0.
    endmethod
    
    method addInt takes integer entry, real weight returns nothing
        local integer in = 0
        if .Cnt == MAX_ENTRIES then
            //Can't hold any more entries
            debug call BJDebugMsg(SCOPE_PREFIX+"Error: .addEntry has reached MAX_ENTRIES")
            return
        elseif weight <= 0. then
            //Zero or negative weights make no sense
            debug call BJDebugMsg(SCOPE_PREFIX+"Error: .addEntry can't take zero or negative weights")
            return
        endif
        set in = LoadInteger(ht, integer(this), entry)
        if in > 0 then
            //Update old entry
            set .WeightTotal = .WeightTotal - .Weights[in] + weight
            set .Weights[in] = weight
        //    debug call BJDebugMsg(SCOPE_PREFIX+"Pool updated existing entry: "+I2S(entry))
        else
            //Make a new entry
            set .Cnt           = .Cnt + 1
            call SaveInteger(ht, integer(this), entry, .Cnt)
            set .Entries[.Cnt] = entry
            set .Weights[.Cnt] = weight
            set .WeightTotal   = .WeightTotal + weight
         //   debug call BJDebugMsg(SCOPE_PREFIX+"Pool New Entry: "+I2S(entry))
        endif
    endmethod
    
    method flush takes nothing returns nothing
        local integer c = 0
        call FlushChildHashtable(ht, integer(this))
        loop
            exitwhen c > Cnt
            set .Entries[.Cnt] = 0
            set .Weights[.Cnt] = 0
            set c = c + 1
        endloop
        set .WeightTotal = 0
        set .Cnt         = 0
    endmethod
    
    method removeInt takes integer entry returns nothing
        local integer in = LoadInteger(ht, integer(this), entry) 
        if in > 0 then
            call RemoveSavedInteger(ht, integer(this), entry) 
            
            //Remove its entry in the arrays
            set .WeightTotal = .WeightTotal - .Weights[in]
            
            if in != .Cnt then           
                set .Entries[in] = .Entries[.Cnt]
                set .Weights[in] = .Weights[.Cnt]
                call SaveInteger(ht, integer(this), .Entries[in], in) 
            endif
            set .Entries[.Cnt] = 0
            set .Weights[.Cnt] = 0
            set .Cnt         = .Cnt - 1
            
            if .Cnt == 0 then
                call this.flush()
            endif
        debug else
            debug call BJDebugMsg(SCOPE_PREFIX+"Error: .removeEntry entry doesn't exist")
        endif
    endmethod
    
    method getRandomInt takes nothing returns integer
        local real    r = GetRandomReal(0, .WeightTotal)
        local integer c = 0
        if .WeightTotal <= 0. then
            debug call BJDebugMsg(SCOPE_PREFIX+"Error: intpool has no entries")
            return INTPOOL_NO_ENTRIES
        endif
        loop
            set r = r - .Weights[c]
            exitwhen r <= 0
            set c = c + 1
        endloop
        return .Entries[c]
    endmethod
    
endstruct
endlibrary
__________________

Last edited by MoCo : 10-23-2013 at 01:48 AM.
MoCo is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 12:43 PM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2018, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services