game_board 0.0.1 → 0.0.2

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.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .pairs
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ## GameBoard
2
2
 
3
+ Authors: [MrPowers](https://github.com/MrPowers), [sandbochs](https://github.com/sandbochs)
4
+
3
5
  This class helps calculate the rows, columns, diagonals, and diagonals of a coordinate for nested array data structures. It is useful for games like Tic-Tac-Toe, Connect Four, Battleship, etc.
4
6
 
5
7
  ## Getting Started
@@ -59,4 +61,11 @@ Get all rows or columns:
59
61
  ```ruby
60
62
  board.rows
61
63
  board.columns
64
+ ```
65
+
66
+ Print the board to console:
67
+
68
+ ```ruby
69
+ # Returns a string: "[1, 2, 3]\n[4, 5, 6]\n[7, 8, 9]\n[10, 11, 12]"
70
+ puts board.to_s
62
71
  ```
@@ -74,8 +74,8 @@ class GameBoard
74
74
  end
75
75
 
76
76
  def down_right_diagonals(grid_array)
77
- number_of_rows.times.map { |row_index| down_right_diagonal(row_index, 0, grid_array) } +
78
- number_of_columns.times.map { |column_index| down_right_diagonal(1, column_index, grid_array)}
77
+ number_of_rows.times.map { |row_index| down_right_diagonal(row_index, 0, grid_array) }.reverse +
78
+ (1..number_of_columns - 1).map { |column_index| down_right_diagonal(0, column_index, grid_array)}
79
79
  end
80
80
 
81
81
  def grid_reflected_about_y_axis
@@ -85,5 +85,4 @@ class GameBoard
85
85
  def grid_reflected_about_x_axis
86
86
  grid.reverse
87
87
  end
88
-
89
- end
88
+ end
@@ -1,3 +1,3 @@
1
1
  class GameBoard
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -12,51 +12,93 @@ describe GameBoard do
12
12
  end
13
13
 
14
14
  context "#set_grid" do
15
+
15
16
  it "sets a new grid for the game board" do
16
17
  new_grid = [[1, 1, 1],[2, 2, 2],[3, 3, 3],[4, 4, 4]]
17
18
  expect { board.set_grid(new_grid) }.to change { board.grid }.from([[1, 2, 3],[4, 5, 6], [7, 8, 9], [10, 11, 12]]).to([[1, 1, 1],[2, 2, 2],[3, 3, 3],[4, 4, 4]])
18
19
  end
20
+
19
21
  end
20
22
 
21
23
  context "#get_cell" do
24
+
22
25
  it { board.get_cell(0, 2).should eq 3 }
26
+
23
27
  end
24
28
 
25
29
  context "#set_cell" do
30
+
26
31
  it "sets a cell at a coordinate" do
27
32
  expect { board.set_cell(1, 1, "BOB")}.to change { board.get_cell(1, 1) }.from(5).to("BOB")
28
33
  end
34
+
29
35
  end
30
36
 
31
37
  context '#row' do
38
+
32
39
  it { board.row(1).should eq [4, 5, 6] }
40
+
33
41
  end
34
42
 
35
43
  context '#rows' do
44
+
36
45
  it { board.rows.should eq [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] }
46
+
37
47
  end
38
48
 
39
49
  context '#column' do
50
+
40
51
  it { board.column(2).should eq [3, 6, 9, 12] }
52
+
41
53
  end
42
54
 
43
55
  context '#columns' do
56
+
44
57
  it "calculate all columns" do
45
58
  board.columns === ([[1, 2, 7, 10], [2, 5, 8, 11], [3, 6, 9, 12]])
46
59
  end
60
+
47
61
  end
48
62
 
49
63
  context "#coordinate_diagonals" do
64
+
50
65
  it { board.coordinate_diagonals(0, 0).should eq [[1, 5, 9], [1]] }
51
66
  it { board.coordinate_diagonals(1, 1).should eq [[1, 5, 9], [3, 5, 7]] }
52
- it { board.coordinate_diagonals(2, 2).should eq [[1, 5, 9], [9, 11]] }
67
+ it { board.coordinate_diagonals(2, 2).should eq [[1, 5, 9], [9, 11]] }
68
+ it { board.coordinate_diagonals(1, 0).should eq [[4, 8, 12], [2, 4]] }
69
+ it { board.coordinate_diagonals(2, 0).should eq [[7, 11], [3, 5, 7]] }
70
+ it { board.coordinate_diagonals(3, 0).should eq [[10], [6, 8 , 10]] }
71
+ it { board.coordinate_diagonals(0, 1).should eq [[2, 6], [2, 4]] }
72
+ it { board.coordinate_diagonals(0, 2).should eq [[3], [3, 5, 7]] }
73
+
53
74
  end
54
75
 
55
76
  context '#diagonals' do
77
+
56
78
  it 'calculates all diagonals' do
57
- board.diagonals === [[10], [7, 11], [4, 8, 12], [1, 5, 9], [2, 6], [3],
79
+ board.diagonals == [[10], [7, 11], [4, 8, 12], [1, 5, 9], [2, 6], [3],
58
80
  [1], [4, 2], [7, 5, 3], [10, 8, 6], [11, 9], [12]]
59
81
  end
82
+
83
+
84
+
85
+ it "calculates all diagonals" do
86
+ board2 = GameBoard.new(2, 4)
87
+ board2.set_grid([[1, 2, 3, 4],
88
+ [5, 6, 7, 8]])
89
+
90
+ board2.diagonals == [[5], [1, 6], [2, 7], [3, 8], [4],
91
+ [1], [5, 2], [6, 3], [7, 4], [8]]
92
+ end
93
+
94
+ end
95
+
96
+ context '#to_s' do
97
+
98
+ it "prints the board properly" do
99
+ board.to_s.should eq "[1, 2, 3]\n[4, 5, 6]\n[7, 8, 9]\n[10, 11, 12]"
100
+ end
101
+
60
102
  end
61
103
 
62
104
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: game_board
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-11-08 00:00:00.000000000 Z
13
+ date: 2012-12-04 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: This is a GameBoard class with methods to help analyze the grid.
16
16
  email: