battlesnake 0.1.1 → 0.1.3

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.
@@ -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::Board</li>
78
80
 
79
81
  </ul>
@@ -307,6 +309,54 @@
307
309
  <li class="public ">
308
310
  <span class="summary_signature">
309
311
 
312
+ <a href="#available%3F-instance_method" title="#available? (instance method)">#<strong>available?</strong>(location) &#x21d2; Boolean </a>
313
+
314
+
315
+
316
+ </span>
317
+
318
+
319
+
320
+
321
+
322
+
323
+
324
+
325
+
326
+ <span class="summary_desc"><div class='inline'>
327
+ <p>Whether the supplied location is available (unoccupied).</p>
328
+ </div></span>
329
+
330
+ </li>
331
+
332
+
333
+ <li class="public ">
334
+ <span class="summary_signature">
335
+
336
+ <a href="#available_directions-instance_method" title="#available_directions (instance method)">#<strong>available_directions</strong>(location) &#x21d2; Array&lt;String&gt; </a>
337
+
338
+
339
+
340
+ </span>
341
+
342
+
343
+
344
+
345
+
346
+
347
+
348
+
349
+
350
+ <span class="summary_desc"><div class='inline'>
351
+ <p>List of directions (up, down, left, right) available for moving from given <em>Location</em>.</p>
352
+ </div></span>
353
+
354
+ </li>
355
+
356
+
357
+ <li class="public ">
358
+ <span class="summary_signature">
359
+
310
360
  <a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(json_or_hash) &#x21d2; Board </a>
311
361
 
312
362
 
@@ -327,12 +377,119 @@
327
377
  <p>Returns a new instance of Board.</p>
328
378
  </div></span>
329
379
 
380
+ </li>
381
+
382
+
383
+ <li class="public ">
384
+ <span class="summary_signature">
385
+
386
+ <a href="#occupied%3F-instance_method" title="#occupied? (instance method)">#<strong>occupied?</strong>(location) &#x21d2; Boolean </a>
387
+
388
+
389
+
390
+ </span>
391
+
392
+
393
+
394
+
395
+
396
+
397
+
398
+
399
+
400
+ <span class="summary_desc"><div class='inline'>
401
+ <p>Whether the supplied location is occupied.</p>
402
+ </div></span>
403
+
404
+ </li>
405
+
406
+
407
+ <li class="public ">
408
+ <span class="summary_signature">
409
+
410
+ <a href="#occupied_locations-instance_method" title="#occupied_locations (instance method)">#<strong>occupied_locations</strong> &#x21d2; Array&lt;Location&gt; </a>
411
+
412
+
413
+
414
+ </span>
415
+
416
+
417
+
418
+
419
+
420
+
421
+
422
+
423
+
424
+ <span class="summary_desc"><div class='inline'>
425
+ <p>List of all occupied locations on the board; snakes, food, hazards, etc.</p>
426
+ </div></span>
427
+
428
+ </li>
429
+
430
+
431
+ <li class="public ">
432
+ <span class="summary_signature">
433
+
434
+ <a href="#on_board%3F-instance_method" title="#on_board? (instance method)">#<strong>on_board?</strong>(location) &#x21d2; Boolean </a>
435
+
436
+
437
+
438
+ </span>
439
+
440
+
441
+
442
+
443
+
444
+
445
+
446
+
447
+
448
+ <span class="summary_desc"><div class='inline'>
449
+ <p>Where the supplied location falls within the boundaries of the board.</p>
450
+ </div></span>
451
+
452
+ </li>
453
+
454
+
455
+ <li class="public ">
456
+ <span class="summary_signature">
457
+
458
+ <a href="#paths-instance_method" title="#paths (instance method)">#<strong>paths</strong>(from, to) &#x21d2; Array&lt;Path&gt; </a>
459
+
460
+
461
+
462
+ </span>
463
+
464
+
465
+
466
+
467
+
468
+
469
+
470
+
471
+
472
+ <span class="summary_desc"><div class='inline'>
473
+ <p>List of valid, consecutive paths from one location to the next.</p>
474
+ </div></span>
475
+
330
476
  </li>
331
477
 
332
478
 
333
479
  </ul>
334
480
 
335
481
 
482
+
483
+
484
+
485
+
486
+
487
+
488
+
489
+
490
+
491
+ <h3 class="inherited">Methods inherited from <span class='object_link'><a href="Base.html" title="Battlesnake::Base (class)">Base</a></span></h3>
492
+ <p class="inherited"><span class='object_link'><a href="Base.html#==-instance_method" title="Battlesnake::Base#== (method)">#==</a></span></p>
336
493
  <div id="constructor_details" class="method_details_list">
337
494
  <h2>Constructor Details</h2>
338
495
 
@@ -785,10 +942,499 @@
785
942
  </div>
786
943
 
787
944
 
945
+ <div id="instance_method_details" class="method_details_list">
946
+ <h2>Instance Method Details</h2>
947
+
948
+
949
+ <div class="method_details first">
950
+ <h3 class="signature first" id="available?-instance_method">
951
+
952
+ #<strong>available?</strong>(location) &#x21d2; <tt>Boolean</tt>
953
+
954
+
955
+
956
+
957
+
958
+ </h3><div class="docstring">
959
+ <div class="discussion">
960
+
961
+ <p>Whether the supplied location is available (unoccupied).</p>
962
+
963
+
964
+ </div>
965
+ </div>
966
+ <div class="tags">
967
+ <p class="tag_title">Parameters:</p>
968
+ <ul class="param">
969
+
970
+ <li>
971
+
972
+ <span class='name'>location</span>
973
+
974
+
975
+ <span class='type'>(<tt><span class='object_link'><a href="Location.html" title="Battlesnake::Location (class)">Location</a></span></tt>)</span>
976
+
977
+
978
+
979
+ &mdash;
980
+ <div class='inline'>
981
+ <p>being tested for availability.</p>
982
+ </div>
983
+
984
+ </li>
985
+
986
+ </ul>
987
+
988
+ <p class="tag_title">Returns:</p>
989
+ <ul class="return">
990
+
991
+ <li>
992
+
993
+
994
+ <span class='type'>(<tt>Boolean</tt>)</span>
995
+
996
+
997
+
998
+ &mdash;
999
+ <div class='inline'>
1000
+ <p>true if location is available (unoccupied by snakes, food, hazards, etc).</p>
1001
+ </div>
1002
+
1003
+ </li>
1004
+
1005
+ </ul>
1006
+
1007
+ </div><table class="source_code">
1008
+ <tr>
1009
+ <td>
1010
+ <pre class="lines">
1011
+
1012
+
1013
+ 78
1014
+ 79
1015
+ 80</pre>
1016
+ </td>
1017
+ <td>
1018
+ <pre class="code"><span class="info file"># File 'lib/battlesnake/board.rb', line 78</span>
1019
+
1020
+ <span class='kw'>def</span> <span class='id identifier rubyid_available?'>available?</span><span class='lparen'>(</span><span class='id identifier rubyid_location'>location</span><span class='rparen'>)</span>
1021
+ <span class='id identifier rubyid_on_board?'>on_board?</span><span class='lparen'>(</span><span class='id identifier rubyid_location'>location</span><span class='rparen'>)</span> <span class='op'>&amp;&amp;</span> <span class='op'>!</span><span class='id identifier rubyid_occupied?'>occupied?</span><span class='lparen'>(</span><span class='id identifier rubyid_location'>location</span><span class='rparen'>)</span>
1022
+ <span class='kw'>end</span></pre>
1023
+ </td>
1024
+ </tr>
1025
+ </table>
1026
+ </div>
1027
+
1028
+ <div class="method_details ">
1029
+ <h3 class="signature " id="available_directions-instance_method">
1030
+
1031
+ #<strong>available_directions</strong>(location) &#x21d2; <tt>Array&lt;String&gt;</tt>
1032
+
1033
+
1034
+
1035
+
1036
+
1037
+ </h3><div class="docstring">
1038
+ <div class="discussion">
1039
+
1040
+ <p>List of directions (up, down, left, right) available for moving from given <em>Location</em>.</p>
1041
+
1042
+
1043
+ </div>
1044
+ </div>
1045
+ <div class="tags">
1046
+ <p class="tag_title">Parameters:</p>
1047
+ <ul class="param">
1048
+
1049
+ <li>
1050
+
1051
+ <span class='name'>location</span>
1052
+
1053
+
1054
+ <span class='type'>(<tt><span class='object_link'><a href="Location.html" title="Battlesnake::Location (class)">Location</a></span></tt>)</span>
1055
+
1056
+
1057
+
1058
+ &mdash;
1059
+ <div class='inline'>
1060
+ <p>from which moving is desired.</p>
1061
+ </div>
1062
+
1063
+ </li>
1064
+
1065
+ </ul>
1066
+
1067
+ <p class="tag_title">Returns:</p>
1068
+ <ul class="return">
1069
+
1070
+ <li>
1071
+
1072
+
1073
+ <span class='type'>(<tt>Array&lt;String&gt;</tt>)</span>
1074
+
1075
+
1076
+
1077
+ &mdash;
1078
+ <div class='inline'>
1079
+ <p>list of direction strings (“up”, “down”, “left”, “right”)</p>
1080
+ </div>
1081
+
1082
+ </li>
1083
+
1084
+ </ul>
1085
+
1086
+ </div><table class="source_code">
1087
+ <tr>
1088
+ <td>
1089
+ <pre class="lines">
1090
+
1091
+
1092
+ 88
1093
+ 89
1094
+ 90
1095
+ 91
1096
+ 92</pre>
1097
+ </td>
1098
+ <td>
1099
+ <pre class="code"><span class="info file"># File 'lib/battlesnake/board.rb', line 88</span>
1100
+
1101
+ <span class='kw'>def</span> <span class='id identifier rubyid_available_directions'>available_directions</span><span class='lparen'>(</span><span class='id identifier rubyid_location'>location</span><span class='rparen'>)</span>
1102
+ <span class='const'><span class='object_link'><a href="Location.html" title="Battlesnake::Location (class)">Location</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Location.html#DIRECTIONS-constant" title="Battlesnake::Location::DIRECTIONS (constant)">DIRECTIONS</a></span></span><span class='period'>.</span><span class='id identifier rubyid_select'>select</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_direction'>direction</span><span class='op'>|</span>
1103
+ <span class='id identifier rubyid_available?'>available?</span><span class='lparen'>(</span><span class='id identifier rubyid_location'>location</span><span class='period'>.</span><span class='id identifier rubyid_move'>move</span><span class='lparen'>(</span><span class='id identifier rubyid_direction'>direction</span><span class='rparen'>)</span><span class='rparen'>)</span>
1104
+ <span class='kw'>end</span>
1105
+ <span class='kw'>end</span></pre>
1106
+ </td>
1107
+ </tr>
1108
+ </table>
1109
+ </div>
1110
+
1111
+ <div class="method_details ">
1112
+ <h3 class="signature " id="occupied?-instance_method">
1113
+
1114
+ #<strong>occupied?</strong>(location) &#x21d2; <tt>Boolean</tt>
1115
+
1116
+
1117
+
1118
+
1119
+
1120
+ </h3><div class="docstring">
1121
+ <div class="discussion">
1122
+
1123
+ <p>Whether the supplied location is occupied.</p>
1124
+
1125
+
1126
+ </div>
1127
+ </div>
1128
+ <div class="tags">
1129
+ <p class="tag_title">Parameters:</p>
1130
+ <ul class="param">
1131
+
1132
+ <li>
1133
+
1134
+ <span class='name'>location</span>
1135
+
1136
+
1137
+ <span class='type'>(<tt><span class='object_link'><a href="Location.html" title="Battlesnake::Location (class)">Location</a></span></tt>)</span>
1138
+
1139
+
1140
+
1141
+ &mdash;
1142
+ <div class='inline'>
1143
+ <p>being checked for occupancy.</p>
1144
+ </div>
1145
+
1146
+ </li>
1147
+
1148
+ </ul>
1149
+
1150
+ <p class="tag_title">Returns:</p>
1151
+ <ul class="return">
1152
+
1153
+ <li>
1154
+
1155
+
1156
+ <span class='type'>(<tt>Boolean</tt>)</span>
1157
+
1158
+
1159
+
1160
+ &mdash;
1161
+ <div class='inline'>
1162
+ <p>true if location is occupied by snakes, food, hazards, etc.</p>
1163
+ </div>
1164
+
1165
+ </li>
1166
+
1167
+ </ul>
1168
+
1169
+ </div><table class="source_code">
1170
+ <tr>
1171
+ <td>
1172
+ <pre class="lines">
1173
+
1174
+
1175
+ 58
1176
+ 59
1177
+ 60</pre>
1178
+ </td>
1179
+ <td>
1180
+ <pre class="code"><span class="info file"># File 'lib/battlesnake/board.rb', line 58</span>
1181
+
1182
+ <span class='kw'>def</span> <span class='id identifier rubyid_occupied?'>occupied?</span><span class='lparen'>(</span><span class='id identifier rubyid_location'>location</span><span class='rparen'>)</span>
1183
+ <span class='id identifier rubyid_occupied_locations'>occupied_locations</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_location'>location</span><span class='rparen'>)</span>
1184
+ <span class='kw'>end</span></pre>
1185
+ </td>
1186
+ </tr>
1187
+ </table>
1188
+ </div>
1189
+
1190
+ <div class="method_details ">
1191
+ <h3 class="signature " id="occupied_locations-instance_method">
1192
+
1193
+ #<strong>occupied_locations</strong> &#x21d2; <tt>Array&lt;<span class='object_link'><a href="Location.html" title="Battlesnake::Location (class)">Location</a></span>&gt;</tt>
1194
+
1195
+
1196
+
1197
+
1198
+
1199
+ </h3><div class="docstring">
1200
+ <div class="discussion">
1201
+
1202
+ <p>List of all occupied locations on the board; snakes, food, hazards, etc</p>
1203
+
1204
+
1205
+ </div>
1206
+ </div>
1207
+ <div class="tags">
1208
+
1209
+ <p class="tag_title">Returns:</p>
1210
+ <ul class="return">
1211
+
1212
+ <li>
1213
+
1214
+
1215
+ <span class='type'>(<tt>Array&lt;<span class='object_link'><a href="Location.html" title="Battlesnake::Location (class)">Location</a></span>&gt;</tt>)</span>
1216
+
1217
+
1218
+
1219
+ &mdash;
1220
+ <div class='inline'>
1221
+ <p>list of occupied locations</p>
1222
+ </div>
1223
+
1224
+ </li>
1225
+
1226
+ </ul>
1227
+
1228
+ </div><table class="source_code">
1229
+ <tr>
1230
+ <td>
1231
+ <pre class="lines">
1232
+
1233
+
1234
+ 47
1235
+ 48
1236
+ 49
1237
+ 50</pre>
1238
+ </td>
1239
+ <td>
1240
+ <pre class="code"><span class="info file"># File 'lib/battlesnake/board.rb', line 47</span>
1241
+
1242
+ <span class='kw'>def</span> <span class='id identifier rubyid_occupied_locations'>occupied_locations</span>
1243
+ <span class='kw'>return</span> <span class='ivar'>@occupied_locations</span> <span class='kw'>if</span> <span class='kw'>defined?</span><span class='lparen'>(</span><span class='ivar'>@occupied_locations</span><span class='rparen'>)</span>
1244
+ <span class='ivar'>@occupied_locations</span> <span class='op'>=</span> <span class='id identifier rubyid_snakes'>snakes</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lparen'>(</span><span class='op'>&amp;</span><span class='symbol'>:body</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span> <span class='op'>+</span> <span class='id identifier rubyid_food'>food</span> <span class='op'>+</span> <span class='id identifier rubyid_hazards'>hazards</span>
1245
+ <span class='kw'>end</span></pre>
1246
+ </td>
1247
+ </tr>
1248
+ </table>
1249
+ </div>
1250
+
1251
+ <div class="method_details ">
1252
+ <h3 class="signature " id="on_board?-instance_method">
1253
+
1254
+ #<strong>on_board?</strong>(location) &#x21d2; <tt>Boolean</tt>
1255
+
1256
+
1257
+
1258
+
1259
+
1260
+ </h3><div class="docstring">
1261
+ <div class="discussion">
1262
+
1263
+ <p>Where the supplied location falls within the boundaries of the board.</p>
1264
+
1265
+
1266
+ </div>
1267
+ </div>
1268
+ <div class="tags">
1269
+ <p class="tag_title">Parameters:</p>
1270
+ <ul class="param">
1271
+
1272
+ <li>
1273
+
1274
+ <span class='name'>location</span>
1275
+
1276
+
1277
+ <span class='type'>(<tt><span class='object_link'><a href="Location.html" title="Battlesnake::Location (class)">Location</a></span></tt>)</span>
1278
+
1279
+
1280
+
1281
+ &mdash;
1282
+ <div class='inline'>
1283
+ <p>being tested.</p>
1284
+ </div>
1285
+
1286
+ </li>
1287
+
1288
+ </ul>
1289
+
1290
+ <p class="tag_title">Returns:</p>
1291
+ <ul class="return">
1292
+
1293
+ <li>
1294
+
1295
+
1296
+ <span class='type'>(<tt>Boolean</tt>)</span>
1297
+
1298
+
1299
+
1300
+ &mdash;
1301
+ <div class='inline'>
1302
+ <p>true if location is within the boundaries of the board.</p>
1303
+ </div>
1304
+
1305
+ </li>
1306
+
1307
+ </ul>
1308
+
1309
+ </div><table class="source_code">
1310
+ <tr>
1311
+ <td>
1312
+ <pre class="lines">
1313
+
1314
+
1315
+ 68
1316
+ 69
1317
+ 70</pre>
1318
+ </td>
1319
+ <td>
1320
+ <pre class="code"><span class="info file"># File 'lib/battlesnake/board.rb', line 68</span>
1321
+
1322
+ <span class='kw'>def</span> <span class='id identifier rubyid_on_board?'>on_board?</span><span class='lparen'>(</span><span class='id identifier rubyid_location'>location</span><span class='rparen'>)</span>
1323
+ <span class='id identifier rubyid_location'>location</span><span class='period'>.</span><span class='id identifier rubyid_x'>x</span> <span class='op'>&gt;=</span> <span class='int'>0</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_location'>location</span><span class='period'>.</span><span class='id identifier rubyid_y'>y</span> <span class='op'>&gt;=</span> <span class='int'>0</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_location'>location</span><span class='period'>.</span><span class='id identifier rubyid_x'>x</span> <span class='op'>&lt;</span> <span class='id identifier rubyid_width'>width</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_location'>location</span><span class='period'>.</span><span class='id identifier rubyid_y'>y</span> <span class='op'>&lt;</span> <span class='id identifier rubyid_height'>height</span>
1324
+ <span class='kw'>end</span></pre>
1325
+ </td>
1326
+ </tr>
1327
+ </table>
1328
+ </div>
1329
+
1330
+ <div class="method_details ">
1331
+ <h3 class="signature " id="paths-instance_method">
1332
+
1333
+ #<strong>paths</strong>(from, to) &#x21d2; <tt>Array&lt;Path&gt;</tt>
1334
+
1335
+
1336
+
1337
+
1338
+
1339
+ </h3><div class="docstring">
1340
+ <div class="discussion">
1341
+
1342
+ <p>List of valid, consecutive paths from one location to the next. Paths may not:</p>
1343
+
1344
+ <pre class="code ruby"><code class="ruby">- wander outside board boundaries.
1345
+ - use the same location more than once.
1346
+ - contain occupied locations, EXCEPT the start/end locations.
1347
+ </code></pre>
1348
+
1349
+ <p>The exception for start/end locations allows us to generate paths, for example, from a snake to a food location, without having to calulate the starting/ending permutations ourselves.</p>
1350
+
1351
+
1352
+ </div>
1353
+ </div>
1354
+ <div class="tags">
1355
+ <p class="tag_title">Parameters:</p>
1356
+ <ul class="param">
1357
+
1358
+ <li>
1359
+
1360
+ <span class='name'>from</span>
1361
+
1362
+
1363
+ <span class='type'>(<tt><span class='object_link'><a href="Location.html" title="Battlesnake::Location (class)">Location</a></span></tt>)</span>
1364
+
1365
+
1366
+
1367
+ &mdash;
1368
+ <div class='inline'>
1369
+ <p>starting location, may be occupied</p>
1370
+ </div>
1371
+
1372
+ </li>
1373
+
1374
+ <li>
1375
+
1376
+ <span class='name'>to</span>
1377
+
1378
+
1379
+ <span class='type'>(<tt><span class='object_link'><a href="Location.html" title="Battlesnake::Location (class)">Location</a></span></tt>)</span>
1380
+
1381
+
1382
+
1383
+ &mdash;
1384
+ <div class='inline'>
1385
+ <p>starting location, may be occupied</p>
1386
+ </div>
1387
+
1388
+ </li>
1389
+
1390
+ </ul>
1391
+
1392
+ <p class="tag_title">Returns:</p>
1393
+ <ul class="return">
1394
+
1395
+ <li>
1396
+
1397
+
1398
+ <span class='type'>(<tt>Array&lt;Path&gt;</tt>)</span>
1399
+
1400
+
1401
+
1402
+ &mdash;
1403
+ <div class='inline'>
1404
+ <p>a list of paths, which themselves are lists of consecutive, valid locations.</p>
1405
+ </div>
1406
+
1407
+ </li>
1408
+
1409
+ </ul>
1410
+
1411
+ </div><table class="source_code">
1412
+ <tr>
1413
+ <td>
1414
+ <pre class="lines">
1415
+
1416
+
1417
+ 108
1418
+ 109
1419
+ 110</pre>
1420
+ </td>
1421
+ <td>
1422
+ <pre class="code"><span class="info file"># File 'lib/battlesnake/board.rb', line 108</span>
1423
+
1424
+ <span class='kw'>def</span> <span class='id identifier rubyid_paths'>paths</span><span class='lparen'>(</span><span class='id identifier rubyid_from'>from</span><span class='comma'>,</span> <span class='id identifier rubyid_to'>to</span><span class='rparen'>)</span>
1425
+
1426
+ <span class='kw'>end</span></pre>
1427
+ </td>
1428
+ </tr>
1429
+ </table>
1430
+ </div>
1431
+
1432
+ </div>
1433
+
788
1434
  </div>
789
1435
 
790
1436
  <div id="footer">
791
- Generated on Fri Nov 4 19:07:50 2022 by
1437
+ Generated on Mon Nov 7 15:30:13 2022 by
792
1438
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
793
1439
  0.9.28 (ruby-2.7.2).
794
1440
  </div>
@@ -125,7 +125,7 @@
125
125
  </div>
126
126
 
127
127
  <div id="footer">
128
- Generated on Fri Nov 4 19:07:49 2022 by
128
+ Generated on Mon Nov 7 15:30:13 2022 by
129
129
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
130
130
  0.9.28 (ruby-2.7.2).
131
131
  </div>