ID:152336
 
This may not be where this should go but I would call it "Code Philosophy" So this is the closest thing to that...


I'm making a Laser Tag game and I'm not at home so I can't test this code. If any of you could tell me how "good" or "bad" this code is, it would be appreciated.

Sorting Players Based on Score:
proc/pickHighest(var/i)
var/highest=0
var/mob/R
for(;i<players.len;i++)
if(players[i].score >= highest) //Not sure if you can access a mob's vars from a list like this.
highest=players[i].score
R=players[i]
return R

proc/sortPlayers()//This is sort the players by picking the highest out of the list, eliminating one, each run through the loop.
var/i=1
for(var/mob/M in players)
scores[i]=pickHighest(i)
i++


Calculating Score:
mob/proc/calAccuracy()
if(src.client)
return((Shots_Hit/Shots_Fired)*100)
else
return 0 // or null

mob/proc/calScore()
if(src.client)
var/temp_score= src.Shots_Hit * 3.5 // 3.5 is not definite, not sure how high I want the scores to go.
return temp_score + (temp_score * (src.calAccuracy()/100))
else
return 0 // or null



Thats what I've got for now, what do you guys/girls think?

Is it good?
Will it work?
Is it efficient?

-KirbyAllStar
I'm not bumping this, just saying thanks to Jik for replying and for deleting his reply...
In response to KirbyAllStar (#1)
KirbyAllStar wrote:
I'm not bumping this, just saying thanks to Jik for replying and for deleting his reply...

Sorry Kirby,

I posted a reply but read the order of the procs wrong...

I stated that the scoring looks good, but I'd need to make more code to test it. As to the sorting proc, something seemed wrong with it to me, but I have to check again...

[EDIT]

I think I see it now...
proc/pickHighest(var/i)
var/highest=0
var/mob/R
for(;i<players.len;i++)
if(players[i].score >= highest) //Not sure if you can access a mob's vars from a list like this.
highest=players[i].score
R=players[i]
return R

proc/sortPlayers()//This is sort the players by picking the highest out of the list, eliminating one, each run through the loop.
var/i=1
for(var/mob/M in players)
scores[i]=pickHighest(i)
i++


I follow the sortPlayers itterations. you'll find the first highest score in pickHighest(), as you look from player 1 to x(last player). But if player 1 doesn't have the highest score, he is excluded in the next check when i is incremented. The same will happen with players[2] on the 3rd pass, and so on.
In response to Jik (#2)
proc
PickHighest()
var/list/L = new()
for(var/client/C)
L += C.mob.score
return max(L)
In response to Xx Dark Wizard xX (#3)
Xx Dark Wizard xX wrote:
> proc
> PickHighest()
> var/list/L = new()
> for(var/client/C)
> L += C.mob.score
> return max(L)

damn... I didn't know there was a proc called max... I went and created my own sort for nothing...
In response to Jik (#4)
Its ok Jik, your first post gave me ideas.

I like the idea of the max proc but its not what I need, I'm sorting the players by there scores not just the scores...

Here's my modified version
var/list/temp=new/list()
var/list/score_list=new/list()

proc/sortPlayers()
temp=players
for(var/i=1; i < players.len; i++)
score_list[i]=pickHighest()
i++

proc/pickHighest()
var/highest=0
var/mob/R
for(var/i=1;i<=temp.len;i++)
if(temp[i].score>=highest)
highest=temp[i].score
R = temp[i]
temp-=R
return R


Hopefully that would work better I should be able to test it all soon.
In response to KirbyAllStar (#5)
Be careful. Since lists are actually treated like objects (as in elements, not objs), removing those players from the temp list will in fact also remove them from the players list. Be sure to use list.Copy() to get a new version of the list that's safe to change.

Also, instead of creating the temp list at the base level, why not just create when you need it and then pass it through the arguments?
In response to DarkCampainger (#6)
Wow, thank you.

That would have screwed with quite a lot.
In response to KirbyAllStar (#7)
KirbyAllStar wrote:
Wow, thank you.

That would have screwed with quite a lot.

I did something similar in my card game when I was setting the deal order. I did "var/list/DealOrder = Joined", and found that it messed up all the deals after the first hand...