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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20d26deb08d61a42eb83cfa3a26f55c0c879926a
4
- data.tar.gz: 5aea778474abd40447b8b858429c058e125b59a4
3
+ metadata.gz: 7a3e533fd420dc06eccaed5652ed1cdee4124a92
4
+ data.tar.gz: 44990056f6c175c4ba2bbf3a5c854034855dcd46
5
5
  SHA512:
6
- metadata.gz: b6d249421f0f528db58637fcee1f9d96e2f790e8ad97bc1cdf7107d8a851845a3787ed3c13dc4fff2632fbd76e54bad726aeb36864b855f12e9b8851768b3f56
7
- data.tar.gz: a59ade6b5717365f5fe0ea611e3fdab700863e1d7e939e02e46560622b41205499312708228929936d394258e7d00cbe44e7d4a393a9d222a76e2e7f48993f00
6
+ metadata.gz: 260e45aa189cb9cf5e52e0541312382bc6cce88d57a145951cb1b82fdb09326143ce633ac6f39a3264573606d1238264a1d4b01efbcbdeed2e83b019a07f1e2d
7
+ data.tar.gz: 454d61ce7ce5b8ba97d05357a08f719d7e90c0b2b6c1caec0712759986b1332f3e4e97d860eb98274e486855dcd9af12167fe767640261ce08ef0e7ea04d1b1c
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Gameboard
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gameboard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sampson Crowley