Notifications
Clear all

Scoreboard/Leaderboard

9 Posts
2 Users
0 Likes
192 Views
(@bwinter)
Member
Joined: 1 month ago
Posts: 3
Topic starter  

I'm working on an Arduino-based game for kids (somewhat like an "escape-room" type challenge). It'll be a time-based challenge, with the duration simply measured by a start/stop trigger (to derive the CurrentScore). I'd also like to be able to track scoring (HighScore), and possibly a leader-board.  Tracking the HighScore is rather simple (I think):  If CurrentScore < HighScore, then CurrentScore = HighScore.

However, I'm stumped on how to implement the following:

  • I'd like to track the player-initials (and possibly date time stamp) of the high score.  Obviously, I would have an input device (such as a TFT touchscreen) that I would use to both input initials and display the score.  I guess I could simply expand the code above to also switch CurrentScoreInitials with HighScoreInitials--but I'm wondering if there's a better method.
  • I'd also like to possibly keep a leaderboard (of the top scores), keeping both the time, initials and date time stamp.  This would be used to display/track the top 5-10 scores, sorted.

Is there any elegant method to track this information?  I'm somewhat aware of how to "data-log" to an SD card--but not sure if this is the right path to investigate.

My programming-level is probably low-level intermediate--I have a good understanding of the basic Arduino programming, but I'm wondering if there are other Arduino functions out there that I simply haven't been exposed to yet.

This topic was modified 1 month ago by bwinter

   
Quote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6972
 

bwinter I think your estimate of your programming creds may be optimistic given you said

 Tracking the HighScore is rather simple (I think):  If CurrentScore < HighScore, then CurrentScore = HighScore.

That is two errors. It should be

  if CurrentScore > HighScore then HighScore = CurrentScore

Not to worry, I have over 50 years experience and am autistic so make errors like that all the time.

You probably will need to add some more reliable (regular SD cards are NOT reliable) semi-permanent memory. An inexpensive small USB memory stick, EEPROM, and probably some choices I have overlooked. SD can be an option if it is the special High Wear types used for security cameras.

All your other requirements are easy enough and your design choices are possible but may not be ideal in that TFT screens and handwriting initials is more art than science. A mini keyboard even on screen is a more reliable method and obviously any time keeping is trivial for an MCU/MPU.

A 'leader board' is a classic Data Processing problem with several solutions. Since it is only a small number, an array that is looped over comparing existing numbers to a new entry and copying from either old or newest to the new array is a brute force approach, while some sort of in memory sort is another. I have a long history with this and used a 3rd approach I call 'Named Doubly Linked Lists. it is modelled after a certain OS list manager but I got rid of all my code after I retired thinking I would never use it again so although I recently started to resurrect it, it is far from complete and will take me months to years to complete as I can only work a few days a week for a few hours a day due to health issues. I recommend either doing an array type approach or looking for a sort library.

Good luck.

 

 

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@bwinter)
Member
Joined: 1 month ago
Posts: 3
Topic starter  

Thanks for the reply!

Actually since this would be a speed-based challenge, the lowest time would be the "high score" (as far as the leaderboard goes).  So I would think that the < is the appropriate operator--but you're correct on the second mistake.  I actually haven't written this sketch yet (let alone tested)--it was just an off-the-cuff example of what I was thinking.

As far as inputting the initials, I was planning to use some type of TFT keyboard and certainly not trying to interpret hand-written letters (that's nowhere in my realm of possibility).

Regarding the array:  that was something I was considering, but my entry-level array-knowledge in Arduino is generally limited to using an array to "set a bank of pins to high/low."  But 1) I wasn't sure if arrays could be sorted (I haven't come across that yet), and 2) so far I've only thought an array contain a single variable-type (such as TIME), so it wasn't clear how I'd link to the other arrays (such as INITIALS) after any sort.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6972
 

@bwinter Please use the Reply link at the bottom right so the poster gets an email to notify them.

I saw SCORE not time. Some sort of cultural difference?

You could still use a TFT, just write out the letters and then when the user taps a letter the touch API should be good enough to give the correct answer, but of course you could do an 'did you mean X? followed by a large YES and NO tappable area. OR several other paradigms are possible.

An array is just a chunk of memory, what it contains is up to the programmer. Often it is just a pointer to a data structure. You don't sort the array, you create a second array, then loop over the first array (already sorted from earlier) comparing that data to the now best score data and when you find where it logically belongs, put that address (of the new best score) into the output array. then finish copying the next n-1 entries. It's -1 since the input might be 5+1(new) being copied into 5 where 5 is whatever you decide is the number of leaders to keep.

Clear?

I will prepare a sample sketch demonstrating these techniques.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6972
 

@bwinter As I promised. Here is Ver 1 (there will be more) of a sketch to give you an idea about structs and arrays. This is basic, I will fancy it up a bit in a few minutes so stay tuned for more.

struct sLeaderBoard {
  int score = 0;
  char init1 = ' ';
  char init2 = ' ';
};

struct sLeaderBoard LeaderBoard[5];

void setup() {
  Serial.begin(115200);
  while (!Serial.availableForWrite()) {}

// There are several ways to initialize an array, this is one
// Notice array index and members can be out of order
  LeaderBoard[1].score = 12000;
  LeaderBoard[0].init1 = 'M';
  LeaderBoard[1].init2 = 'E';

  LeaderBoard[0].init2 = 'Y';
  LeaderBoard[1].init1 = 'N';
  LeaderBoard[0].score = 17000;
}

void loop() {
  // put your main code here, to run repeatedly:
  int numLeaders = 2;
  int indxLeaders = 0;

  for (indxLeaders = 0; indxLeaders < numLeaders; ++indxLeaders){
    Serial.print(" Initials="); 
    Serial.print(LeaderBoard[indxLeaders].init1);
    Serial.print(LeaderBoard[indxLeaders].init2);
    Serial.print(" score=");
    Serial.println(LeaderBoard[indxLeaders].score);
  }
  delay(10000);
}

 

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@bwinter)
Member
Joined: 1 month ago
Posts: 3
Topic starter  

@zander 

This is making sense.  I haven't been exposed to STRUCT yet, so I think this is pointing me in the right direction for what functions I need to study more.  What you've provided above is enough for me to keep moving forward--thanks!


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6972
 

@bwinter I am working on a little more. I am old so work slow.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6972
 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6972
 

@bwinter Hmm, I don't see my post and code, I see it as all blank. Here is the original post and now I will attach a zip file.

====

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote