monkeymusic 0.0.12 → 0.0.13
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 +8 -8
- data/demo_player +130 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
M2NmMDBlZGU0ZjRlNzdlY2EwZDY0NGVjNzQ0NWRlMzQwY2FmMjUwOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MTQzMTY4YjdlZDc3ZGYyYWI4ZDFmMWVhNTQxN2VhNGRkM2ZmNzQwMQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODRlNjZlMGNiN2FlODU4ZWNmZjcwODA5NDM4OTEyMTVhZmM2N2IzNDM5Yjkx
|
10
|
+
MmI3NDQ4Njg5ZjIxMmE0MzdmZjg4MjFjZmQ5OTM3ODdmNzZjMWQxZDhkYmRl
|
11
|
+
NmVkNmE3MWU3NzA5NTAyMzQ3YTFlYTdkMzYwMDI5NmZkZGU3N2I=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MWZlMjY5MjdiNjgxMjIwOGEwMzgxNTBjNjQzZmEzNTIwY2E1MzNjYzg2ZjI1
|
14
|
+
YmY5NTNkNTAyMDE2YTAzZjJiYWEzOTYxOTA0Yzg3MTg4MzU0MTM2YzU4NWFh
|
15
|
+
MDQxN2Q5ZTgyOTFmZmFlNjhlOTViNDkzZTcwMTQ5M2M1YjZjYzE=
|
data/demo_player
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
if RUBY_VERSION =~ /1.9/
|
5
|
+
Encoding.default_external = Encoding::UTF_8
|
6
|
+
Encoding.default_internal = Encoding::UTF_8
|
7
|
+
end
|
8
|
+
|
9
|
+
class DemoPlayer
|
10
|
+
|
11
|
+
@@cache_prefix = "cache"
|
12
|
+
|
13
|
+
def initialize(id)
|
14
|
+
@id = id
|
15
|
+
@known_tracks = {}
|
16
|
+
@unknown_tracks = {}
|
17
|
+
@track_positions = []
|
18
|
+
@cache_file = DemoPlayer.cache_file(id)
|
19
|
+
end
|
20
|
+
|
21
|
+
def do_init_phase!
|
22
|
+
@width = Integer($stdin.gets.chomp)
|
23
|
+
@height = Integer($stdin.gets.chomp)
|
24
|
+
@turn_limit = Integer($stdin.gets.chomp)
|
25
|
+
# Read toplists
|
26
|
+
@toplists = {}
|
27
|
+
[:top_tracks, :top_albums, :top_artists, :disliked_artists].each do |toplist|
|
28
|
+
@toplists[toplist] = []
|
29
|
+
n = Integer($stdin.gets.chomp)
|
30
|
+
n.times { @toplists[toplist] << $stdin.gets.chomp }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def do_turn_phase!
|
35
|
+
read_turn!
|
36
|
+
read_level!
|
37
|
+
if (@remaining_capacity > 0) && (not @track_positions.empty?)
|
38
|
+
puts move_toward(*closest_track)
|
39
|
+
else
|
40
|
+
puts move_toward(*@user_position)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def write_to_file!
|
45
|
+
File.open(@cache_file, "w+") do |f|
|
46
|
+
f.write YAML::dump(self)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.read_from_file(id)
|
51
|
+
YAML::load IO.read(DemoPlayer.cache_file(id))
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def self.cache_file(id)
|
57
|
+
File.join(Dir.getwd, "#{@@cache_prefix}_#{id}")
|
58
|
+
end
|
59
|
+
|
60
|
+
def read_turn!
|
61
|
+
@turn = Integer($stdin.gets.chomp)
|
62
|
+
@remaining_capacity = Integer($stdin.gets.chomp)
|
63
|
+
@remaining_time = Integer($stdin.gets.chomp)
|
64
|
+
# Read metadata query responses
|
65
|
+
num_responses = Integer($stdin.gets.chomp)
|
66
|
+
num_responses.times do
|
67
|
+
response = $stdin.gets.chomp.split(",")
|
68
|
+
uri = response.unshift
|
69
|
+
@known_tracks[uri][response]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def read_level!
|
74
|
+
@track_positions = []
|
75
|
+
@height.times do |y|
|
76
|
+
row = $stdin.gets.chomp.split(',')
|
77
|
+
@width.times do |x|
|
78
|
+
case row[x]
|
79
|
+
when "M#{@id}" then @x, @y = x, y
|
80
|
+
when /spotify:track/ then @track_positions << [x, y]
|
81
|
+
when "U" then @user_position = [x, y]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def move_toward(x, y)
|
88
|
+
if @x < x
|
89
|
+
"E"
|
90
|
+
elsif @x > x
|
91
|
+
"W"
|
92
|
+
elsif @y < y
|
93
|
+
"S"
|
94
|
+
elsif @y > y
|
95
|
+
"N"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def distance_to(x, y)
|
100
|
+
(@x - x).abs + (@y - y).abs
|
101
|
+
end
|
102
|
+
|
103
|
+
def closest_track
|
104
|
+
return if @track_positions.empty?
|
105
|
+
curr_closest = @track_positions[0]
|
106
|
+
curr_smallest_distance = distance_to(*curr_closest)
|
107
|
+
@track_positions.each do |track|
|
108
|
+
curr_distance = distance_to(*track)
|
109
|
+
if curr_distance < curr_smallest_distance
|
110
|
+
curr_closest = track
|
111
|
+
curr_smallest_distance = curr_distance
|
112
|
+
end
|
113
|
+
end
|
114
|
+
curr_closest
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
type = $stdin.gets.chomp
|
120
|
+
id = $stdin.gets.chomp
|
121
|
+
|
122
|
+
if type == "INIT"
|
123
|
+
player = DemoPlayer.new(id)
|
124
|
+
player.do_init_phase!
|
125
|
+
elsif type == "TURN"
|
126
|
+
player = DemoPlayer.read_from_file(id)
|
127
|
+
player.do_turn_phase!
|
128
|
+
end
|
129
|
+
|
130
|
+
player.write_to_file!
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monkeymusic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Soderlund
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- Gemfile
|
70
70
|
- README.md
|
71
71
|
- LICENSE
|
72
|
+
- demo_player
|
72
73
|
homepage: https://github.com/odsod/monkey-music
|
73
74
|
licenses:
|
74
75
|
- MIT
|