HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Need help from computer science freak, or at least one knowing "insertion sort" GOOD!

06-15-2006, 05:23 PM#1
MasterofSickness
I have tried so much!
If I only would count the time worked on this one problem, it would go up to 3 days properly.
So here my problem:
The insertion sort trigger works 100% right, the only problem I just can't figure out is how do I refer to the respectively player who killed a unit to increase his kills value by 1?
The following trigger has the event every time a unit dies and the udg_SpielergruppeAr[2] is a force where all playing, not computer controlled players are set in.
The array udg_IntAr_Kills[x] is declared as: udg_IntAr_Kills[1-8]=0
The array udg_IntAr_Row[x] is declared as: udg_IntAr_Row[1-8]=1-8
I tried to follow the player array changes with udg_IntAr_Row in the insertion sort at the bottom of the thread (thats why this variable is here), but I realized that it is not possible, because the numbers from udg_IntAr_Row will be overwritten after some kills...
GUI:
Trigger:
Custom script: local integer A=0
Custom script: local integer B=0
Custom script: loop
Custom script: exitwhen A>10
Custom script: if (IsPlayerInForce(Player(A),udg_SpielergruppeAr[2])==true) then
Custom script: set B=(B+1)
Custom script: if (Player(A) == GetOwningPlayer(GetKillingUnitBJ())) then
Custom script: set udg_IntAr_Kills[udg_IntAr_Row[ B ]]=(udg_IntAr_Kills[udg_IntAr_Row[ B ]]+1)
Custom script: call TriggerExecute(gg_trg_InsertionSort)
Custom script: endif
Custom script: endif
Custom script: set A=(A+1)
Custom script: endloop


Here is my insertion sort trigger in GUI and JASS:
The array udg_IntAr_Counter[8] contains the number of players which are human, not computer controlled.
The array udg_IntAr_Player[x] is set up by increasing player number of human, not computer controlled players.
(Example: udg_IntAr_Player[1]=0 0 for Player(1) Red)

Trigger:
InsertionSort
Events
Conditions
Collapse Actions
-------- udg_IntAr_Counter[8] = number of human players --------
-------- A = rows (Example: Bottom: A=1 ; Top: A=8) --------
-------- InitLocals --------
Custom script: local integer A=1
Custom script: local integer B
Custom script: local integer C=0
Custom script: local integer Kills
Custom script: local integer Playa
Custom script: local integer Row
-------- Put values in order --------
Custom script: loop
Custom script: exitwhen A==(udg_IntAr_Counter[8]+1)
Custom script: set Kills=udg_IntAr_Kills[A]
Custom script: set Playa=udg_IntAr_Player[A]
Custom script: set B=(A-1)
Custom script: loop
Custom script: exitwhen B<1 or udg_IntAr_Kills[b]<=Kills
Custom script: set udg_IntAr_Kills[B+1]=udg_IntAr_Kills[b]
Custom script: set udg_IntAr_Player[B+1]=udg_IntAr_Player[b]
Custom script: set udg_IntAr_Row[B+1]=B
Custom script: set udg_IntAr_Row[B-C]=A
Custom script: set B=(B-1)
Custom script: set C=(C+1)
Custom script: endloop
Custom script: set udg_IntAr_Kills[B+1]=Kills
Custom script: set udg_IntAr_Player[B+1]=Playa
Custom script: set A=(A+1)
Custom script: endloop
-------- NextTrigger --------
Custom script: call TriggerExecute(gg_trg_MultiboardAktualisieren)

Collapse JASS:
function Trig_InsertionSort_Actions takes nothing returns nothing
    // udg_IntAr_Counter[8] = number of human players
    // A = rows (Example: Bottom: A=1 ; Top: A=8)
    // InitLocals
    local integer A=1
    local integer B
    local integer C=0
    local integer Kills
    local integer Playa
    local integer Row
    // Put values in order
    loop
    exitwhen A==(udg_IntAr_Counter[8]+1)
    set Kills=udg_IntAr_Kills[A]
    set Playa=udg_IntAr_Player[A]
    set B=(A-1)
    loop
    exitwhen B<1 or udg_IntAr_Kills[b]<=Kills
    set udg_IntAr_Kills[B+1]=udg_IntAr_Kills[b]
    set udg_IntAr_Player[B+1]=udg_IntAr_Player[b]
    set udg_IntAr_Row[B+1]=B
    set udg_IntAr_Row[B-C]=A
    set B=(B-1)
    set C=(C+1)
    endloop
    set udg_IntAr_Kills[B+1]=Kills
    set udg_IntAr_Player[B+1]=Playa
    set A=(A+1)
    endloop
    // NextTrigger
    call TriggerExecute(gg_trg_MultiboardAktualisieren)
endfunction

//===========================================================================
function InitTrig_InsertionSort takes nothing returns nothing
    set gg_trg_InsertionSort = CreateTrigger(  )
    call TriggerAddAction( gg_trg_InsertionSort, function Trig_InsertionSort_Actions )
endfunction

I "only" need to know how I can refer to the right udg_IntAr_Kills[]?
Example:
A unit dies
set udg_IntAr_Kills[?]=(udg_IntAr_Kills[?]+1)

If you need any further infos then please ask for them!
Hope that someone can help...
06-15-2006, 05:29 PM#2
Rising_Dusk
Normally I would set the sorting to be by player number.
That way you can detect GetPlayerId(whichplayer) for the proper number.

Since player's always keep their numbers, no matter what, it's a good way of going about it.
So...
Collapse JASS:
local integer pnum = GetPlayerId(GetOwningPlayer(GetKillingUnit()))
set udg_IntAr_Kills[pnum]=udg_IntAr_Kills[pnum]+1
06-15-2006, 05:31 PM#3
blu_da_noob
The whole point of the sort is to, well, have it sorted. Otherwise he wouldn't be doing it.

By best suggestion would be to have a second array of all the player numbers which you 'sort' in sync with the array of number of kills. You can then get the correct position in the array for a player from this array.
06-15-2006, 05:42 PM#4
MasterofSickness
@ Rising_Dusk:
Yeah, thats right, the players number would never change, but the udg_IntAr_Kills will totally change through the insertion sort, so that udg_IntAr_Kills[1] can be the kills from player green (7)...AFAIK


Quote:
have a second array

Hmmm, I already thought of that, but didn't tried it yet, because this idea made me headache...
blu_da_noob, do you perhaps already have written a trigger that way?
06-15-2006, 05:45 PM#5
weaaddar
You could always just seek the players in the player array and find that index.
06-15-2006, 05:46 PM#6
Rising_Dusk
AHH... I see what you meant by the sort then.
You're sorting them by numbers of kills, I see.

Apologies, I must have misinterpreted what you were doing.
What you'd need to do is have a second array where the array pointers are the player numbers, and then the values are their position in the first array. (Basically what Blu said >_>)

That would allow easy access to the values in the firs array of a certain player.
06-15-2006, 05:50 PM#7
blu_da_noob
Erm, it appears he already has a secondary array in which he sorts players. Didn't see that. You've basically implemented my idea already, just do as weaadder said and loop through your player array to find the correct spot.
06-15-2006, 05:54 PM#8
MasterofSickness
@ weaaddar:
You mean using if conditions in the insertion sort?
Please give me some trigger examples, I'm very confused after clearing it up myself that I can't follow the players change for adding 1 to the right owner of killing unit by using this idea with udg_IntAr_Row[]...

The best way to help would post this second array trigger ;)
I start trying this now...
-> Brain tries to think of a solution... !!!... AHH,ouch,ouch!

K, I will try it, but as I said, If you have a trigger like that please show...
06-15-2006, 05:59 PM#9
blu_da_noob
Collapse JASS:
local integer i = 0
local player p = GetOwningPlayer(GetKillingUnit()) //or whatever player you want

loop
     exitwhen udg_IntAr_Player[i] == p
     set i = i + 1
endloop
// i is now the correct position in the kill array to increment
06-15-2006, 06:13 PM#10
MasterofSickness
K, I will try it on tomorrow, I can't think any more.
But one last thing to say:
In the insertion sort trigger "udg_IntAr_Kills[x]" and "udg_IntAr_Player[x]".
The "x" has less to do with any player number, it is the respectively row where the values are sorted to!
set udg_IntAr_Player[ B+1 ]=udg_IntAr_Player[ B ]
This just set the player to the player below him...

I'm so sad... I feel like I will never get that Multiboard to work *cry*
I'm back tomorrow...
EDIT:
Quote:
exitwhen udg_IntAr_Player[i] == p
udg_IntAr_Player[i] is an integer array while p is a player!?
Thx for your help so far...
06-15-2006, 07:18 PM#11
Rising_Dusk
Use this instead.
Collapse JASS:
local integer p = GetPlayerId(GetOwningPlayer(GetKillingUnit()))
06-15-2006, 07:26 PM#12
MasterofSickness
I know that I can use GetPlayerID(), but I...
Ah, it is so horrible, I don't understand what you say.
I have really no idea how to implement this!!!
When should I use this trigger?
Where should I use this trigger?

I have no second player array I think!
I have removed those udg_IntAr_Row now, because they never worked!
So how do I make a second player array?

In your eyes I'm surely a complete idiot, but I know I'm not, but otherwise I don't get what you try to tell me at a whole...
EDIT:
udg_IntAr_Player[1] can be any player number
udg_IntAr_Player[2] can be any player number
.
.
.
udg_IntAr_Player[8] can be any player number
Beside that I'm using Player 1 (Red), 2 (Blue), 3, 4, 6, 7, 8 and 11 and udg_IntAr_Player[x] gets only values from 1-8???
So how should this trigger help me???
06-15-2006, 07:52 PM#13
Rising_Dusk
He's saying in your code, loop through all player indicies and have a SECOND array (In your case udg_IntAr_Player) that loads to it via player number all integer array locations for the other, sorted array.

That way you can use the GetPlayerId() bit and then find the array location of that player in the other array, and THEN use that array location to manipulate their kills.
06-16-2006, 12:39 PM#14
MasterofSickness
That's seriously strange, but after looking through this thread again for arround 2 min today... I understood it!
That's crazy, yesterday I understood really nothing and thought that this simple 2nd loop is something really complicated I had to transfer anyhow to my code, but now it's apparent!
I only can explain this to me, because yesterday I worked arround 6 hours without break at the udg_IntAr_Row - problem before and I was fully concentrated the whole time... properly it was simply too much for one day! Anyhow for me...
But here I have to thank you that you stayed tough and continued with trying to help me!
Thanks Rising Dusk! that you explained probs in detail!
Thanks blu da noob! that you posted this trigger example!
Thanks weaaddar! that you joined this insertion sort subject of me again!

I will now try to make it work! This should be done in short time!
If not I'm writing back, here at my wc3editing home! Greatest Forum Ever!
EDIT: Yeah, works flawlessly! ...and is such an easy solution *argh*