git_game_show 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/git_game_show/cli.rb +175 -123
- data/lib/git_game_show/game_server.rb +610 -233
- data/lib/git_game_show/player_client.rb +307 -292
- data/lib/git_game_show/updater.rb +17 -17
- data/lib/git_game_show/version.rb +1 -1
- data/lib/git_game_show.rb +4 -4
- data/mini_games/date_ordering_quiz.rb +78 -21
- metadata +2 -2
@@ -13,7 +13,7 @@ module GitGameShow
|
|
13
13
|
latest_version = fetch_latest_version
|
14
14
|
|
15
15
|
return if latest_version.nil?
|
16
|
-
|
16
|
+
|
17
17
|
# Compare versions
|
18
18
|
if newer_version_available?(current_version, latest_version)
|
19
19
|
display_update_prompt(current_version, latest_version)
|
@@ -26,7 +26,7 @@ module GitGameShow
|
|
26
26
|
begin
|
27
27
|
uri = URI.parse("https://rubygems.org/api/v1/gems/git_game_show.json")
|
28
28
|
response = Net::HTTP.get_response(uri)
|
29
|
-
|
29
|
+
|
30
30
|
if response.code == "200"
|
31
31
|
data = JSON.parse(response.body)
|
32
32
|
return data["version"]
|
@@ -57,22 +57,22 @@ module GitGameShow
|
|
57
57
|
|
58
58
|
def display_update_prompt(current_version, latest_version)
|
59
59
|
prompt = TTY::Prompt.new
|
60
|
-
|
60
|
+
|
61
61
|
# Clear the terminal for better visibility
|
62
62
|
puts "\n\n"
|
63
|
-
|
64
|
-
puts "
|
65
|
-
puts "
|
66
|
-
puts "
|
67
|
-
puts "
|
68
|
-
puts "
|
69
|
-
puts "
|
70
|
-
puts "
|
71
|
-
puts "
|
63
|
+
|
64
|
+
puts "╭―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――╮".colorize(:cyan)
|
65
|
+
puts "│ UPDATE AVAILABLE FOR GIT GAME SHOW │".colorize(:cyan)
|
66
|
+
puts "├―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――┤".colorize(:cyan)
|
67
|
+
puts "│ │".colorize(:cyan)
|
68
|
+
puts "│ Current version: #{current_version.ljust(44)}│".colorize(:cyan)
|
69
|
+
puts "│ Latest version: #{latest_version.ljust(44)}│".colorize(:cyan)
|
70
|
+
puts "│ │".colorize(:cyan)
|
71
|
+
puts "╰―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――╯".colorize(:cyan)
|
72
72
|
puts "\n"
|
73
|
-
|
73
|
+
|
74
74
|
update_now = prompt.yes?("Would you like to update now?")
|
75
|
-
|
75
|
+
|
76
76
|
if update_now
|
77
77
|
perform_update
|
78
78
|
else
|
@@ -83,12 +83,12 @@ module GitGameShow
|
|
83
83
|
|
84
84
|
def perform_update
|
85
85
|
puts "\nUpdating Git Game Show to the latest version...".colorize(:cyan)
|
86
|
-
|
86
|
+
|
87
87
|
begin
|
88
88
|
# Use system to capture both stdout and stderr
|
89
89
|
update_command = "gem update git_game_show"
|
90
90
|
result = system(update_command)
|
91
|
-
|
91
|
+
|
92
92
|
if result
|
93
93
|
puts "\n✅ Update completed successfully!".colorize(:green)
|
94
94
|
puts "Please restart Git Game Show to use the new version.".colorize(:yellow)
|
@@ -104,4 +104,4 @@ module GitGameShow
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
end
|
107
|
-
end
|
107
|
+
end
|
data/lib/git_game_show.rb
CHANGED
@@ -17,16 +17,16 @@ require 'net/http'
|
|
17
17
|
# Define module and constants first before loading any other files
|
18
18
|
module GitGameShow
|
19
19
|
# VERSION is defined in version.rb
|
20
|
-
|
20
|
+
|
21
21
|
# Default configuration
|
22
22
|
DEFAULT_CONFIG = {
|
23
|
-
|
23
|
+
internal_port: 80,
|
24
24
|
rounds: 3,
|
25
25
|
question_timeout: 30, # seconds
|
26
26
|
question_display_time: 5, # seconds to show results before next question
|
27
27
|
transition_delay: 5 # seconds between rounds
|
28
28
|
}.freeze
|
29
|
-
|
29
|
+
|
30
30
|
# Message types for WebSocket communication
|
31
31
|
module MessageType
|
32
32
|
JOIN_REQUEST = 'join_request'
|
@@ -47,4 +47,4 @@ end
|
|
47
47
|
Dir[File.join(__dir__, 'git_game_show', '*.rb')].sort.each { |file| require file }
|
48
48
|
|
49
49
|
# Load all mini-games
|
50
|
-
Dir[File.join(__dir__, '..', 'mini_games', '*.rb')].sort.each { |file| require file }
|
50
|
+
Dir[File.join(__dir__, '..', 'mini_games', '*.rb')].sort.each { |file| require file }
|
@@ -179,29 +179,68 @@ module GitGameShow
|
|
179
179
|
def evaluate_answers(question, player_answers)
|
180
180
|
results = {}
|
181
181
|
|
182
|
+
# Safety check for nil or empty responses
|
183
|
+
return results if player_answers.nil? || player_answers.empty?
|
184
|
+
return results unless question && question[:correct_answer]
|
185
|
+
|
186
|
+
# Get total number of items in the correct answer
|
187
|
+
total_items = question[:correct_answer].size
|
188
|
+
|
182
189
|
player_answers.each do |player_name, answer_data|
|
190
|
+
# Skip nil entries
|
191
|
+
next unless player_name && answer_data
|
192
|
+
|
193
|
+
# Extract player's answer with defensive checks
|
183
194
|
player_answer = answer_data[:answer]
|
184
195
|
time_taken = answer_data[:time_taken] || 20
|
185
196
|
|
186
|
-
#
|
187
|
-
|
197
|
+
# Initialize points
|
198
|
+
points = 0
|
188
199
|
|
189
|
-
#
|
190
|
-
|
191
|
-
|
192
|
-
|
200
|
+
# New scoring system: checks positions relative to each other item
|
201
|
+
if player_answer && !player_answer.empty?
|
202
|
+
# Create a mapping from item to its position in player's answer
|
203
|
+
item_positions = {}
|
204
|
+
player_answer.each_with_index do |item, index|
|
205
|
+
item_positions[item] = index if item # Skip nil items
|
206
|
+
end
|
207
|
+
|
208
|
+
# Create mapping from item to correct position
|
209
|
+
correct_positions = {}
|
210
|
+
question[:correct_answer].each_with_index do |item, index|
|
211
|
+
correct_positions[item] = index if item # Skip nil items
|
212
|
+
end
|
213
|
+
|
214
|
+
# For each item, calculate points based on relative positions
|
215
|
+
question[:correct_answer].each_with_index do |item, correct_index|
|
216
|
+
# Skip if the item isn't in the player's answer
|
217
|
+
next unless item && item_positions.key?(item)
|
218
|
+
|
219
|
+
player_index = item_positions[item]
|
220
|
+
|
221
|
+
# Check position relative to other items
|
222
|
+
question[:correct_answer].each_with_index do |other_item, other_correct_index|
|
223
|
+
next if !other_item || item == other_item || !item_positions.key?(other_item)
|
224
|
+
|
225
|
+
other_player_index = item_positions[other_item]
|
226
|
+
|
227
|
+
# If this item should be before the other item
|
228
|
+
if correct_index < other_correct_index
|
229
|
+
points += 1 if player_index < other_player_index
|
230
|
+
# If this item should be after the other item
|
231
|
+
elsif correct_index > other_correct_index
|
232
|
+
points += 1 if player_index > other_player_index
|
233
|
+
end
|
234
|
+
end
|
193
235
|
end
|
194
236
|
end
|
195
237
|
|
196
|
-
#
|
197
|
-
|
198
|
-
|
238
|
+
# Bonus points for perfect answer
|
239
|
+
perfect_score = total_items * (total_items - 1)
|
240
|
+
perfect_score = 1 if perfect_score <= 0 # Prevent division by zero
|
241
|
+
fully_correct = points == perfect_score
|
199
242
|
|
200
|
-
|
201
|
-
if correct_positions == total_items
|
202
|
-
# Base bonus for fully correct answer
|
203
|
-
points += 3
|
204
|
-
|
243
|
+
if fully_correct
|
205
244
|
# Additional time-based bonus (faster answers get more points)
|
206
245
|
if time_taken < 8 # Really fast (under 8 seconds)
|
207
246
|
points += 4
|
@@ -210,17 +249,35 @@ module GitGameShow
|
|
210
249
|
end
|
211
250
|
end
|
212
251
|
|
213
|
-
# Create feedback
|
214
|
-
|
252
|
+
# Create detailed feedback
|
253
|
+
max_possible = total_items * (total_items - 1)
|
254
|
+
max_possible = 1 if max_possible <= 0 # Prevent division by zero
|
255
|
+
feedback = "#{points}/#{max_possible} points (based on relative ordering)"
|
215
256
|
if question[:commit_dates]
|
216
|
-
feedback += "\n\nActual dates
|
257
|
+
feedback += "\n\nActual dates:"
|
258
|
+
# Split by newlines and add them as separate lines for better readability
|
259
|
+
question[:commit_dates].to_s.split("\n").each do |date_line|
|
260
|
+
feedback += "\n • #{date_line}"
|
261
|
+
end
|
217
262
|
end
|
218
263
|
|
264
|
+
# Ensure we return all required fields
|
265
|
+
results[player_name] = {
|
266
|
+
answer: player_answer || [],
|
267
|
+
correct: fully_correct || false,
|
268
|
+
points: points || 0,
|
269
|
+
partial_score: feedback || ""
|
270
|
+
}
|
271
|
+
end
|
272
|
+
|
273
|
+
# Return a default result if somehow we ended up with empty results
|
274
|
+
if results.empty? && !player_answers.empty?
|
275
|
+
player_name = player_answers.keys.first
|
219
276
|
results[player_name] = {
|
220
|
-
answer:
|
221
|
-
correct:
|
222
|
-
points:
|
223
|
-
partial_score:
|
277
|
+
answer: [],
|
278
|
+
correct: false,
|
279
|
+
points: 0,
|
280
|
+
partial_score: "Error calculating score"
|
224
281
|
}
|
225
282
|
end
|
226
283
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_game_show
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Paulson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|