Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
DARKBASIC PRO 3d WORLD EDITOR
13
Years of Service
User Offline
Joined: 2nd May 2012
Location:
Posted: 2nd May 2015 07:50
Okay.. I have been using the concept of sorting arrays as non-UDT arrays but I decided to go the UDT route because it is just easier to read and write. I also seen Ian's commands which made me want to do this even more. However, I've run into a problem in sorting where I can't sort like I want to...


non-UDT array sort

do
flag=0

for i=1 to 399
if PlayerStats(team,i,0)>PlayerStats(team,i+1,0)
a=PlayerStats(team,i,0): b=PlayerStats(team,i+1,0)
PlayerStats(team,i,0)=b: PlayerStats(team,i+1,0)=a
for j=1 to 40
a=PlayerStats(team,i,j): b=PlayerStats(team,i+1,j)
PlayerStats(team,i,j)=b: PlayerStats(team,i+1,j)=a
next j
flag=1
endif
next i

if flag=0 then exit

loop


This method worked when the '0' in the variable -----> PlayerStats(team,i,0) was the variable to sort


but now I have instead of PlayerStats(team,player,0-40)
I have... PlayerStats(team,player).Name which is then first item.. I can't seem to sort with Ian's commands.. help!!

- Infinity is Simplicity -
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 2nd May 2015 10:01 Edited at: 2nd May 2015 10:04
Why not do

Should be easier to sort if it is not mixing both udt and multi dimension

DARKBASIC PRO 3d WORLD EDITOR
13
Years of Service
User Offline
Joined: 2nd May 2012
Location:
Posted: 2nd May 2015 22:53
Quote: "Should be easier to sort if it is not mixing both udt and multi dimension"


Well to give a better detail, this is what I'm doing now with the UDT..



I dont know if anyone is familiar with basketball but this is an array to hold players data.. 40 teams, 15 players a peice
All the players have been randomly given values from name to ratings..
Doing this however, it doesn't fix the depth chart accordingly...

like..


.Name .Pos .Height .Age .OVR
---------------------------------------------------
player(1,1) Justin Powers PF 6'11" 26 77 starters
player(1,2) Rob Manowski SF 6'10" 23 82
player(1,3) Jim Jefferson C 6'11" 27 78
player(1,4) Brandon Hollis PG 6'2" 29 76
player(1,5) Jimmy Gordon SG 6'5" 32 73
---------------------------------------------------
player(1,6) Al Harris PF 6'8" 30 73 bench
player(1,7) Steve Porter SF 6'8" 35 61
player(1,8) Harold Woods C 6'10" 30 72
player(1,9) Stevie Hardy PG 6'7" 21 70
player(1,10) Prince Powers SG 6'5" 22 84
player(1,11) Jin Lee PF 6'11" 22 74
player(1,12) John Martinez SF 6'10" 22 70
player(1,13) Jeff Brown C 6'11" 25 68
player(1,14) Daquan Sanders PG 6'1" 18 68
player(1,15) Drazen Mozgov SG 6'4" 19 69

If your familiar with basketball.. You know the starting five most likely are the best 5 players. This isn't the case here as random values are given. I want to sort it so the best PF overall is always first. E.g. player(x,1) with x being the team number. The 2nd best PF would be 6 and last would be 11.

starting bench bench
1 PF 6 PF 11 PF
2 SF 7 SF 12 SF
3 C 8 C 13 C
4 PG 9 PG 14 PG
5 SG 10 SG 15 SG


so looking back at the data table..
Prince Powers should be the starting SG because he is 84 OVR and the current starter is only 73 OVR

My fault to get into detail, but thats the only way I can explain it fully...

*side note* if you want a name generator or a schedule maker, I have source available...

- Infinity is Simplicity -
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 3rd May 2015 14:49 Edited at: 3rd May 2015 20:46
How about use 'Linked Lists', parent and child structure for this.

You'd have an array that holds all the team data, then you'd have one that holds all the player data and each player is just added to a team in a list fashion.

I prefer this method because players or entities are treated singularly, can be easily moved and edited and aren't bound to a specific array.

Another advantage is it saves memory cause you only use want you need and don't need to predefine array limits which affect every team. Say team A has 30 players (b players etc...) and team B as 10 players, you'd have to make the array _data(2,30) < but this means that team B has 20 empty players stored in memory doing nothing and it's limited to 20 more players. But doing link listed we can have any amount of teams and players in a team without empty arrays and doesn't affect other arrays elements when we want to add or delete entries.

Here's an example:


"Get in the Van!" - Van B
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 5th May 2015 19:37
Agreed. Using multidimensional arrays reduces the amount of array manipulation functionality available to you if you stick with one column; its logic is easier to work with and permits you to give the teams some crucial information:

Teams( Player(MyPlayer).Team ).Score = 0

Sets the teams score to zero

Player(MyTeam, MyPlayer).Score = 0

Would only set the player's score to zero, you'd have to iterate all the other players to set their scores aswell. Even if you worked around that, the name of the variable is not self descriptive; think of reading the following in 12 months time after college/uni/holiday/marriage or some other conflicting event:

Player(4,3).Age = 30 // Tired programmer asks 'Is that team 4 or player 4'

Quote: "players or entities are treated singularly, can be easily moved and edited and aren't bound to a specific array. "


I think this is the cruicial point; what if you decide to allow teams to employ substitute players, or what if you wanted to add a reserves team?



Obviously what Ortu and Sasuke stated is more than sufficient; but it doesn't hurt to contribute an additional opinion.

Bored of the Rings
User Banned
Posted: 8th May 2015 09:42 Edited at: 8th May 2015 09:52
I don't know if this is any help, but the code below is how I performed a UDT sort:

The function for the UDT sort is:
function AlphaSortUDT(sortorder,debug).

The program as a whole just does a sort (on a data list of functions) without UDT and then does it with UDT. I wanted to see how long both ways took and too see which was more efficient/practical for the project I wanted to use it in.

Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 8th May 2015 13:31 Edited at: 9th May 2015 01:12
@Bored of the Rings, there's a few things you can do to greatly reduce and make it more efficient.

In your code this adds an empty array element at the end... probably want to remove that


Timer() can't be set, it just returns system clock so you can remove timer()=0

You can simply do if upper$(string$(n)) > upper$(string$(n+1)) to see if it needs to be swapped, make some sort of recursion round it and it's sorted.

Treat the UDT's exactly the same when swapping, so:


"Get in the Van!" - Van B

Login to post a reply

Server time is: 2025-05-12 02:27:43
Your offset time is: 2025-05-12 02:27:43