Skip to content

Commit 095da50

Browse files
authored
Add high-scores (#128)
1 parent 5c968b1 commit 095da50

9 files changed

Lines changed: 221 additions & 0 deletions

File tree

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,14 @@
282282
"prerequisites": [],
283283
"difficulty": 3
284284
},
285+
{
286+
"slug": "high-scores",
287+
"name": "High Scores",
288+
"uuid": "0d067c10-738a-475c-a0a3-3f95b45f3a5f",
289+
"practices": [],
290+
"prerequisites": [],
291+
"difficulty": 3
292+
},
285293
{
286294
"slug": "house",
287295
"name": "House",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
return {
2+
default = {
3+
ROOT = { '.' }
4+
}
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Instructions
2+
3+
Manage a game player's High Score list.
4+
5+
Your task is to build a high-score component of the classic Frogger game, one of the highest selling and most addictive games of all time, and a classic of the arcade era.
6+
Your task is to write methods that return the highest score from the list, the last added score and the three highest scores.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"authors": [
3+
"glennj"
4+
],
5+
"files": {
6+
"solution": [
7+
"high_scores.moon"
8+
],
9+
"test": [
10+
"high_scores_spec.moon"
11+
],
12+
"example": [
13+
".meta/example.moon"
14+
]
15+
},
16+
"blurb": "Manage a player's High Score list.",
17+
"source": "Tribute to the eighties' arcade game Frogger"
18+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class HighScores
2+
new: (@_scores) =>
3+
@_sorted = [s for s in *@_scores]
4+
table.sort @_sorted, (a, b) -> b < a
5+
6+
scores: => @_scores
7+
latest: => @_scores[#@_scores]
8+
personalBest: => @_sorted[1]
9+
personalTopThree: => {table.unpack @_sorted, 1, 3}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
int_list = (list) -> "{#{table.concat list, ', '}}"
2+
3+
4+
{
5+
module_name: 'HighScores',
6+
7+
generate_test: (case, level) ->
8+
lines = {
9+
"scores = HighScores #{int_list case.input.scores}"
10+
}
11+
12+
switch case.property
13+
when 'latestAfterTopThree'
14+
table.insert lines, "_ = scores\\personalTopThree!"
15+
table.insert lines, "result = scores\\latest!"
16+
when 'scoresAfterTopThree'
17+
table.insert lines, "_ = scores\\personalTopThree!"
18+
table.insert lines, "result = scores\\scores!"
19+
when 'latestAfterBest'
20+
table.insert lines, "_ = scores\\personalBest!"
21+
table.insert lines, "result = scores\\latest!"
22+
when 'scoresAfterBest'
23+
table.insert lines, "_ = scores\\personalBest!"
24+
table.insert lines, "result = scores\\scores!"
25+
else
26+
table.insert lines, "result = scores\\#{case.property}!"
27+
28+
if type(case.expected) == 'table'
29+
table.insert lines, "expected = #{int_list case.expected}"
30+
else
31+
table.insert lines, "expected = #{case.expected}"
32+
33+
table.insert lines, "assert.are.same expected, result"
34+
table.concat [indent line, level for line in *lines], '\n'
35+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[1035eb93-2208-4c22-bab8-fef06769a73c]
13+
description = "List of scores"
14+
15+
[6aa5dbf5-78fa-4375-b22c-ffaa989732d2]
16+
description = "Latest score"
17+
18+
[b661a2e1-aebf-4f50-9139-0fb817dd12c6]
19+
description = "Personal best"
20+
21+
[3d996a97-c81c-4642-9afc-80b80dc14015]
22+
description = "Top 3 scores -> Personal top three from a list of scores"
23+
24+
[1084ecb5-3eb4-46fe-a816-e40331a4e83a]
25+
description = "Top 3 scores -> Personal top highest to lowest"
26+
27+
[e6465b6b-5a11-4936-bfe3-35241c4f4f16]
28+
description = "Top 3 scores -> Personal top when there is a tie"
29+
30+
[f73b02af-c8fd-41c9-91b9-c86eaa86bce2]
31+
description = "Top 3 scores -> Personal top when there are less than 3"
32+
33+
[16608eae-f60f-4a88-800e-aabce5df2865]
34+
description = "Top 3 scores -> Personal top when there is only one"
35+
36+
[2df075f9-fec9-4756-8f40-98c52a11504f]
37+
description = "Top 3 scores -> Latest score after personal top scores"
38+
39+
[809c4058-7eb1-4206-b01e-79238b9b71bc]
40+
description = "Top 3 scores -> Scores after personal top scores"
41+
42+
[ddb0efc0-9a86-4f82-bc30-21ae0bdc6418]
43+
description = "Top 3 scores -> Latest score after personal best"
44+
45+
[6a0fd2d1-4cc4-46b9-a5bb-2fb667ca2364]
46+
description = "Top 3 scores -> Scores after personal best"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class HighScores
2+
new: (scoreList) =>
3+
error 'Implement the constructor'
4+
5+
scores: =>
6+
error 'Implement the scores method'
7+
8+
latest: =>
9+
error 'Implement the latest method'
10+
11+
personalBest: =>
12+
error 'Implement the personalBest method'
13+
14+
personalTopThree: =>
15+
error 'Implement the personalTopThree method'
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
HighScores = require 'high_scores'
2+
3+
describe 'high-scores', ->
4+
it 'List of scores', ->
5+
scores = HighScores {30, 50, 20, 70}
6+
result = scores\scores!
7+
expected = {30, 50, 20, 70}
8+
assert.are.same expected, result
9+
10+
pending 'Latest score', ->
11+
scores = HighScores {100, 0, 90, 30}
12+
result = scores\latest!
13+
expected = 30
14+
assert.are.same expected, result
15+
16+
pending 'Personal best', ->
17+
scores = HighScores {40, 100, 70}
18+
result = scores\personalBest!
19+
expected = 100
20+
assert.are.same expected, result
21+
22+
describe 'Top 3 scores', ->
23+
pending 'Personal top three from a list of scores', ->
24+
scores = HighScores {10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70}
25+
result = scores\personalTopThree!
26+
expected = {100, 90, 70}
27+
assert.are.same expected, result
28+
29+
pending 'Personal top highest to lowest', ->
30+
scores = HighScores {20, 10, 30}
31+
result = scores\personalTopThree!
32+
expected = {30, 20, 10}
33+
assert.are.same expected, result
34+
35+
pending 'Personal top when there is a tie', ->
36+
scores = HighScores {40, 20, 40, 30}
37+
result = scores\personalTopThree!
38+
expected = {40, 40, 30}
39+
assert.are.same expected, result
40+
41+
pending 'Personal top when there are less than 3', ->
42+
scores = HighScores {30, 70}
43+
result = scores\personalTopThree!
44+
expected = {70, 30}
45+
assert.are.same expected, result
46+
47+
pending 'Personal top when there is only one', ->
48+
scores = HighScores {40}
49+
result = scores\personalTopThree!
50+
expected = {40}
51+
assert.are.same expected, result
52+
53+
pending 'Latest score after personal top scores', ->
54+
scores = HighScores {70, 50, 20, 30}
55+
_ = scores\personalTopThree!
56+
result = scores\latest!
57+
expected = 30
58+
assert.are.same expected, result
59+
60+
pending 'Scores after personal top scores', ->
61+
scores = HighScores {30, 50, 20, 70}
62+
_ = scores\personalTopThree!
63+
result = scores\scores!
64+
expected = {30, 50, 20, 70}
65+
assert.are.same expected, result
66+
67+
pending 'Latest score after personal best', ->
68+
scores = HighScores {20, 70, 15, 25, 30}
69+
_ = scores\personalBest!
70+
result = scores\latest!
71+
expected = 30
72+
assert.are.same expected, result
73+
74+
pending 'Scores after personal best', ->
75+
scores = HighScores {20, 70, 15, 25, 30}
76+
_ = scores\personalBest!
77+
result = scores\scores!
78+
expected = {20, 70, 15, 25, 30}
79+
assert.are.same expected, result

0 commit comments

Comments
 (0)