ID:158962
 
Hi, not really a coding problem as i'm a bit lost on how to even do this, while I do know how to code, my math isn't too great, sadly, so making an algorithm like this would prove difficult.

My obj/cards for creatures have an ATK value, and I want to know how to make a PROC where I can send a list, and it'll return the highest, mid, or lowest ATK/DEF value based on arguments I send sortproc(listname,1,1)

the second 1 being "Atk" (0 is defense), and the first 1 being "Mid", 2 being high, 0 being lowest.

The thing needs to be able to list all sorts of atoms too, obj, turf, mobs, ect
Update! I don't need middle

I did this code myself, will someone just tell me if this will work? I don't want to have to make a bunch of unneeded code to test it.

atom
proc
highestlowest(var/list/L1,var/highlow,var/atkdef)
if(atkdef==1)
if(highlow==0)
var/sort1 = 0
var/list/HightoLow=list()
var/I = 0
var/I2 = L1.len
var/I3 = L1.len
while(sort1==1)
var/sort2=0
for(var/obj/card/C1 in L1)
if(C1)
I2 = L1.len
var/obj/card/C2
sort2=0
while(sort2==0)
C2 = L1.Find(/obj/card,I,I)
if(C1.ccurrentatk>=C2.ccurrentatk)
I++
if(I==I2)
HightoLow+=C1
L1-=C1
sort2=1
var/I4 = HightoLow.len
if(I4==I3)
return HightoLow
if(highlow==1)
var/sort1 = 0
var/list/lowtohigh=list()
var/I = 0
var/I2 = L1.len
var/I3 = L1.len
while(sort1==1)
var/sort2=0
for(var/obj/card/C1 in L1)
if(C1)
I2 = L1.len
var/obj/card/C2
sort2=0
while(sort2==0)
C2 = L1.Find(/obj/card,I,I)
if(C1.ccurrentatk<=C2.ccurrentatk)
I++
if(I==I2)
lowtohigh+=C1
L1-=C1
sort2=1
var/I4 = lowtohigh.len
if(I4==I3)
return lowtohigh
else
if(highlow==0)
var/sort1 = 0
var/list/HightoLow=list()
var/I = 0
var/I2 = L1.len
var/I3 = L1.len
while(sort1==1)
var/sort2=0
for(var/obj/card/C1 in L1)
if(C1)
I2 = L1.len
var/obj/card/C2
sort2=0
while(sort2==0)
C2 = L1.Find(/obj/card,I,I)
if(C1.ccurrentdef>=C2.ccurrentdef)
I++
if(I==I2)
HightoLow+=C1
L1-=C1
sort2=1
var/I4 = HightoLow.len
if(I4==I3)
return HightoLow
if(highlow==1)
var/sort1 = 0
var/list/lowtohigh=list()
var/I = 0
var/I2 = L1.len
var/I3 = L1.len
while(sort1==1)
var/sort2=0
for(var/obj/card/C1 in L1)
if(C1)
I2 = L1.len
var/obj/card/C2
sort2=0
while(sort2==0)
C2 = L1.Find(/obj/card,I,I)
if(C1.ccurrentdef<=C2.ccurrentdef)
I++
if(I==I2)
lowtohigh+=C1
L1-=C1
sort2=1
var/I4 = lowtohigh.len
if(I4==I3)
return lowtohigh






In response to Asellia
I'm finding it difficult to read what you've written, but it seems to be much too long. Here's what I'd do:

//hilo = 1 for highest, 0 for lowest
//atkdef = 1 for atk, 0 for def
proc/findextreme(var/list/L, var/hilo, var/atkdef)
//just grab the first card to start with
var/card/best = L[1]
for(var/card/C in L)
if(atkdef)
if(hilo)
if(C.atk > best.atk)
best = C
else
if(C.atk < best.atk)
best = C
else
if(hilo)
if(C.def > best.def)
best = C
else
if(C.atk < best.atk)
best = C
return best