gobgems 0.0.2 → 0.0.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.
- checksums.yaml +4 -4
- data/lib/gobgems/board.rb +8 -4
- data/lib/gobgems/direction.rb +4 -4
- data/lib/gobgems/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 239ff963fa7c0bd9fa484a94b351b83248bac407
|
|
4
|
+
data.tar.gz: a158c751e9a4230b472b44c9b3a84a00815e65bc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2d078d15dc86ab72359f817fe704247515576ae656d2c0211fe5e223f4b26b4a37aaed0ed28128a8ef7b3c7ef441619fe9777287c291ef4df282883941b4576e
|
|
7
|
+
data.tar.gz: 9b653a1a342f2e61a4634b1f57ff7454b7bceb85c36186ce1a924a4e64470e851695f8f358660970181f9a4582bdc7fa02e19e2706034fb2300da14762ac3068
|
data/lib/gobgems/board.rb
CHANGED
|
@@ -11,6 +11,10 @@ module Gobgems
|
|
|
11
11
|
__move_to__ next_position(direction)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
+
def move_to_edge(direction)
|
|
15
|
+
move(direction) while can_move?(direction)
|
|
16
|
+
end
|
|
17
|
+
|
|
14
18
|
def __move_to__(position)
|
|
15
19
|
raise OutOfBoardError unless within_bounds? position
|
|
16
20
|
@head_position = position
|
|
@@ -55,7 +59,7 @@ module Gobgems
|
|
|
55
59
|
end
|
|
56
60
|
|
|
57
61
|
def size
|
|
58
|
-
[cells.size, cells
|
|
62
|
+
[cells[0].size, cells.size]
|
|
59
63
|
end
|
|
60
64
|
|
|
61
65
|
def ==(other)
|
|
@@ -69,7 +73,7 @@ module Gobgems
|
|
|
69
73
|
end
|
|
70
74
|
|
|
71
75
|
def self.empty(x, y, position=[0, 0])
|
|
72
|
-
self.new((1..
|
|
76
|
+
self.new((1..y).map { (1..x).map { empty_cell } }, position)
|
|
73
77
|
end
|
|
74
78
|
|
|
75
79
|
def self.from(cells, position=[0, 0])
|
|
@@ -82,7 +86,7 @@ module Gobgems
|
|
|
82
86
|
|
|
83
87
|
def __cell_at__(position)
|
|
84
88
|
raise OutOfBoardError unless within_bounds? position
|
|
85
|
-
cells[position[
|
|
89
|
+
cells[-(position[1]+1)][position[0]]
|
|
86
90
|
end
|
|
87
91
|
|
|
88
92
|
private
|
|
@@ -90,7 +94,7 @@ module Gobgems
|
|
|
90
94
|
def within_bounds?(position)
|
|
91
95
|
(x, y) = size
|
|
92
96
|
position[0] >= 0 && position[1] >= 0 &&
|
|
93
|
-
position[0]
|
|
97
|
+
position[0] < x && position[1] < y
|
|
94
98
|
end
|
|
95
99
|
|
|
96
100
|
def head_cell
|
data/lib/gobgems/direction.rb
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
module Gobgems
|
|
2
2
|
module Direction
|
|
3
3
|
def east
|
|
4
|
-
@east ||= -> (x, y) { [x, y
|
|
4
|
+
@east ||= -> (x, y) { [x+1, y] }
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
def west
|
|
8
|
-
@west ||= -> (x, y) { [x, y
|
|
8
|
+
@west ||= -> (x, y) { [x-1, y] }
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def north
|
|
12
|
-
@north ||= -> (x, y) { [x
|
|
12
|
+
@north ||= -> (x, y) { [x, y+1] }
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def south
|
|
16
|
-
@south ||= -> (x, y) { [x
|
|
16
|
+
@south ||= -> (x, y) { [x, y-1] }
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def all
|
data/lib/gobgems/version.rb
CHANGED