// A game's high-score table: best scores kept, the top 3, a player's rank and neighbours.
//
//   quillo run leaderboard.qwe      then open http://localhost:8080/board

use "leaderboard.qwer"

route POST /score = leaderboard_score("arcade", request.json.player, int(request.json.score), "best")?

route GET /board {
    leaderboard_reset("demo", "")?
    for p in [["ada", 900], ["bo", 750], ["cy", 750], ["di", 600], ["ed", 1200], ["fi", 300]] {
        leaderboard_score("demo", p[0], p[1], "best")?
    }
    leaderboard_score("demo", "fi", 100, "best")?          // lower than fi's best: kept at 300
    leaderboard_score("demo", "di", 200, "add")?           // 600 + 200
    { top: leaderboard_top("demo", 3)?, di: leaderboard_rank("demo", "di")?, around_cy: leaderboard_around("demo", "cy", 1)? }
}
