battlesnake 0.1.4 → 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/CHANGELOG.md +14 -0
- data/Gemfile.lock +1 -1
- data/lib/battlesnake/board.rb +47 -1
- data/lib/battlesnake/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f8520692a2004710c7e4c597c44248819caf6b7f5f864985a70a6ab3fa85e44
|
4
|
+
data.tar.gz: 66547ac978ce2a6c48a575d9bc6d6b57630c3e980445882278fef94c08a0b466
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c37667f70cfcc7ad968e4563341b00cb46f336f3ffe86a14a7fd8d0112fccea55cb545479d8e7423c7377c1293a45a7406a024ac1380e18eff62a40325a78ca
|
7
|
+
data.tar.gz: 55ea92d1d7e6e0ae6d163a23f7d517c3144e9adec7c312615294a6f33613d95830dea08b5865249674239f046a08e54e77a1baa5ecc6911daab1ae22ba24c229
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Battlesnake
|
2
2
|
|
3
|
+
## 0.1.5 (2023-01-04)
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
- Board
|
8
|
+
- #available_neighbors(location) returns neighboring locations available for moving.
|
9
|
+
- #flood_fills(location) returns hash of reachable locations by direction
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
- Board
|
14
|
+
- #find_path(from, to, max_distance: nil) skips recursion if manhattan distance is greater than
|
15
|
+
max_distance.
|
16
|
+
|
3
17
|
## 0.1.4 (2023-01-03)
|
4
18
|
|
5
19
|
### Added
|
data/Gemfile.lock
CHANGED
data/lib/battlesnake/board.rb
CHANGED
@@ -102,6 +102,33 @@ module Battlesnake
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
+
##
|
106
|
+
# List of neighboring locations available for moving from given _Location_.
|
107
|
+
#
|
108
|
+
# @param [Location] location from which moving is desired.
|
109
|
+
#
|
110
|
+
# @return [Array<Location>] list of locations
|
111
|
+
def available_neighbors(location)
|
112
|
+
Location::DIRECTIONS.map{ |direction| location.move(direction) }.select{ |l| available?(l) }
|
113
|
+
end
|
114
|
+
|
115
|
+
##
|
116
|
+
# List reachable locations in each orthogonal direction.
|
117
|
+
#
|
118
|
+
# @return [Hash] hash of reachable locations by direction
|
119
|
+
def flood_fills(location)
|
120
|
+
fills = Location::DIRECTIONS.map{ |direction| [direction, []]}.to_h
|
121
|
+
|
122
|
+
available_directions(location).each do |direction|
|
123
|
+
@flood_fill_checked = []
|
124
|
+
@flood_fill_matches = []
|
125
|
+
|
126
|
+
fills[direction] = flood_fill(location.move(direction)) #.uniq(&:coords)
|
127
|
+
end
|
128
|
+
|
129
|
+
fills
|
130
|
+
end
|
131
|
+
|
105
132
|
##
|
106
133
|
# List of valid, consecutive paths from one location to the next. Paths may not:
|
107
134
|
#
|
@@ -117,8 +144,11 @@ module Battlesnake
|
|
117
144
|
#
|
118
145
|
# @return [Array<Path>] a list of paths, which themselves are lists of consecutive, valid locations.
|
119
146
|
def find_path(from, to, max_distance: nil)
|
147
|
+
distance = from.distance(to)
|
148
|
+
return nil if max_distance && max_distance < distance
|
149
|
+
|
120
150
|
@paths = []
|
121
|
-
@ideal_path_size =
|
151
|
+
@ideal_path_size = distance + 1
|
122
152
|
@shortest_path_size = max_distance || @ideal_path_size
|
123
153
|
@ideal_path_size_found = false
|
124
154
|
|
@@ -127,6 +157,22 @@ module Battlesnake
|
|
127
157
|
@paths.select{ |path| path.size == @shortest_path_size }.first
|
128
158
|
end
|
129
159
|
|
160
|
+
private
|
161
|
+
|
162
|
+
def flood_fill(location)
|
163
|
+
@flood_fill_checked << location.coords
|
164
|
+
|
165
|
+
unless occupied?(location)
|
166
|
+
@flood_fill_matches << location
|
167
|
+
|
168
|
+
available_neighbors(location).each do |neighbor|
|
169
|
+
flood_fill(neighbor) unless @flood_fill_checked.include?(neighbor.coords)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
@flood_fill_matches
|
174
|
+
end
|
175
|
+
|
130
176
|
def recursive_paths(from, to, path)
|
131
177
|
head = path.last
|
132
178
|
|
data/lib/battlesnake/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jaime Bellmyer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|