Wc3C.net Find minimal value?
 Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar

 01-31-2010, 05:43 PM #1 rednek ",:..:,"     Join Date: May 2006 Posts: 236 Submissions (11) Find minimal value? Let we say I have 10 integer variables, each of them has random number between 0 and 100. Now, how can I find which one of them has lowest value? Min function World Editor has can compare only two variables (as far as I know) Or I'm doing this, because I'm trying to find closest unit to a certain point. If there's any clear way to find which one is it, well, I'm all ears :) __________________ (lol, a hole in there, damn I fail :C )
 01-31-2010, 05:49 PM #2 Kueken User   Join Date: Mar 2009 Posts: 149 For the first one, use a sort algorithm, or simply loop though the numbers and get the lowest one by multiple comparisons For the second one, pick all units and compare their distances like mentioned
 01-31-2010, 06:24 PM #3 rednek ",:..:,"     Join Date: May 2006 Posts: 236 Submissions (11) Thanks for the reply, could you be more specific please? The number of variables is unknown to me, might be more than 10. I can't imagine how to sucesfully compare them, without having it to be ridiculously long. What is this sorting algoritm you speak of, and how do I accomplish it? __________________ (lol, a hole in there, damn I fail :C ) Last edited by rednek : 01-31-2010 at 06:24 PM.
 01-31-2010, 06:48 PM #4 TriggerHappy ￼   Join Date: Feb 2008 Posts: 405 Submissions (2) Should output the lowest #. Not tested (or syntax checked). JASS:```local integer i = 1 local integer lowest = yourArray[0] local integer index = 0 loop exitwhen i > 10 if (yourArray[i] < lowest) then set lowest = yourArray[i] set index = i endif set i = i + 1 endloop call BJDebugMsg("yourArray["+I2S(index)+"] has the lowest value, " + I2S(lowest)) ```
 01-31-2010, 06:53 PM #5 moyack Evil Emoticon   Respected UserProject Leader: PoC   Join Date: Jan 2006 Posts: 3,279 Submissions (17) JASS:```globals integer array A integer Size = 9 // for values in the array with index between 0 - 9 endglobals function Min10 takes nothing returns integer local integer i = 0 local integer r = A[0] local integer a = 0 loop exitwhen i == Size set a = Min(A[i], A[i+1]) if a < r then set r = a endif set i = i+1 endloop return r endfunction```
01-31-2010, 06:56 PM   #6
Anitarf
Procrastination Incarnate

Development Director

Join Date: Feb 2004
Posts: 8,190

Submissions (19)

If you want to find the nearest unit to a point, PruneGroup can help.
__________________
 Cinema Workshop released! Let's make some cinematics! Editor's version of the winner of the Blizzard's Cinematic Contest: The Spirit of Vengeance

01-31-2010, 07:04 PM   #7
Michael Peppers
Lepus?

Join Date: Jan 2009
Posts: 1,308

Quote:
 Originally Posted by Anitarf If you want to find the nearest unit to a point, PruneGroup can help.
...or my FindUnits =P
__________________
Projects:
Tutorials: Competitive AI Step by Step with AI Editor (Pending)
Resources: [AI Script] Michael Peppers's Melee AI template (Pending)

Last edited by Michael Peppers : 01-31-2010 at 07:04 PM.

01-31-2010, 07:53 PM   #8
Themerion
Brahms-fan

Join Date: Jan 2006
Posts: 642

Submissions (2)

Quote:
 I'm trying to find closest unit to a certain point.

Here's an outline for how it's done. It's made to be simple, read comment on (meaningless? :P) optimizations below.

Trigger:
Set CertainPoint = (Center of (Playable Map Area))
Set TempReal = 500
Set TempUnit = No Unit
Unit Group - Pick All units in 500 from CertainPoint
Loop
If
Conditions
Distance Between (Certain Point) and (Position of (Picked Unit)) less than TempReal
Actions
Set TempUnit = (Picked Unit)
Set TempReal = Distance Between (Certain Point) and (Position of (Picked Unit))

if TempUnit not equal to No Unit
--- Voila, the closest unit was TempUnit ---

Once you understand this outline, you should probably optimize it by storing "Distance Between..." as a variable (so you won't have to check multiple times for the same unit). You should also take care of the point-leaks, and the unit group leak.
__________________
Submissions::
 (v)JASS Tutorial Covers how to make fast and safe coding for common tasks in vJASS/JASS. Creep Respawn System It has never been easier to respawn creep groups...

Last edited by Themerion : 01-31-2010 at 08:00 PM.

 01-31-2010, 10:06 PM #9 rednek ",:..:,"     Join Date: May 2006 Posts: 236 Submissions (11) Whoa, thanks for all the replies, I went with the moyack's one for finding lowest value, and it works perfectly (thanks man) After that, Themerion's trigger was clear as day to me. I'm glad you posted it :P So, yeah, thanks again ^^ __________________ (lol, a hole in there, damn I fail :C ) Last edited by rednek : 01-31-2010 at 10:10 PM.
02-01-2010, 01:06 PM   #10
Anitarf
Procrastination Incarnate

Development Director

Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Quote:
 Originally Posted by rednek Whoa, thanks for all the replies, I went with the moyack's one for finding lowest value, and it works perfectly
It does? It doesn't even compile for me.
__________________
 Cinema Workshop released! Let's make some cinematics! Editor's version of the winner of the Blizzard's Cinematic Contest: The Spirit of Vengeance

02-01-2010, 01:37 PM   #11
moyack
Evil Emoticon

Respected User

Join Date: Jan 2006
Posts: 3,279

Submissions (17)

Quote:
 Originally Posted by Anitarf It does? It doesn't even compile for me.
Man, you suck at coding.... :P

02-01-2010, 05:05 PM   #12
rednek
",:..:,"

Join Date: May 2006
Posts: 236

Submissions (11)

Quote:
 Originally Posted by Anitarf It does? It doesn't even compile for me.

Perhaps, I didn't exactly copy'n'paste it, just saw how it's done and then did it by memory.
__________________

(lol, a hole in there, damn I fail :C )