A-Net Online

  • HiScore algorithm.

    From xqtr@911:30210/0 to All on Sat Dec 3 20:39:05 2022
    So, you are writing a game for BBSes and want to have a High Score board. Which would be the best option to make this? I mean the logic/algorithm to insert a new score into the board.

    In the past i used to ways. The first one.

    Have an array with the highscores. Iterate through the array, comparing the scores with the new one, you are checking to see if it has to be in it. If the current score is a high score, you save the index of the item in the array, move all items one position below that index and store the current score in that position.

    I think it's the most straight forward thing to do, but i think it's more complicated than it should be, which results in my second method.

    Have the scores stored in an array, that is larger by one. For example if you have a Top 10, you use in your program an array of 11 items. When you want to store/check the current score, you put it in the last position and then sort the array. Automatically the current score, will be put in the right position and the 11th item, should be ignored and not used.

    The sort method could be anything and it doesn't need something complicated, a simple quicksort method is fine, after all there aren't too many stuff to compare. Below is a snippet of code, with the simplest possible way.

    procedure sortscorers;
    var
    i,k:byte;
    begin
    for i:=1 to 10 do
    for k:=i+1 to 11 do
    if Highscores[i].score < Highscores[k].score then Highscores[i].score:=Highscores[k];
    end;

    This is referred to a Top 10 high score board.

    .
    :: XQTR :: Another Droid BBS :: andr01d.zapto.org:9999 :: xqtr@gmx.com

    --- Mystic BBS v1.12 A47 2020/11/23 (Raspberry Pi/32)
    * Origin: Another Droid BBS # andr01d.zapto.org:9999 (911:30210/0)