gameboard 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gameboard/board.rb +26 -2
- data/lib/gameboard/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: 7a3e533fd420dc06eccaed5652ed1cdee4124a92
|
4
|
+
data.tar.gz: 44990056f6c175c4ba2bbf3a5c854034855dcd46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 260e45aa189cb9cf5e52e0541312382bc6cce88d57a145951cb1b82fdb09326143ce633ac6f39a3264573606d1238264a1d4b01efbcbdeed2e83b019a07f1e2d
|
7
|
+
data.tar.gz: 454d61ce7ce5b8ba97d05357a08f719d7e90c0b2b6c1caec0712759986b1332f3e4e97d860eb98274e486855dcd9af12167fe767640261ce08ef0e7ea04d1b1c
|
data/lib/gameboard/board.rb
CHANGED
@@ -33,8 +33,7 @@ module Gameboard
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def find_cell(coord)
|
36
|
-
@board.find {|cell|
|
37
|
-
cell.coord.position == coord}
|
36
|
+
@board.find {|cell| cell.coord.position == coord}
|
38
37
|
end
|
39
38
|
|
40
39
|
def horizontal(coords = false)
|
@@ -57,6 +56,21 @@ module Gameboard
|
|
57
56
|
columns
|
58
57
|
end
|
59
58
|
|
59
|
+
def diagonal(coords = false)
|
60
|
+
diagonals = []
|
61
|
+
|
62
|
+
height.times do |i|
|
63
|
+
diagonals << get_diagonal([0, i], coords)
|
64
|
+
diagonals << get_diagonal([0, height - 1 - i], coords, false)
|
65
|
+
end
|
66
|
+
(1...width).each do
|
67
|
+
|i| diagonals << get_diagonal([i, 0], coords)
|
68
|
+
diagonals << get_diagonal([i, height - 1], coords, false)
|
69
|
+
end
|
70
|
+
|
71
|
+
diagonals
|
72
|
+
end
|
73
|
+
|
60
74
|
def full?
|
61
75
|
@board.none? { |cell| cell.value == cells }
|
62
76
|
end
|
@@ -64,5 +78,15 @@ module Gameboard
|
|
64
78
|
private
|
65
79
|
attr_reader :cells
|
66
80
|
|
81
|
+
def get_diagonal(start, coords, slope = true)
|
82
|
+
oper = (slope == true ? :+ : :-)
|
83
|
+
diagonal = (0...height).map do |i|
|
84
|
+
position = [start[0] + i, start[1].send(oper, i)]
|
85
|
+
if ((0...width).include?(start[0] + i) && (0...height).include?(start[1].send(oper, i)))
|
86
|
+
board.find {|cell| cell.coord.position == position}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
diagonal.compact.map{|cell| coords ? cell.coord.position : cell.value }
|
90
|
+
end
|
67
91
|
end
|
68
92
|
end
|
data/lib/gameboard/version.rb
CHANGED