gobgems 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38dc483246de3b289186d9341b762dce713d92d2
4
- data.tar.gz: 20897b5b070ec488b7ba5307badfb6e279fc1f41
3
+ metadata.gz: 239ff963fa7c0bd9fa484a94b351b83248bac407
4
+ data.tar.gz: a158c751e9a4230b472b44c9b3a84a00815e65bc
5
5
  SHA512:
6
- metadata.gz: bfb5ffdf7a27e13bb6746a95a5de74185f2e3f8c1236d1bc6b7c6a6347da155e43f894fc11602f0ef132e9ff65a9bb3589d710df8a297fd47d82db40902eea8e
7
- data.tar.gz: 668e8ca386c57d1824156e29074b4811e0c27866a91800ecbd1deafa6b135077bf025e529b69289a01006c1bdc1b7a5d74601c57ff3b3a7fafdde33149e8a447
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[0].size]
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..x).map { (1..y).map { empty_cell } }, position)
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[0]][position[1]]
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] <= x && position[1] <= y
97
+ position[0] < x && position[1] < y
94
98
  end
95
99
 
96
100
  def head_cell
@@ -1,19 +1,19 @@
1
1
  module Gobgems
2
2
  module Direction
3
3
  def east
4
- @east ||= -> (x, y) { [x, y+1] }
4
+ @east ||= -> (x, y) { [x+1, y] }
5
5
  end
6
6
 
7
7
  def west
8
- @west ||= -> (x, y) { [x, y-1] }
8
+ @west ||= -> (x, y) { [x-1, y] }
9
9
  end
10
10
 
11
11
  def north
12
- @north ||= -> (x, y) { [x-1, y] }
12
+ @north ||= -> (x, y) { [x, y+1] }
13
13
  end
14
14
 
15
15
  def south
16
- @south ||= -> (x, y) { [x+1, y] }
16
+ @south ||= -> (x, y) { [x, y-1] }
17
17
  end
18
18
 
19
19
  def all
@@ -1,3 +1,3 @@
1
1
  module Gobgems
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gobgems
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Federico Aloi