battlesnake 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,1005 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ Class: Battlesnake::Location
8
+
9
+ &mdash; Documentation by YARD 0.9.28
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="../css/style.css" type="text/css" />
14
+
15
+ <link rel="stylesheet" href="../css/common.css" type="text/css" />
16
+
17
+ <script type="text/javascript">
18
+ pathId = "Battlesnake::Location";
19
+ relpath = '../';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="../class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="../_index.html">Index (L)</a> &raquo;
40
+ <span class='title'><span class='object_link'><a href="../Battlesnake.html" title="Battlesnake (module)">Battlesnake</a></span></span>
41
+ &raquo;
42
+ <span class="title">Location</span>
43
+
44
+ </div>
45
+
46
+ <div id="search">
47
+
48
+ <a class="full_list_link" id="class_list_link"
49
+ href="../class_list.html">
50
+
51
+ <svg width="24" height="24">
52
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
+ </svg>
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <div id="content"><h1>Class: Battlesnake::Location
63
+
64
+
65
+
66
+ </h1>
67
+ <div class="box_info">
68
+
69
+ <dl>
70
+ <dt>Inherits:</dt>
71
+ <dd>
72
+ <span class="inheritName">Object</span>
73
+
74
+ <ul class="fullTree">
75
+ <li>Object</li>
76
+
77
+ <li class="next">Battlesnake::Location</li>
78
+
79
+ </ul>
80
+ <a href="#" class="inheritanceTree">show all</a>
81
+
82
+ </dd>
83
+ </dl>
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+ <dl>
96
+ <dt>Defined in:</dt>
97
+ <dd>lib/battlesnake/location.rb</dd>
98
+ </dl>
99
+
100
+ </div>
101
+
102
+ <h2>Overview</h2><div class="docstring">
103
+ <div class="discussion">
104
+
105
+ <p>Represents a pair of (x,y) coordinates, and provides helper methods for managing distance and direction.</p>
106
+
107
+
108
+ </div>
109
+ </div>
110
+ <div class="tags">
111
+
112
+
113
+ </div>
114
+
115
+ <h2>
116
+ Constant Summary
117
+ <small><a href="#" class="constants_summary_toggle">collapse</a></small>
118
+ </h2>
119
+
120
+ <dl class="constants">
121
+
122
+ <dt id="DIRECTIONS-constant" class="">DIRECTIONS =
123
+ <div class="docstring">
124
+ <div class="discussion">
125
+
126
+ <p>Valid directions.</p>
127
+
128
+
129
+ </div>
130
+ </div>
131
+ <div class="tags">
132
+
133
+
134
+ </div>
135
+ </dt>
136
+ <dd><pre class="code"><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>up</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>down</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>right</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>left</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span></pre></dd>
137
+
138
+ </dl>
139
+
140
+
141
+
142
+
143
+
144
+ <h2>Instance Attribute Summary <small><a href="#" class="summary_toggle">collapse</a></small></h2>
145
+ <ul class="summary">
146
+
147
+ <li class="public ">
148
+ <span class="summary_signature">
149
+
150
+ <a href="#as_json-instance_method" title="#as_json (instance method)">#<strong>as_json</strong> &#x21d2; Hash </a>
151
+
152
+
153
+
154
+ </span>
155
+
156
+
157
+
158
+
159
+ <span class="note title readonly">readonly</span>
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+ <span class="summary_desc"><div class='inline'>
170
+ <p>Coordinates as a hash, for integration with other objects.</p>
171
+ </div></span>
172
+
173
+ </li>
174
+
175
+
176
+ <li class="public ">
177
+ <span class="summary_signature">
178
+
179
+ <a href="#x-instance_method" title="#x (instance method)">#<strong>x</strong> &#x21d2; Integer </a>
180
+
181
+
182
+
183
+ </span>
184
+
185
+
186
+
187
+
188
+ <span class="note title readonly">readonly</span>
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+ <span class="summary_desc"><div class='inline'>
199
+ <p>A positive integer representing the distance from the left side of the board.</p>
200
+ </div></span>
201
+
202
+ </li>
203
+
204
+
205
+ <li class="public ">
206
+ <span class="summary_signature">
207
+
208
+ <a href="#y-instance_method" title="#y (instance method)">#<strong>y</strong> &#x21d2; Integer </a>
209
+
210
+
211
+
212
+ </span>
213
+
214
+
215
+
216
+
217
+ <span class="note title readonly">readonly</span>
218
+
219
+
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+ <span class="summary_desc"><div class='inline'>
228
+ <p>A positive integer representing the distance from the bottom of the board.</p>
229
+ </div></span>
230
+
231
+ </li>
232
+
233
+
234
+ </ul>
235
+
236
+
237
+
238
+
239
+
240
+ <h2>
241
+ Instance Method Summary
242
+ <small><a href="#" class="summary_toggle">collapse</a></small>
243
+ </h2>
244
+
245
+ <ul class="summary">
246
+
247
+ <li class="public ">
248
+ <span class="summary_signature">
249
+
250
+ <a href="#coords-instance_method" title="#coords (instance method)">#<strong>coords</strong> &#x21d2; Array </a>
251
+
252
+
253
+
254
+ </span>
255
+
256
+
257
+
258
+
259
+
260
+
261
+
262
+
263
+
264
+ <span class="summary_desc"><div class='inline'>
265
+ <p>Convenience method to return (x,y) coordinates as an array.</p>
266
+ </div></span>
267
+
268
+ </li>
269
+
270
+
271
+ <li class="public ">
272
+ <span class="summary_signature">
273
+
274
+ <a href="#direction-instance_method" title="#direction (instance method)">#<strong>direction</strong>(location) &#x21d2; one of DIRECTIONS </a>
275
+
276
+
277
+
278
+ </span>
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+
288
+ <span class="summary_desc"><div class='inline'>
289
+ <p>Determine the most prominent orthoganal direction [see DIRECTIONS] toward another location.</p>
290
+ </div></span>
291
+
292
+ </li>
293
+
294
+
295
+ <li class="public ">
296
+ <span class="summary_signature">
297
+
298
+ <a href="#distance-instance_method" title="#distance (instance method)">#<strong>distance</strong>(location) &#x21d2; Integer </a>
299
+
300
+
301
+
302
+ </span>
303
+
304
+
305
+
306
+
307
+
308
+
309
+
310
+
311
+
312
+ <span class="summary_desc"><div class='inline'>
313
+ <p>Calculate the distance from this instance to another.</p>
314
+ </div></span>
315
+
316
+ </li>
317
+
318
+
319
+ <li class="public ">
320
+ <span class="summary_signature">
321
+
322
+ <a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(*coordinates) &#x21d2; Location </a>
323
+
324
+
325
+
326
+ </span>
327
+
328
+
329
+ <span class="note title constructor">constructor</span>
330
+
331
+
332
+
333
+
334
+
335
+
336
+
337
+
338
+ <span class="summary_desc"><div class='inline'>
339
+ <p>Instantiates with the given (x,y) coordinates.</p>
340
+ </div></span>
341
+
342
+ </li>
343
+
344
+
345
+ <li class="public ">
346
+ <span class="summary_signature">
347
+
348
+ <a href="#move-instance_method" title="#move (instance method)">#<strong>move</strong>(requested_direction) &#x21d2; Location </a>
349
+
350
+
351
+
352
+ </span>
353
+
354
+
355
+
356
+
357
+
358
+
359
+
360
+
361
+
362
+ <span class="summary_desc"><div class='inline'>
363
+ <p>Return a new location instance with coordinates moved one step in the requested direction.</p>
364
+ </div></span>
365
+
366
+ </li>
367
+
368
+
369
+ </ul>
370
+
371
+
372
+ <div id="constructor_details" class="method_details_list">
373
+ <h2>Constructor Details</h2>
374
+
375
+ <div class="method_details first">
376
+ <h3 class="signature first" id="initialize-instance_method">
377
+
378
+ #<strong>initialize</strong>(*coordinates) &#x21d2; <tt><span class='object_link'><a href="" title="Battlesnake::Location (class)">Location</a></span></tt>
379
+
380
+
381
+
382
+
383
+
384
+ </h3><div class="docstring">
385
+ <div class="discussion">
386
+
387
+ <p>Instantiates with the given (x,y) coordinates. Coordinates can be:</p>
388
+ <ul><li>
389
+ <p>a hash containing “x” and “y” keys</p>
390
+ </li><li>
391
+ <p>a JSON string that parses to such a hash</p>
392
+ </li><li>
393
+ <p>an array containing (x,y) coordinates</p>
394
+ </li><li>
395
+ <p>two separate (x,y) parameters</p>
396
+ </li></ul>
397
+
398
+
399
+ </div>
400
+ </div>
401
+ <div class="tags">
402
+ <p class="tag_title">Parameters:</p>
403
+ <ul class="param">
404
+
405
+ <li>
406
+
407
+ <span class='name'>coordinates</span>
408
+
409
+
410
+ <span class='type'>(<tt>Hash</tt>, <tt>Array</tt>, <tt>String</tt>)</span>
411
+
412
+
413
+
414
+ &mdash;
415
+ <div class='inline'>
416
+ <p>the coordinates</p>
417
+ </div>
418
+
419
+ </li>
420
+
421
+ </ul>
422
+
423
+
424
+ </div><table class="source_code">
425
+ <tr>
426
+ <td>
427
+ <pre class="lines">
428
+
429
+
430
+ 32
431
+ 33
432
+ 34
433
+ 35
434
+ 36</pre>
435
+ </td>
436
+ <td>
437
+ <pre class="code"><span class="info file"># File 'lib/battlesnake/location.rb', line 32</span>
438
+
439
+ <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_coordinates'>coordinates</span><span class='rparen'>)</span>
440
+ <span class='id identifier rubyid_set_xy'>set_xy</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_coordinates'>coordinates</span><span class='rparen'>)</span>
441
+
442
+ <span class='ivar'>@as_json</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>x</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_x'>x</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>y</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_y'>y</span><span class='rbrace'>}</span>
443
+ <span class='kw'>end</span></pre>
444
+ </td>
445
+ </tr>
446
+ </table>
447
+ </div>
448
+
449
+ </div>
450
+
451
+ <div id="instance_attr_details" class="attr_details">
452
+ <h2>Instance Attribute Details</h2>
453
+
454
+
455
+ <span id=""></span>
456
+ <div class="method_details first">
457
+ <h3 class="signature first" id="as_json-instance_method">
458
+
459
+ #<strong>as_json</strong> &#x21d2; <tt>Hash</tt> <span class="extras">(readonly)</span>
460
+
461
+
462
+
463
+
464
+
465
+ </h3><div class="docstring">
466
+ <div class="discussion">
467
+
468
+ <p>Returns coordinates as a hash, for integration with other objects.</p>
469
+
470
+
471
+ </div>
472
+ </div>
473
+ <div class="tags">
474
+
475
+ <p class="tag_title">Returns:</p>
476
+ <ul class="return">
477
+
478
+ <li>
479
+
480
+
481
+ <span class='type'>(<tt>Hash</tt>)</span>
482
+
483
+
484
+
485
+ &mdash;
486
+ <div class='inline'>
487
+ <p>coordinates as a hash, for integration with other objects.</p>
488
+ </div>
489
+
490
+ </li>
491
+
492
+ </ul>
493
+
494
+ </div><table class="source_code">
495
+ <tr>
496
+ <td>
497
+ <pre class="lines">
498
+
499
+
500
+ 17
501
+ 18
502
+ 19</pre>
503
+ </td>
504
+ <td>
505
+ <pre class="code"><span class="info file"># File 'lib/battlesnake/location.rb', line 17</span>
506
+
507
+ <span class='kw'>def</span> <span class='id identifier rubyid_as_json'>as_json</span>
508
+ <span class='ivar'>@as_json</span>
509
+ <span class='kw'>end</span></pre>
510
+ </td>
511
+ </tr>
512
+ </table>
513
+ </div>
514
+
515
+
516
+ <span id=""></span>
517
+ <div class="method_details ">
518
+ <h3 class="signature " id="x-instance_method">
519
+
520
+ #<strong>x</strong> &#x21d2; <tt>Integer</tt> <span class="extras">(readonly)</span>
521
+
522
+
523
+
524
+
525
+
526
+ </h3><div class="docstring">
527
+ <div class="discussion">
528
+
529
+ <p>Returns a positive integer representing the distance from the left side of the board.</p>
530
+
531
+
532
+ </div>
533
+ </div>
534
+ <div class="tags">
535
+
536
+ <p class="tag_title">Returns:</p>
537
+ <ul class="return">
538
+
539
+ <li>
540
+
541
+
542
+ <span class='type'>(<tt>Integer</tt>)</span>
543
+
544
+
545
+
546
+ &mdash;
547
+ <div class='inline'>
548
+ <p>a positive integer representing the distance from the left side of the board.</p>
549
+ </div>
550
+
551
+ </li>
552
+
553
+ </ul>
554
+
555
+ </div><table class="source_code">
556
+ <tr>
557
+ <td>
558
+ <pre class="lines">
559
+
560
+
561
+ 10
562
+ 11
563
+ 12</pre>
564
+ </td>
565
+ <td>
566
+ <pre class="code"><span class="info file"># File 'lib/battlesnake/location.rb', line 10</span>
567
+
568
+ <span class='kw'>def</span> <span class='id identifier rubyid_x'>x</span>
569
+ <span class='ivar'>@x</span>
570
+ <span class='kw'>end</span></pre>
571
+ </td>
572
+ </tr>
573
+ </table>
574
+ </div>
575
+
576
+
577
+ <span id=""></span>
578
+ <div class="method_details ">
579
+ <h3 class="signature " id="y-instance_method">
580
+
581
+ #<strong>y</strong> &#x21d2; <tt>Integer</tt> <span class="extras">(readonly)</span>
582
+
583
+
584
+
585
+
586
+
587
+ </h3><div class="docstring">
588
+ <div class="discussion">
589
+
590
+ <p>Returns a positive integer representing the distance from the bottom of the board.</p>
591
+
592
+
593
+ </div>
594
+ </div>
595
+ <div class="tags">
596
+
597
+ <p class="tag_title">Returns:</p>
598
+ <ul class="return">
599
+
600
+ <li>
601
+
602
+
603
+ <span class='type'>(<tt>Integer</tt>)</span>
604
+
605
+
606
+
607
+ &mdash;
608
+ <div class='inline'>
609
+ <p>a positive integer representing the distance from the bottom of the board.</p>
610
+ </div>
611
+
612
+ </li>
613
+
614
+ </ul>
615
+
616
+ </div><table class="source_code">
617
+ <tr>
618
+ <td>
619
+ <pre class="lines">
620
+
621
+
622
+ 14
623
+ 15
624
+ 16</pre>
625
+ </td>
626
+ <td>
627
+ <pre class="code"><span class="info file"># File 'lib/battlesnake/location.rb', line 14</span>
628
+
629
+ <span class='kw'>def</span> <span class='id identifier rubyid_y'>y</span>
630
+ <span class='ivar'>@y</span>
631
+ <span class='kw'>end</span></pre>
632
+ </td>
633
+ </tr>
634
+ </table>
635
+ </div>
636
+
637
+ </div>
638
+
639
+
640
+ <div id="instance_method_details" class="method_details_list">
641
+ <h2>Instance Method Details</h2>
642
+
643
+
644
+ <div class="method_details first">
645
+ <h3 class="signature first" id="coords-instance_method">
646
+
647
+ #<strong>coords</strong> &#x21d2; <tt>Array</tt>
648
+
649
+
650
+
651
+
652
+
653
+ </h3><div class="docstring">
654
+ <div class="discussion">
655
+
656
+ <p>Convenience method to return (x,y) coordinates as an array.</p>
657
+
658
+
659
+ </div>
660
+ </div>
661
+ <div class="tags">
662
+
663
+ <p class="tag_title">Returns:</p>
664
+ <ul class="return">
665
+
666
+ <li>
667
+
668
+
669
+ <span class='type'>(<tt>Array</tt>)</span>
670
+
671
+
672
+
673
+ </li>
674
+
675
+ </ul>
676
+
677
+ </div><table class="source_code">
678
+ <tr>
679
+ <td>
680
+ <pre class="lines">
681
+
682
+
683
+ 42
684
+ 43
685
+ 44
686
+ 45</pre>
687
+ </td>
688
+ <td>
689
+ <pre class="code"><span class="info file"># File 'lib/battlesnake/location.rb', line 42</span>
690
+
691
+ <span class='kw'>def</span> <span class='id identifier rubyid_coords'>coords</span>
692
+ <span class='kw'>return</span> <span class='ivar'>@coords</span> <span class='kw'>if</span> <span class='kw'>defined?</span><span class='lparen'>(</span><span class='ivar'>@coords</span><span class='rparen'>)</span>
693
+ <span class='ivar'>@coords</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='id identifier rubyid_x'>x</span><span class='comma'>,</span> <span class='id identifier rubyid_y'>y</span><span class='rbracket'>]</span>
694
+ <span class='kw'>end</span></pre>
695
+ </td>
696
+ </tr>
697
+ </table>
698
+ </div>
699
+
700
+ <div class="method_details ">
701
+ <h3 class="signature " id="direction-instance_method">
702
+
703
+ #<strong>direction</strong>(location) &#x21d2; <tt>one of <span class='object_link'><a href="#DIRECTIONS-constant" title="Battlesnake::Location::DIRECTIONS (constant)">DIRECTIONS</a></span></tt>
704
+
705
+
706
+
707
+
708
+
709
+ </h3><div class="docstring">
710
+ <div class="discussion">
711
+
712
+ <div class="note notetag">
713
+ <strong>Note:</strong>
714
+ <div class='inline'>
715
+ <p>Returns <em>nil</em> if the locations are the same. Favors “up” or “down” if horizontal and vertical distances are the same.</p>
716
+ </div>
717
+ </div>
718
+
719
+
720
+ <p>Determine the most prominent orthoganal direction [see DIRECTIONS] toward another location.</p>
721
+
722
+
723
+ </div>
724
+ </div>
725
+ <div class="tags">
726
+ <p class="tag_title">Parameters:</p>
727
+ <ul class="param">
728
+
729
+ <li>
730
+
731
+ <span class='name'>location</span>
732
+
733
+
734
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Battlesnake::Location (class)">Location</a></span></tt>)</span>
735
+
736
+
737
+
738
+ &mdash;
739
+ <div class='inline'>
740
+ <p>another location instance.</p>
741
+ </div>
742
+
743
+ </li>
744
+
745
+ </ul>
746
+
747
+ <p class="tag_title">Returns:</p>
748
+ <ul class="return">
749
+
750
+ <li>
751
+
752
+
753
+ <span class='type'>(<tt>one of <span class='object_link'><a href="#DIRECTIONS-constant" title="Battlesnake::Location::DIRECTIONS (constant)">DIRECTIONS</a></span></tt>)</span>
754
+
755
+
756
+
757
+ </li>
758
+
759
+ </ul>
760
+
761
+ </div><table class="source_code">
762
+ <tr>
763
+ <td>
764
+ <pre class="lines">
765
+
766
+
767
+ 67
768
+ 68
769
+ 69
770
+ 70
771
+ 71
772
+ 72
773
+ 73
774
+ 74
775
+ 75
776
+ 76
777
+ 77
778
+ 78</pre>
779
+ </td>
780
+ <td>
781
+ <pre class="code"><span class="info file"># File 'lib/battlesnake/location.rb', line 67</span>
782
+
783
+ <span class='kw'>def</span> <span class='id identifier rubyid_direction'>direction</span><span class='lparen'>(</span><span class='id identifier rubyid_location'>location</span><span class='rparen'>)</span>
784
+ <span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>if</span> <span class='id identifier rubyid_distance'>distance</span><span class='lparen'>(</span><span class='id identifier rubyid_location'>location</span><span class='rparen'>)</span> <span class='op'>==</span> <span class='int'>0</span>
785
+
786
+ <span class='id identifier rubyid_dx'>dx</span> <span class='op'>=</span> <span class='id identifier rubyid_delta_x'>delta_x</span><span class='lparen'>(</span><span class='id identifier rubyid_location'>location</span><span class='rparen'>)</span>
787
+ <span class='id identifier rubyid_dy'>dy</span> <span class='op'>=</span> <span class='id identifier rubyid_delta_y'>delta_y</span><span class='lparen'>(</span><span class='id identifier rubyid_location'>location</span><span class='rparen'>)</span>
788
+
789
+ <span class='kw'>if</span> <span class='id identifier rubyid_dx'>dx</span><span class='period'>.</span><span class='id identifier rubyid_abs'>abs</span> <span class='op'>&lt;=</span> <span class='id identifier rubyid_dy'>dy</span><span class='period'>.</span><span class='id identifier rubyid_abs'>abs</span>
790
+ <span class='id identifier rubyid_dy'>dy</span> <span class='op'>&gt;</span> <span class='int'>0</span> <span class='op'>?</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>up</span><span class='tstring_end'>&#39;</span></span> <span class='op'>:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>down</span><span class='tstring_end'>&#39;</span></span>
791
+ <span class='kw'>elsif</span> <span class='id identifier rubyid_dx'>dx</span><span class='period'>.</span><span class='id identifier rubyid_abs'>abs</span> <span class='op'>&gt;</span> <span class='id identifier rubyid_dy'>dy</span><span class='period'>.</span><span class='id identifier rubyid_abs'>abs</span>
792
+ <span class='id identifier rubyid_dx'>dx</span> <span class='op'>&gt;</span> <span class='int'>0</span> <span class='op'>?</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>right</span><span class='tstring_end'>&#39;</span></span> <span class='op'>:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>left</span><span class='tstring_end'>&#39;</span></span>
793
+ <span class='kw'>end</span>
794
+ <span class='kw'>end</span></pre>
795
+ </td>
796
+ </tr>
797
+ </table>
798
+ </div>
799
+
800
+ <div class="method_details ">
801
+ <h3 class="signature " id="distance-instance_method">
802
+
803
+ #<strong>distance</strong>(location) &#x21d2; <tt>Integer</tt>
804
+
805
+
806
+
807
+
808
+
809
+ </h3><div class="docstring">
810
+ <div class="discussion">
811
+
812
+ <p>Calculate the distance from this instance to another.</p>
813
+
814
+
815
+ </div>
816
+ </div>
817
+ <div class="tags">
818
+ <p class="tag_title">Parameters:</p>
819
+ <ul class="param">
820
+
821
+ <li>
822
+
823
+ <span class='name'>location</span>
824
+
825
+
826
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Battlesnake::Location (class)">Location</a></span></tt>)</span>
827
+
828
+
829
+
830
+ &mdash;
831
+ <div class='inline'>
832
+ <p>another Location instance.</p>
833
+ </div>
834
+
835
+ </li>
836
+
837
+ </ul>
838
+
839
+ <p class="tag_title">Returns:</p>
840
+ <ul class="return">
841
+
842
+ <li>
843
+
844
+
845
+ <span class='type'>(<tt>Integer</tt>)</span>
846
+
847
+
848
+
849
+ &mdash;
850
+ <div class='inline'>
851
+ <p>the number of blocks away, in “manhattan distance”.</p>
852
+ </div>
853
+
854
+ </li>
855
+
856
+ </ul>
857
+
858
+ </div><table class="source_code">
859
+ <tr>
860
+ <td>
861
+ <pre class="lines">
862
+
863
+
864
+ 53
865
+ 54
866
+ 55</pre>
867
+ </td>
868
+ <td>
869
+ <pre class="code"><span class="info file"># File 'lib/battlesnake/location.rb', line 53</span>
870
+
871
+ <span class='kw'>def</span> <span class='id identifier rubyid_distance'>distance</span><span class='lparen'>(</span><span class='id identifier rubyid_location'>location</span><span class='rparen'>)</span>
872
+ <span class='lbracket'>[</span><span class='id identifier rubyid_delta_x'>delta_x</span><span class='lparen'>(</span><span class='id identifier rubyid_location'>location</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_abs'>abs</span><span class='comma'>,</span> <span class='id identifier rubyid_delta_y'>delta_y</span><span class='lparen'>(</span><span class='id identifier rubyid_location'>location</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_abs'>abs</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='symbol'>:+</span><span class='rparen'>)</span>
873
+ <span class='kw'>end</span></pre>
874
+ </td>
875
+ </tr>
876
+ </table>
877
+ </div>
878
+
879
+ <div class="method_details ">
880
+ <h3 class="signature " id="move-instance_method">
881
+
882
+ #<strong>move</strong>(requested_direction) &#x21d2; <tt><span class='object_link'><a href="" title="Battlesnake::Location (class)">Location</a></span></tt>
883
+
884
+
885
+
886
+
887
+
888
+ </h3><div class="docstring">
889
+ <div class="discussion">
890
+
891
+ <div class="note notetag">
892
+ <strong>Note:</strong>
893
+ <div class='inline'>
894
+ <p>Returns <em>nil</em> if the requested direction is not recognized.</p>
895
+ </div>
896
+ </div>
897
+
898
+
899
+ <p>Return a new location instance with coordinates moved one step in the requested direction.</p>
900
+
901
+
902
+ </div>
903
+ </div>
904
+ <div class="tags">
905
+ <p class="tag_title">Parameters:</p>
906
+ <ul class="param">
907
+
908
+ <li>
909
+
910
+ <span class='name'>requested_direction</span>
911
+
912
+
913
+ <span class='type'>(<tt>one of <span class='object_link'><a href="#DIRECTIONS-constant" title="Battlesnake::Location::DIRECTIONS (constant)">DIRECTIONS</a></span></tt>)</span>
914
+
915
+
916
+
917
+ </li>
918
+
919
+ </ul>
920
+
921
+ <p class="tag_title">Returns:</p>
922
+ <ul class="return">
923
+
924
+ <li>
925
+
926
+
927
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Battlesnake::Location (class)">Location</a></span></tt>)</span>
928
+
929
+
930
+
931
+ &mdash;
932
+ <div class='inline'>
933
+ <p>a new location instance.</p>
934
+ </div>
935
+
936
+ </li>
937
+
938
+ </ul>
939
+
940
+ </div><table class="source_code">
941
+ <tr>
942
+ <td>
943
+ <pre class="lines">
944
+
945
+
946
+ 88
947
+ 89
948
+ 90
949
+ 91
950
+ 92
951
+ 93
952
+ 94
953
+ 95
954
+ 96
955
+ 97
956
+ 98
957
+ 99
958
+ 100
959
+ 101
960
+ 102
961
+ 103
962
+ 104
963
+ 105
964
+ 106</pre>
965
+ </td>
966
+ <td>
967
+ <pre class="code"><span class="info file"># File 'lib/battlesnake/location.rb', line 88</span>
968
+
969
+ <span class='kw'>def</span> <span class='id identifier rubyid_move'>move</span><span class='lparen'>(</span><span class='id identifier rubyid_requested_direction'>requested_direction</span><span class='rparen'>)</span>
970
+ <span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>unless</span> <span class='const'><span class='object_link'><a href="#DIRECTIONS-constant" title="Battlesnake::Location::DIRECTIONS (constant)">DIRECTIONS</a></span></span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_requested_direction'>requested_direction</span><span class='rparen'>)</span>
971
+
972
+ <span class='id identifier rubyid_new_x'>new_x</span> <span class='op'>=</span> <span class='id identifier rubyid_x'>x</span>
973
+ <span class='id identifier rubyid_new_y'>new_y</span> <span class='op'>=</span> <span class='id identifier rubyid_y'>y</span>
974
+
975
+ <span class='kw'>case</span> <span class='id identifier rubyid_requested_direction'>requested_direction</span>
976
+ <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>right</span><span class='tstring_end'>&#39;</span></span>
977
+ <span class='id identifier rubyid_new_x'>new_x</span> <span class='op'>+=</span> <span class='int'>1</span>
978
+ <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>left</span><span class='tstring_end'>&#39;</span></span>
979
+ <span class='id identifier rubyid_new_x'>new_x</span> <span class='op'>-=</span> <span class='int'>1</span>
980
+ <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>up</span><span class='tstring_end'>&#39;</span></span>
981
+ <span class='id identifier rubyid_new_y'>new_y</span> <span class='op'>+=</span> <span class='int'>1</span>
982
+ <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>down</span><span class='tstring_end'>&#39;</span></span>
983
+ <span class='id identifier rubyid_new_y'>new_y</span> <span class='op'>-=</span> <span class='int'>1</span>
984
+ <span class='kw'>end</span>
985
+
986
+ <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_new_x'>new_x</span><span class='comma'>,</span> <span class='id identifier rubyid_new_y'>new_y</span><span class='rparen'>)</span>
987
+ <span class='kw'>end</span></pre>
988
+ </td>
989
+ </tr>
990
+ </table>
991
+ </div>
992
+
993
+ </div>
994
+
995
+ </div>
996
+
997
+ <div id="footer">
998
+ Generated on Fri Nov 4 14:55:40 2022 by
999
+ <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1000
+ 0.9.28 (ruby-2.7.2).
1001
+ </div>
1002
+
1003
+ </div>
1004
+ </body>
1005
+ </html>