gingham 0.2.0 → 0.3.0
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/.travis.yml +1 -0
- data/README.md +1 -0
- data/gingham.gemspec +1 -0
- data/lib/gingham/actor.rb +4 -1
- data/lib/gingham/cell.rb +5 -1
- data/lib/gingham/path_finder.rb +73 -88
- data/lib/gingham/space.rb +1 -1
- data/lib/gingham/version.rb +1 -1
- data/lib/gingham/waypoint.rb +1 -4
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f4ff2ca6e1ddb2e09b7c38b0fb695fbca6b1b9b
|
4
|
+
data.tar.gz: c0e7e93a7e5c13921d5ec4f1a34843e41e6993b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5fe647461cec8da29c6f46c3b088e8de6687c7de996948de66b2e5591d3103b28ce64d265309128df8c3bc07d373b68c3959a137fd3890a76bbdef88161d2db
|
7
|
+
data.tar.gz: e3ba843d637ae944ca2cfd18fcbea6897d3079f15b643392977ae230b1c2bf67d163b67e03a89a1998ddb1739e5a12136e279b6ec1c945eb15f1eb3827fa11c9
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Gingham
|
2
2
|
|
3
3
|
[](https://travis-ci.org/cignoir/gingham)
|
4
|
+
[](https://coveralls.io/github/cignoir/gingham?branch=master)
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
data/gingham.gemspec
CHANGED
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "bundler", '~> 1.11', '>= 1.11.2'
|
24
24
|
spec.add_development_dependency "rake", '~> 11.1', '>= 11.1.2'
|
25
25
|
spec.add_development_dependency "rspec", '~> 3.4', '>= 3.4.0'
|
26
|
+
spec.add_development_dependency(%q<coveralls>, [">= 0"])
|
26
27
|
end
|
data/lib/gingham/actor.rb
CHANGED
@@ -4,12 +4,15 @@ module Gingham
|
|
4
4
|
attr_accessor :move_steps
|
5
5
|
attr_accessor :team_id
|
6
6
|
attr_accessor :move_status
|
7
|
+
attr_accessor :move_power, :jump_power
|
7
8
|
|
8
|
-
def initialize(waypoint, weight = 100, team_id = 0)
|
9
|
+
def initialize(waypoint, weight = 100, team_id = 0, move_power = 999, jump_power = 999)
|
9
10
|
@waypoint = waypoint
|
10
11
|
@weight = weight
|
11
12
|
@team_id = team_id
|
12
13
|
@move_status = Gingham::MoveStatus::DEFAULT
|
14
|
+
@move_power = move_power
|
15
|
+
@jump_power = jump_power
|
13
16
|
end
|
14
17
|
|
15
18
|
def move_end?
|
data/lib/gingham/cell.rb
CHANGED
@@ -12,7 +12,6 @@ module Gingham
|
|
12
12
|
other.is_a?(Gingham::Cell) && @x == other.x && @y == other.y && @z == other.z
|
13
13
|
end
|
14
14
|
|
15
|
-
#FIXME
|
16
15
|
def occupied?
|
17
16
|
@is_occupied
|
18
17
|
end
|
@@ -36,5 +35,10 @@ module Gingham
|
|
36
35
|
def inspect
|
37
36
|
"(#{x},#{y},#{z})"
|
38
37
|
end
|
38
|
+
|
39
|
+
def set_ground
|
40
|
+
@is_ground = true
|
41
|
+
self
|
42
|
+
end
|
39
43
|
end
|
40
44
|
end
|
data/lib/gingham/path_finder.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Gingham
|
2
2
|
class PathFinder
|
3
3
|
class << self
|
4
|
-
def find_move_path(space, from, to,
|
4
|
+
def find_move_path(space, from, to, move_power = 999, jump_power = 999)
|
5
5
|
raise ArgumentError unless space && space.is_a?(Gingham::Space)
|
6
6
|
raise ArgumentError unless from && from.is_a?(Gingham::Waypoint) && to && to.is_a?(Gingham::Waypoint)
|
7
7
|
|
@@ -15,9 +15,9 @@ module Gingham
|
|
15
15
|
close_list << current_wp
|
16
16
|
open_list = open_list.drop 1
|
17
17
|
|
18
|
-
adjacent_waypoints = Gingham::PathFinder.find_adjacent_waypoints(space, current_wp)
|
18
|
+
adjacent_waypoints = Gingham::PathFinder.find_adjacent_waypoints(space, current_wp, jump_power)
|
19
19
|
adjacent_waypoints.each do |wp|
|
20
|
-
if wp.sum_cost <
|
20
|
+
if wp.sum_cost < move_power
|
21
21
|
open_list << wp unless close_list.include? wp
|
22
22
|
end
|
23
23
|
end
|
@@ -25,7 +25,7 @@ module Gingham
|
|
25
25
|
end
|
26
26
|
|
27
27
|
shortest_chains = [from]
|
28
|
-
end_points = close_list.select{ |closed| closed.cell == to.cell }
|
28
|
+
end_points = close_list.select { |closed| closed.cell == to.cell }
|
29
29
|
|
30
30
|
unless end_points.size.zero?
|
31
31
|
shortest_cost = 999
|
@@ -39,56 +39,41 @@ module Gingham
|
|
39
39
|
shortest_chains
|
40
40
|
end
|
41
41
|
|
42
|
-
def find_skill_path(space, from, to, max_height =
|
42
|
+
def find_skill_path(space, from, to, max_height = 999)
|
43
43
|
path = [from]
|
44
|
-
last_wp = path.last
|
45
44
|
should_move_y = from.direction == Gingham::Direction::D8 || from.direction == Gingham::Direction::D2
|
46
45
|
|
47
46
|
loop_limit = 0
|
48
|
-
while
|
47
|
+
while path.last.cell.x != to.cell.x || path.last.cell.y != to.cell.y
|
49
48
|
loop_limit += 1
|
50
49
|
break if loop_limit > 30
|
51
50
|
|
52
|
-
if should_move_y &&
|
53
|
-
if
|
54
|
-
if
|
55
|
-
height = space.height_at(
|
56
|
-
cell = space.cells[
|
51
|
+
if should_move_y && path.last.cell.y != to.cell.y
|
52
|
+
if path.last.cell.y < to.cell.y
|
53
|
+
if path.last.cell.y + 1 != space.depth
|
54
|
+
height = space.height_at(path.last.cell.x, path.last.cell.y + 1)
|
55
|
+
cell = space.cells[path.last.cell.x][path.last.cell.y + 1][height]
|
57
56
|
break unless cell.passable?
|
58
57
|
|
59
|
-
if
|
60
|
-
|
61
|
-
wp = Gingham::Waypoint.new(cell, 8, last_wp)
|
62
|
-
path << wp
|
63
|
-
last_wp = wp
|
64
|
-
else
|
65
|
-
tmp = Gingham::Waypoint.new(last_wp.cell, 8, last_wp)
|
66
|
-
path << tmp
|
67
|
-
break if cell.z > max_height
|
68
|
-
tmp = Gingham::Waypoint.new(cell, 8, tmp)
|
69
|
-
path << tmp
|
70
|
-
last_wp = tmp
|
58
|
+
if path.last.direction != 8
|
59
|
+
path << Gingham::Waypoint.new(path.last.cell, 8, path.last)
|
71
60
|
end
|
61
|
+
|
62
|
+
break if cell.z > max_height
|
63
|
+
path << Gingham::Waypoint.new(cell, 8, path.last)
|
72
64
|
end
|
73
|
-
elsif
|
74
|
-
if
|
75
|
-
height = space.height_at(
|
76
|
-
cell = space.cells[
|
65
|
+
elsif path.last.cell.y > to.cell.y
|
66
|
+
if path.last.cell.y - 1 >= 0
|
67
|
+
height = space.height_at(path.last.cell.x, path.last.cell.y - 1)
|
68
|
+
cell = space.cells[path.last.cell.x][path.last.cell.y - 1][height]
|
77
69
|
break unless cell.passable?
|
78
70
|
|
79
|
-
if
|
80
|
-
|
81
|
-
wp = Gingham::Waypoint.new(cell, 2, last_wp)
|
82
|
-
path << wp
|
83
|
-
last_wp = wp
|
84
|
-
else
|
85
|
-
tmp = Gingham::Waypoint.new(last_wp.cell, 2, last_wp)
|
86
|
-
path << tmp
|
87
|
-
break if cell.z > max_height
|
88
|
-
tmp = Gingham::Waypoint.new(cell, 2, tmp)
|
89
|
-
path << tmp
|
90
|
-
last_wp = tmp
|
71
|
+
if path.last.direction != 2
|
72
|
+
path << Gingham::Waypoint.new(path.last.cell, 2, path.last)
|
91
73
|
end
|
74
|
+
|
75
|
+
break if cell.z > max_height
|
76
|
+
path << Gingham::Waypoint.new(cell, 2, path.last)
|
92
77
|
end
|
93
78
|
end
|
94
79
|
should_move_y = false
|
@@ -97,65 +82,49 @@ module Gingham
|
|
97
82
|
should_move_y = false
|
98
83
|
end
|
99
84
|
|
100
|
-
if !should_move_y &&
|
101
|
-
if
|
102
|
-
if
|
103
|
-
height = space.height_at(
|
104
|
-
cell = space.cells[
|
85
|
+
if !should_move_y && path.last.cell.x != to.cell.x
|
86
|
+
if path.last.cell.x < to.cell.x
|
87
|
+
if path.last.cell.x + 1 != space.width
|
88
|
+
height = space.height_at(path.last.cell.x + 1, path.last.cell.y)
|
89
|
+
cell = space.cells[path.last.cell.x + 1][path.last.cell.y][height]
|
105
90
|
break unless cell.passable?
|
106
91
|
|
107
|
-
if
|
108
|
-
|
109
|
-
wp = Gingham::Waypoint.new(cell, 6, last_wp)
|
110
|
-
path << wp
|
111
|
-
last_wp = wp
|
112
|
-
else
|
113
|
-
tmp = Gingham::Waypoint.new(last_wp.cell, 6, last_wp)
|
114
|
-
path << tmp
|
115
|
-
break if cell.z > max_height
|
116
|
-
tmp = Gingham::Waypoint.new(cell, 6, tmp)
|
117
|
-
path << tmp
|
118
|
-
last_wp = tmp
|
92
|
+
if path.last.direction != 6
|
93
|
+
path << Gingham::Waypoint.new(path.last.cell, 6, path.last)
|
119
94
|
end
|
95
|
+
|
96
|
+
break if cell.z > max_height
|
97
|
+
path << Gingham::Waypoint.new(cell, 6, path.last)
|
120
98
|
end
|
121
|
-
elsif
|
122
|
-
if
|
123
|
-
height = space.height_at(
|
124
|
-
cell = space.cells[
|
99
|
+
elsif path.last.cell.x > to.cell.x
|
100
|
+
if path.last.cell.x - 1 >= 0
|
101
|
+
height = space.height_at(path.last.cell.x - 1, path.last.cell.y)
|
102
|
+
cell = space.cells[path.last.cell.x - 1][path.last.cell.y][height]
|
125
103
|
break unless cell.passable?
|
126
104
|
|
127
|
-
if
|
128
|
-
|
129
|
-
wp = Gingham::Waypoint.new(cell, 4, last_wp)
|
130
|
-
path << wp
|
131
|
-
last_wp = wp
|
132
|
-
else
|
133
|
-
tmp = Gingham::Waypoint.new(last_wp.cell, 4, last_wp)
|
134
|
-
path << tmp
|
135
|
-
break if cell.z > max_height
|
136
|
-
tmp = Gingham::Waypoint.new(cell, 4, tmp)
|
137
|
-
path << tmp
|
138
|
-
last_wp = tmp
|
105
|
+
if path.last.direction != 4
|
106
|
+
path << Gingham::Waypoint.new(path.last.cell, 4, path.last)
|
139
107
|
end
|
108
|
+
|
109
|
+
break if cell.z > max_height
|
110
|
+
path << Gingham::Waypoint.new(cell, 4, path.last)
|
140
111
|
end
|
141
112
|
end
|
142
|
-
should_move_y = true
|
143
|
-
next
|
144
|
-
else
|
145
|
-
should_move_y = true
|
146
113
|
end
|
114
|
+
|
115
|
+
should_move_y = true
|
147
116
|
end
|
148
117
|
|
149
118
|
path.compact
|
150
119
|
end
|
151
120
|
end
|
152
121
|
|
153
|
-
def self.find_adjacent_waypoints(space, wp)
|
122
|
+
def self.find_adjacent_waypoints(space, wp, jump_power = 999)
|
154
123
|
raise unless space && space.is_a?(Gingham::Space)
|
155
124
|
raise unless wp && wp.is_a?(Gingham::Waypoint)
|
156
125
|
|
157
126
|
adjacent_list = []
|
158
|
-
adjacent_cells = Gingham::PathFinder.find_adjacent_cells(space, wp.cell)
|
127
|
+
adjacent_cells = Gingham::PathFinder.find_adjacent_cells(space, wp.cell, jump_power)
|
159
128
|
adjacent_cells.each do |cell|
|
160
129
|
move_direction = Gingham::Waypoint.detect_direction(wp, cell)
|
161
130
|
parent = wp
|
@@ -169,7 +138,7 @@ module Gingham
|
|
169
138
|
adjacent_list
|
170
139
|
end
|
171
140
|
|
172
|
-
def self.find_adjacent_cells(space, cell)
|
141
|
+
def self.find_adjacent_cells(space, cell, jump_power = 999)
|
173
142
|
raise unless space && space.is_a?(Gingham::Space)
|
174
143
|
raise unless cell && cell.is_a?(Gingham::Cell)
|
175
144
|
|
@@ -178,23 +147,39 @@ module Gingham
|
|
178
147
|
x, y, z = cell.x, cell.y, cell.z
|
179
148
|
|
180
149
|
if x + 1 < w
|
181
|
-
target_cell = space.
|
182
|
-
|
150
|
+
target_cell = space.ground_at(x + 1, y)
|
151
|
+
if target_cell
|
152
|
+
if !target_cell.occupied? || (z - target_cell.z).abs <= jump_power
|
153
|
+
adjacent_list << target_cell
|
154
|
+
end
|
155
|
+
end
|
183
156
|
end
|
184
157
|
|
185
158
|
if x - 1 >= 0
|
186
|
-
target_cell = space.
|
187
|
-
|
159
|
+
target_cell = space.ground_at(x - 1, y)
|
160
|
+
if target_cell
|
161
|
+
if !target_cell.occupied? || (z - target_cell.z).abs <= jump_power
|
162
|
+
adjacent_list << target_cell
|
163
|
+
end
|
164
|
+
end
|
188
165
|
end
|
189
166
|
|
190
167
|
if y + 1 < d
|
191
|
-
target_cell = space.
|
192
|
-
|
168
|
+
target_cell = space.ground_at(x, y + 1)
|
169
|
+
if target_cell
|
170
|
+
if !target_cell.occupied? || (z - target_cell.z).abs <= jump_power
|
171
|
+
adjacent_list << target_cell
|
172
|
+
end
|
173
|
+
end
|
193
174
|
end
|
194
175
|
|
195
176
|
if y - 1 >= 0
|
196
|
-
target_cell = space.
|
197
|
-
|
177
|
+
target_cell = space.ground_at(x, y - 1)
|
178
|
+
if target_cell
|
179
|
+
if !target_cell.occupied? || (z - target_cell.z).abs <= jump_power
|
180
|
+
adjacent_list << target_cell
|
181
|
+
end
|
182
|
+
end
|
198
183
|
end
|
199
184
|
|
200
185
|
adjacent_list
|
data/lib/gingham/space.rb
CHANGED
data/lib/gingham/version.rb
CHANGED
data/lib/gingham/waypoint.rb
CHANGED
@@ -97,9 +97,6 @@ module Gingham
|
|
97
97
|
@parent ? "#{@parent.cell}/#{@parent.direction}->" + base : base
|
98
98
|
end
|
99
99
|
|
100
|
-
|
101
|
-
base = "#{@cell}/#{@direction}" + ":#{@cost}/#{@sum_cost}"
|
102
|
-
@parent ? "#{@parent.cell}/#{@parent.direction}->" + base : base
|
103
|
-
end
|
100
|
+
alias_method :inspect, :to_s
|
104
101
|
end
|
105
102
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gingham
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cignoir
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -90,6 +90,20 @@ dependencies:
|
|
90
90
|
- - ">="
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: 3.4.0
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: coveralls
|
95
|
+
requirement: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
type: :development
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
93
107
|
description: R.I.P. StruGarden
|
94
108
|
email:
|
95
109
|
- cignoir@gmail.com
|
@@ -141,8 +155,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
155
|
version: '0'
|
142
156
|
requirements: []
|
143
157
|
rubyforge_project:
|
144
|
-
rubygems_version: 2.5.1
|
158
|
+
rubygems_version: 2.4.5.1
|
145
159
|
signing_key:
|
146
160
|
specification_version: 4
|
147
161
|
summary: Implementation of original pathfinding algorythm based on 3d grids.
|
148
162
|
test_files: []
|
163
|
+
has_rdoc:
|