battlesnake 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -69,11 +69,13 @@
69
69
  <dl>
70
70
  <dt>Inherits:</dt>
71
71
  <dd>
72
- <span class="inheritName">Object</span>
72
+ <span class="inheritName"><span class='object_link'><a href="Base.html" title="Battlesnake::Base (class)">Base</a></span></span>
73
73
 
74
74
  <ul class="fullTree">
75
75
  <li>Object</li>
76
76
 
77
+ <li class="next"><span class='object_link'><a href="Base.html" title="Battlesnake::Base (class)">Base</a></span></li>
78
+
77
79
  <li class="next">Battlesnake::Location</li>
78
80
 
79
81
  </ul>
@@ -369,6 +371,17 @@
369
371
  </ul>
370
372
 
371
373
 
374
+
375
+
376
+
377
+
378
+
379
+
380
+
381
+
382
+
383
+ <h3 class="inherited">Methods inherited from <span class='object_link'><a href="Base.html" title="Battlesnake::Base (class)">Base</a></span></h3>
384
+ <p class="inherited"><span class='object_link'><a href="Base.html#==-instance_method" title="Battlesnake::Base#== (method)">#==</a></span></p>
372
385
  <div id="constructor_details" class="method_details_list">
373
386
  <h2>Constructor Details</h2>
374
387
 
@@ -995,7 +1008,7 @@
995
1008
  </div>
996
1009
 
997
1010
  <div id="footer">
998
- Generated on Fri Nov 4 19:07:50 2022 by
1011
+ Generated on Sat Nov 5 20:09:02 2022 by
999
1012
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1000
1013
  0.9.28 (ruby-2.7.2).
1001
1014
  </div>
@@ -69,11 +69,13 @@
69
69
  <dl>
70
70
  <dt>Inherits:</dt>
71
71
  <dd>
72
- <span class="inheritName">Object</span>
72
+ <span class="inheritName"><span class='object_link'><a href="Base.html" title="Battlesnake::Base (class)">Base</a></span></span>
73
73
 
74
74
  <ul class="fullTree">
75
75
  <li>Object</li>
76
76
 
77
+ <li class="next"><span class='object_link'><a href="Base.html" title="Battlesnake::Base (class)">Base</a></span></li>
78
+
77
79
  <li class="next">Battlesnake::Snake</li>
78
80
 
79
81
  </ul>
@@ -502,6 +504,17 @@
502
504
  </ul>
503
505
 
504
506
 
507
+
508
+
509
+
510
+
511
+
512
+
513
+
514
+
515
+
516
+ <h3 class="inherited">Methods inherited from <span class='object_link'><a href="Base.html" title="Battlesnake::Base (class)">Base</a></span></h3>
517
+ <p class="inherited"><span class='object_link'><a href="Base.html#==-instance_method" title="Battlesnake::Base#== (method)">#==</a></span></p>
505
518
  <div id="constructor_details" class="method_details_list">
506
519
  <h2>Constructor Details</h2>
507
520
 
@@ -1339,7 +1352,7 @@
1339
1352
  </div>
1340
1353
 
1341
1354
  <div id="footer">
1342
- Generated on Fri Nov 4 19:07:50 2022 by
1355
+ Generated on Sat Nov 5 20:09:02 2022 by
1343
1356
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1344
1357
  0.9.28 (ruby-2.7.2).
1345
1358
  </div>
@@ -79,7 +79,7 @@
79
79
  <dl>
80
80
  <dt>Defined in:</dt>
81
81
  <dd>lib/battlesnake.rb<span class="defines">,<br />
82
- lib/battlesnake/board.rb,<br /> lib/battlesnake/snake.rb,<br /> lib/battlesnake/version.rb,<br /> lib/battlesnake/location.rb</span>
82
+ lib/battlesnake/base.rb,<br /> lib/battlesnake/game.rb,<br /> lib/battlesnake/board.rb,<br /> lib/battlesnake/snake.rb,<br /> lib/battlesnake/version.rb,<br /> lib/battlesnake/location.rb</span>
83
83
  </dd>
84
84
  </dl>
85
85
 
@@ -102,7 +102,7 @@
102
102
 
103
103
 
104
104
 
105
- <strong class="classes">Classes:</strong> <span class='object_link'><a href="Battlesnake/Board.html" title="Battlesnake::Board (class)">Board</a></span>, <span class='object_link'><a href="Battlesnake/Error.html" title="Battlesnake::Error (class)">Error</a></span>, <span class='object_link'><a href="Battlesnake/Location.html" title="Battlesnake::Location (class)">Location</a></span>, <span class='object_link'><a href="Battlesnake/Snake.html" title="Battlesnake::Snake (class)">Snake</a></span>
105
+ <strong class="classes">Classes:</strong> <span class='object_link'><a href="Battlesnake/Base.html" title="Battlesnake::Base (class)">Base</a></span>, <span class='object_link'><a href="Battlesnake/Board.html" title="Battlesnake::Board (class)">Board</a></span>, <span class='object_link'><a href="Battlesnake/Error.html" title="Battlesnake::Error (class)">Error</a></span>, <span class='object_link'><a href="Battlesnake/Game.html" title="Battlesnake::Game (class)">Game</a></span>, <span class='object_link'><a href="Battlesnake/Location.html" title="Battlesnake::Location (class)">Location</a></span>, <span class='object_link'><a href="Battlesnake/Snake.html" title="Battlesnake::Snake (class)">Snake</a></span>
106
106
 
107
107
 
108
108
  </p>
@@ -129,7 +129,7 @@
129
129
 
130
130
  </div>
131
131
  </dt>
132
- <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>0.1.0</span><span class='tstring_end'>&quot;</span></span></pre></dd>
132
+ <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>0.1.2</span><span class='tstring_end'>&quot;</span></span></pre></dd>
133
133
 
134
134
  </dl>
135
135
 
@@ -145,7 +145,7 @@
145
145
  </div>
146
146
 
147
147
  <div id="footer">
148
- Generated on Fri Nov 4 19:07:49 2022 by
148
+ Generated on Sat Nov 5 20:09:02 2022 by
149
149
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
150
150
  0.9.28 (ruby-2.7.2).
151
151
  </div>
data/docs/_index.html CHANGED
@@ -80,6 +80,13 @@
80
80
  <li class="letter">B</li>
81
81
  <ul>
82
82
 
83
+ <li>
84
+ <span class='object_link'><a href="Battlesnake/Base.html" title="Battlesnake::Base (class)">Base</a></span>
85
+
86
+ <small>(Battlesnake)</small>
87
+
88
+ </li>
89
+
83
90
  <li>
84
91
  <span class='object_link'><a href="Battlesnake.html" title="Battlesnake (module)">Battlesnake</a></span>
85
92
 
@@ -111,6 +118,21 @@
111
118
  </ul>
112
119
 
113
120
 
121
+ <ul id="alpha_G" class="alpha">
122
+ <li class="letter">G</li>
123
+ <ul>
124
+
125
+ <li>
126
+ <span class='object_link'><a href="Battlesnake/Game.html" title="Battlesnake::Game (class)">Game</a></span>
127
+
128
+ <small>(Battlesnake)</small>
129
+
130
+ </li>
131
+
132
+ </ul>
133
+ </ul>
134
+
135
+
114
136
  <ul id="alpha_L" class="alpha">
115
137
  <li class="letter">L</li>
116
138
  <ul>
@@ -149,7 +171,7 @@
149
171
  </div>
150
172
 
151
173
  <div id="footer">
152
- Generated on Fri Nov 4 19:07:49 2022 by
174
+ Generated on Sat Nov 5 20:09:02 2022 by
153
175
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
154
176
  0.9.28 (ruby-2.7.2).
155
177
  </div>
data/docs/class_list.html CHANGED
@@ -43,7 +43,7 @@
43
43
 
44
44
  <ul id="full_list" class="class">
45
45
  <li id="object_" class="odd"><div class="item" style="padding-left:30px"><span class='object_link'><a href="top-level-namespace.html" title="Top Level Namespace (root)">Top Level Namespace</a></span></div></li>
46
- <li id='object_Battlesnake' class='even'><div class='item' style='padding-left:30px'><a class='toggle'></a> <span class='object_link'><a href="Battlesnake.html" title="Battlesnake (module)">Battlesnake</a></span><small class='search_info'>Top Level Namespace</small></div><ul><li id='object_Battlesnake::Board' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Battlesnake/Board.html" title="Battlesnake::Board (class)">Board</a></span> &lt; Object<small class='search_info'>Battlesnake</small></div></li><li id='object_Battlesnake::Error' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Battlesnake/Error.html" title="Battlesnake::Error (class)">Error</a></span> &lt; StandardError<small class='search_info'>Battlesnake</small></div></li><li id='object_Battlesnake::Location' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Battlesnake/Location.html" title="Battlesnake::Location (class)">Location</a></span> &lt; Object<small class='search_info'>Battlesnake</small></div></li><li id='object_Battlesnake::Snake' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Battlesnake/Snake.html" title="Battlesnake::Snake (class)">Snake</a></span> &lt; Object<small class='search_info'>Battlesnake</small></div></li></ul></li>
46
+ <li id='object_Battlesnake' class='even'><div class='item' style='padding-left:30px'><a class='toggle'></a> <span class='object_link'><a href="Battlesnake.html" title="Battlesnake (module)">Battlesnake</a></span><small class='search_info'>Top Level Namespace</small></div><ul><li id='object_Battlesnake::Base' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Battlesnake/Base.html" title="Battlesnake::Base (class)">Base</a></span> &lt; Object<small class='search_info'>Battlesnake</small></div></li><li id='object_Battlesnake::Board' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Battlesnake/Board.html" title="Battlesnake::Board (class)">Board</a></span> &lt; Base<small class='search_info'>Battlesnake</small></div></li><li id='object_Battlesnake::Error' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Battlesnake/Error.html" title="Battlesnake::Error (class)">Error</a></span> &lt; StandardError<small class='search_info'>Battlesnake</small></div></li><li id='object_Battlesnake::Game' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Battlesnake/Game.html" title="Battlesnake::Game (class)">Game</a></span> &lt; Base<small class='search_info'>Battlesnake</small></div></li><li id='object_Battlesnake::Location' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Battlesnake/Location.html" title="Battlesnake::Location (class)">Location</a></span> &lt; Base<small class='search_info'>Battlesnake</small></div></li><li id='object_Battlesnake::Snake' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Battlesnake/Snake.html" title="Battlesnake::Snake (class)">Snake</a></span> &lt; Base<small class='search_info'>Battlesnake</small></div></li></ul></li>
47
47
 
48
48
  </ul>
49
49
  </div>
@@ -97,7 +97,7 @@
97
97
  </div></div>
98
98
 
99
99
  <div id="footer">
100
- Generated on Fri Nov 4 19:07:49 2022 by
100
+ Generated on Sat Nov 5 20:09:02 2022 by
101
101
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
102
102
  0.9.28 (ruby-2.7.2).
103
103
  </div>
data/docs/index.html CHANGED
@@ -97,7 +97,7 @@
97
97
  </div></div>
98
98
 
99
99
  <div id="footer">
100
- Generated on Fri Nov 4 19:07:49 2022 by
100
+ Generated on Sat Nov 5 20:09:02 2022 by
101
101
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
102
102
  0.9.28 (ruby-2.7.2).
103
103
  </div>
@@ -46,8 +46,8 @@
46
46
 
47
47
  <li class="odd ">
48
48
  <div class="item">
49
- <span class='object_link'><a href="Battlesnake/Snake.html#as_json-instance_method" title="Battlesnake::Snake#as_json (method)">#as_json</a></span>
50
- <small>Battlesnake::Snake</small>
49
+ <span class='object_link'><a href="Battlesnake/Base.html#==-instance_method" title="Battlesnake::Base#== (method)">#==</a></span>
50
+ <small>Battlesnake::Base</small>
51
51
  </div>
52
52
  </li>
53
53
 
@@ -60,6 +60,22 @@
60
60
  </li>
61
61
 
62
62
 
63
+ <li class="odd ">
64
+ <div class="item">
65
+ <span class='object_link'><a href="Battlesnake/Snake.html#as_json-instance_method" title="Battlesnake::Snake#as_json (method)">#as_json</a></span>
66
+ <small>Battlesnake::Snake</small>
67
+ </div>
68
+ </li>
69
+
70
+
71
+ <li class="even ">
72
+ <div class="item">
73
+ <span class='object_link'><a href="Battlesnake/Game.html#as_json-instance_method" title="Battlesnake::Game#as_json (method)">#as_json</a></span>
74
+ <small>Battlesnake::Game</small>
75
+ </div>
76
+ </li>
77
+
78
+
63
79
  <li class="odd ">
64
80
  <div class="item">
65
81
  <span class='object_link'><a href="Battlesnake/Board.html#as_json-instance_method" title="Battlesnake::Board#as_json (method)">#as_json</a></span>
@@ -68,6 +84,22 @@
68
84
  </li>
69
85
 
70
86
 
87
+ <li class="even ">
88
+ <div class="item">
89
+ <span class='object_link'><a href="Battlesnake/Board.html#available%3F-instance_method" title="Battlesnake::Board#available? (method)">#available?</a></span>
90
+ <small>Battlesnake::Board</small>
91
+ </div>
92
+ </li>
93
+
94
+
95
+ <li class="odd ">
96
+ <div class="item">
97
+ <span class='object_link'><a href="Battlesnake/Board.html#available_directions-instance_method" title="Battlesnake::Board#available_directions (method)">#available_directions</a></span>
98
+ <small>Battlesnake::Board</small>
99
+ </div>
100
+ </li>
101
+
102
+
71
103
  <li class="even ">
72
104
  <div class="item">
73
105
  <span class='object_link'><a href="Battlesnake/Snake.html#body-instance_method" title="Battlesnake::Snake#body (method)">#body</a></span>
@@ -164,6 +196,22 @@
164
196
  </li>
165
197
 
166
198
 
199
+ <li class="even ">
200
+ <div class="item">
201
+ <span class='object_link'><a href="Battlesnake/Game.html#id-instance_method" title="Battlesnake::Game#id (method)">#id</a></span>
202
+ <small>Battlesnake::Game</small>
203
+ </div>
204
+ </li>
205
+
206
+
207
+ <li class="odd ">
208
+ <div class="item">
209
+ <span class='object_link'><a href="Battlesnake/Snake.html#initialize-instance_method" title="Battlesnake::Snake#initialize (method)">#initialize</a></span>
210
+ <small>Battlesnake::Snake</small>
211
+ </div>
212
+ </li>
213
+
214
+
167
215
  <li class="even ">
168
216
  <div class="item">
169
217
  <span class='object_link'><a href="Battlesnake/Location.html#initialize-instance_method" title="Battlesnake::Location#initialize (method)">#initialize</a></span>
@@ -182,8 +230,8 @@
182
230
 
183
231
  <li class="even ">
184
232
  <div class="item">
185
- <span class='object_link'><a href="Battlesnake/Snake.html#initialize-instance_method" title="Battlesnake::Snake#initialize (method)">#initialize</a></span>
186
- <small>Battlesnake::Snake</small>
233
+ <span class='object_link'><a href="Battlesnake/Game.html#initialize-instance_method" title="Battlesnake::Game#initialize (method)">#initialize</a></span>
234
+ <small>Battlesnake::Game</small>
187
235
  </div>
188
236
  </li>
189
237
 
@@ -205,6 +253,14 @@
205
253
 
206
254
 
207
255
  <li class="odd ">
256
+ <div class="item">
257
+ <span class='object_link'><a href="Battlesnake/Game.html#map-instance_method" title="Battlesnake::Game#map (method)">#map</a></span>
258
+ <small>Battlesnake::Game</small>
259
+ </div>
260
+ </li>
261
+
262
+
263
+ <li class="even ">
208
264
  <div class="item">
209
265
  <span class='object_link'><a href="Battlesnake/Location.html#move-instance_method" title="Battlesnake::Location#move (method)">#move</a></span>
210
266
  <small>Battlesnake::Location</small>
@@ -212,7 +268,7 @@
212
268
  </li>
213
269
 
214
270
 
215
- <li class="even ">
271
+ <li class="odd ">
216
272
  <div class="item">
217
273
  <span class='object_link'><a href="Battlesnake/Snake.html#name-instance_method" title="Battlesnake::Snake#name (method)">#name</a></span>
218
274
  <small>Battlesnake::Snake</small>
@@ -220,6 +276,30 @@
220
276
  </li>
221
277
 
222
278
 
279
+ <li class="even ">
280
+ <div class="item">
281
+ <span class='object_link'><a href="Battlesnake/Board.html#occupied%3F-instance_method" title="Battlesnake::Board#occupied? (method)">#occupied?</a></span>
282
+ <small>Battlesnake::Board</small>
283
+ </div>
284
+ </li>
285
+
286
+
287
+ <li class="odd ">
288
+ <div class="item">
289
+ <span class='object_link'><a href="Battlesnake/Board.html#occupied_locations-instance_method" title="Battlesnake::Board#occupied_locations (method)">#occupied_locations</a></span>
290
+ <small>Battlesnake::Board</small>
291
+ </div>
292
+ </li>
293
+
294
+
295
+ <li class="even ">
296
+ <div class="item">
297
+ <span class='object_link'><a href="Battlesnake/Game.html#ruleset-instance_method" title="Battlesnake::Game#ruleset (method)">#ruleset</a></span>
298
+ <small>Battlesnake::Game</small>
299
+ </div>
300
+ </li>
301
+
302
+
223
303
  <li class="odd ">
224
304
  <div class="item">
225
305
  <span class='object_link'><a href="Battlesnake/Snake.html#shout-instance_method" title="Battlesnake::Snake#shout (method)">#shout</a></span>
@@ -237,6 +317,14 @@
237
317
 
238
318
 
239
319
  <li class="odd ">
320
+ <div class="item">
321
+ <span class='object_link'><a href="Battlesnake/Game.html#source-instance_method" title="Battlesnake::Game#source (method)">#source</a></span>
322
+ <small>Battlesnake::Game</small>
323
+ </div>
324
+ </li>
325
+
326
+
327
+ <li class="even ">
240
328
  <div class="item">
241
329
  <span class='object_link'><a href="Battlesnake/Snake.html#squad-instance_method" title="Battlesnake::Snake#squad (method)">#squad</a></span>
242
330
  <small>Battlesnake::Snake</small>
@@ -244,6 +332,14 @@
244
332
  </li>
245
333
 
246
334
 
335
+ <li class="odd ">
336
+ <div class="item">
337
+ <span class='object_link'><a href="Battlesnake/Game.html#timeout-instance_method" title="Battlesnake::Game#timeout (method)">#timeout</a></span>
338
+ <small>Battlesnake::Game</small>
339
+ </div>
340
+ </li>
341
+
342
+
247
343
  <li class="even ">
248
344
  <div class="item">
249
345
  <span class='object_link'><a href="Battlesnake/Board.html#width-instance_method" title="Battlesnake::Board#width (method)">#width</a></span>
@@ -100,7 +100,7 @@
100
100
  </div>
101
101
 
102
102
  <div id="footer">
103
- Generated on Fri Nov 4 19:07:49 2022 by
103
+ Generated on Sat Nov 5 20:09:02 2022 by
104
104
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
105
105
  0.9.28 (ruby-2.7.2).
106
106
  </div>
@@ -0,0 +1,15 @@
1
+ module Battlesnake
2
+ ##
3
+ # Base class for "model" classes - _Game, Board, Snake, Location,_ etc.
4
+ class Base
5
+ ##
6
+ # Whether both locations have the same coordinates.
7
+ #
8
+ # @param other [Location]
9
+ #
10
+ # @return [Boolean] true if location objects have the same coordinates.
11
+ def ==(other)
12
+ other.is_a?(self.class) && self.as_json == other.as_json
13
+ end
14
+ end
15
+ end
@@ -3,7 +3,7 @@ require 'json'
3
3
  module Battlesnake
4
4
  ##
5
5
  # Represents a single iteration (turn) of a Battlesnake board during gameplay.
6
- class Board
6
+ class Board < Base
7
7
  # @return [Hash] board as a data structure usable by other objects.
8
8
  attr_reader :as_json
9
9
 
@@ -39,5 +39,51 @@ module Battlesnake
39
39
  @food = data['food'].map{ |attrs| Location.new(attrs) }
40
40
  @hazards = data['hazards'].map{ |attrs| Location.new(attrs) }
41
41
  end
42
+
43
+ ##
44
+ # List of all occupied locations on the board; snakes, food, hazards, etc
45
+ #
46
+ # @return [Array<Location>] list of occupied locations
47
+ def occupied_locations
48
+ return @occupied_locations if defined?(@occupied_locations)
49
+ @occupied_locations = snakes.map(&:body).flatten + food + hazards
50
+ end
51
+
52
+ ##
53
+ # Whether the supplied location is occupied.
54
+ #
55
+ # @param *coordinates [Location,Hash,String,Array] can be specified as a _Location_ object,
56
+ # hash containing x/y keys, JSON string of such a hash, or a pair of x,y coordinates expressed
57
+ # as a 2-element array or two separate parameters.
58
+ #
59
+ # @return [Boolean] true if location is occupied by snakes, food, hazards, etc.
60
+ def occupied?(*coordinates)
61
+ location = coordinates.first.is_a?(Location) ? coordinates.first : Location.new(*coordinates)
62
+ occupied_locations.include?(location)
63
+ end
64
+
65
+ ##
66
+ # Whether the supplied location is available (unoccupied).
67
+ #
68
+ # @param *coordinates [Location,Hash,String,Array] can be specified as a _Location_ object,
69
+ # hash containing x/y keys, JSON string of such a hash, or a pair of x,y coordinates expressed
70
+ # as a 2-element array or two separate parameters.
71
+ #
72
+ # @return [Boolean] true if location is available (unoccupied by snakes, food, hazards, etc).
73
+ def available?(*coordinates)
74
+ !occupied?(*coordinates)
75
+ end
76
+
77
+ ##
78
+ # List of directions (up, down, left, right) available for moving from given _Location_.
79
+ #
80
+ # @param [Location] location from which moving is desired.
81
+ #
82
+ # @return [Array<String>] list of direction strings ("up", "down", "left", "right")
83
+ def available_directions(location)
84
+ Location::DIRECTIONS.select do |direction|
85
+ available?(location.move(direction))
86
+ end
87
+ end
42
88
  end
43
89
  end
@@ -0,0 +1,44 @@
1
+ require 'json'
2
+
3
+ module Battlesnake
4
+ ##
5
+ # Represents a Battlesnake game.
6
+ class Game < Base
7
+ # @return [Hash] snake as a data structure usable by other objects.
8
+ attr_reader :as_json
9
+
10
+ # @return [String] unique identifier for this game.
11
+ attr_reader :id
12
+
13
+ # @return [Hash] information about the ruleset being used to run this game.
14
+ attr_reader :ruleset
15
+
16
+ # @return [String] name of the map used to populate the game board with snakes, food, and hazards.
17
+ attr_reader :map
18
+
19
+ # @return [Integer] how much time player APIs have to respond to requests for this game.
20
+ attr_reader :timeout
21
+
22
+ # @return [String] source of this game.
23
+ attr_reader :source
24
+
25
+ ##
26
+ # Returns a new instance of Game.
27
+ #
28
+ # @param json_or_hash [String,Hash] can be a hash of attributes, or a JSON string which
29
+ # represents such a structure.
30
+ #
31
+ # @return [Game]
32
+ def initialize(json_or_hash)
33
+ data = json_or_hash.is_a?(String) ? JSON.parse(json_or_hash) : json_or_hash
34
+
35
+ @as_json = data
36
+
37
+ @id = data['id']
38
+ @ruleset = data['ruleset']
39
+ @map = data['map']
40
+ @timeout = data['timeout']
41
+ @source = data['source']
42
+ end
43
+ end
44
+ end
@@ -4,7 +4,7 @@ module Battlesnake
4
4
  ##
5
5
  # Represents a pair of (x,y) coordinates, and provides helper methods
6
6
  # for managing distance and direction.
7
- class Location
7
+ class Location < Base
8
8
  # @return [Integer] a positive integer representing the distance from the
9
9
  # left side of the board.
10
10
  attr_reader :x
@@ -3,7 +3,7 @@ require 'json'
3
3
  module Battlesnake
4
4
  ##
5
5
  # Represents a single Battlesnake player.
6
- class Snake
6
+ class Snake < Base
7
7
  # @return [Hash] snake as a data structure usable by other objects.
8
8
  attr_reader :as_json
9
9
 
@@ -1,4 +1,4 @@
1
1
  module Battlesnake
2
2
  # The current version of the driver.
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
data/lib/battlesnake.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require "battlesnake/version"
2
+ require 'battlesnake/base'
2
3
  require 'battlesnake/board'
4
+ require 'battlesnake/game'
3
5
  require 'battlesnake/location'
4
6
  require 'battlesnake/snake'
5
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: battlesnake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaime Bellmyer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-05 00:00:00.000000000 Z
11
+ date: 2022-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -100,8 +100,10 @@ files:
100
100
  - bin/console
101
101
  - bin/setup
102
102
  - docs/Battlesnake.html
103
+ - docs/Battlesnake/Base.html
103
104
  - docs/Battlesnake/Board.html
104
105
  - docs/Battlesnake/Error.html
106
+ - docs/Battlesnake/Game.html
105
107
  - docs/Battlesnake/Location.html
106
108
  - docs/Battlesnake/Snake.html
107
109
  - docs/_index.html
@@ -119,7 +121,9 @@ files:
119
121
  - docs/method_list.html
120
122
  - docs/top-level-namespace.html
121
123
  - lib/battlesnake.rb
124
+ - lib/battlesnake/base.rb
122
125
  - lib/battlesnake/board.rb
126
+ - lib/battlesnake/game.rb
123
127
  - lib/battlesnake/location.rb
124
128
  - lib/battlesnake/snake.rb
125
129
  - lib/battlesnake/version.rb