BAIT Community Project (thread 3)

Miscellaneous Forums/Blitz Showcase/BAIT Community Project (thread 3)

Thanks WolRon, it looks good! As promised, here's the code for the ranking system. Add the following three functions to LeagueTable.bb . The Function LTableRankScores should be called after LTableSort, and the note in LTableDisplay that says that tied scores are not treated differently should be removed.

Function LTableRankScores()

	; Purpose:		Replaces the sorted scores with corresponding ranks
	; Parameters:	None
	; Return:		None
	; Notes:		Tied scores are ranked differently
	
	Local index
	Local botsTied = 1
	
	For index = 1 To LTableNumberOfBots
	
		If index = LTableNumberOfBots
		
			LTableReplaceScores( LTableCalculateAverageRank( index, botsTied ), index, botsTied )
		
		Else
		
			If LTablePoints(index - 1) <> LTablePoints(index)
			
				LTableReplaceScores( LTableCalculateAverageRank( index, botsTied ), index, botsTied )
				botsTied = 1
			
			Else
			
				botsTied = botsTied + 1
			
			EndIf
		
		EndIf  
	
	Next

End Function

Function LTableCalculateAverageRank( index, botsTied )

	; Purpose:		Returns the average rank for tied bots
	; Parameters:	index, the last index where bots have tied, and
	;				botsTied, how many bots have tied
	; Return:		The average rank ( an integer ) 
	; Notes:		Averages are rounded up to prevent decimal ranks

	Local rankSum# = 0
	Local ranksLeftToSum = botsTied
	
	While ranksLeftToSum > 0
	
		rankSum = rankSum + (LTableNumberOfBots - index) + 1
		index = index - 1
		ranksLeftToSum = ranksLeftToSum - 1
	
	Wend

	Return Ceil (rankSum / botsTied)

End Function

Function LTableReplaceScores( rank, index, botsTied )

	; Purpose:		Replaces scores with their corresponding ranks
	; Parameters:	rank, the rank to replace the scores with,
	;				index, the last index where bots have tied, and
	;				botsTied, how many bots have tied
	; Return:		None
	; Notes:		None
	
	While botsTied > 0
	
		LTablePoints(index - 1) = rank
		index = index - 1
		botsTied = botsTied - 1
	
	Wend

End Function


P.S. I've a bit more free time on my hands, any more simple 2D algorithms I can help with? Also, how is BVM coming along?

Ryan