chess_vwong 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/spec/game_spec.rb CHANGED
@@ -1,21 +1,20 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
  module ChessVwong
3
3
  describe Game do
4
-
5
- let (:bob) { Player.new("Bob", "w") }
6
- let (:peter) { Player.new("Peter", "b") }
7
- let (:king) { King.new([0,0], "b") }
4
+ let (:bob) { Player.new('Bob', 'w') }
5
+ let (:peter) { Player.new('Peter', 'b') }
6
+ let (:king) { King.new([0, 0], 'b') }
8
7
  let (:game) { Game.new([bob, peter]) }
9
8
 
10
- context "#switch_players" do
11
- it "will set @current_player to @other_player" do
9
+ context '#switch_players' do
10
+ it 'will set @current_player to @other_player' do
12
11
  current_player = bob
13
12
  other_player = peter
14
13
  game.switch_players
15
14
  expect(game.current_player).to eq peter
16
15
  end
17
-
18
- it "will set @other_player to @current_player" do
16
+
17
+ it 'will set @other_player to @current_player' do
19
18
  current_player = bob
20
19
  other_player = peter
21
20
  game.switch_players
@@ -23,16 +22,15 @@ module ChessVwong
23
22
  end
24
23
  end
25
24
 
26
- context "#game_over" do
27
- it "should return winner if king has just been killed" do
25
+ context '#game_over' do
26
+ it 'should return winner if king has just been killed' do
28
27
  game.current_player.kill_list << king
29
28
  expect(game.game_over).to eq game.current_player
30
29
  end
31
30
 
32
- it "should return false if no King" do
31
+ it 'should return false if no King' do
33
32
  expect(game.game_over).to eq false
34
- end
33
+ end
35
34
  end
36
-
37
35
  end
38
- end
36
+ end
data/spec/king_spec.rb CHANGED
@@ -1,51 +1,47 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  module ChessVwong
4
- describe King do
5
- let (:current_space) { [1,1]}
6
- let (:king) { King.new(current_space,"w")}
7
- context "#initialize" do
8
- it "should return Piece attributes: color" do
9
- expect(king.color).to eq "w"
4
+ describe King do
5
+ let (:current_space) { [1, 1] }
6
+ let (:king) { King.new(current_space, 'w') }
7
+ context '#initialize' do
8
+ it 'should return Piece attributes: color' do
9
+ expect(king.color).to eq 'w'
10
10
  end
11
11
 
12
- it "should return Piece attributes: current_space" do
12
+ it 'should return Piece attributes: current_space' do
13
13
  expect(king.current_space).to eq current_space
14
14
  end
15
15
  end
16
16
 
17
- context "#character" do
18
- it "should return a white king character" do
19
- expect(king.character).to eq "\u{265A}"
17
+ context '#character' do
18
+ it 'should return a white king character' do
19
+ expect(king.character).to eq "\u{2654}"
20
20
  end
21
21
 
22
- it "should return a black king character" do
23
- king_2 = King.new(current_space,"b")
24
- expect(king_2.character).to eq "\u{2654}"
25
- end
26
- end
27
-
28
- context "#generate_neighbours" do
22
+ it 'should return a black king character' do
23
+ king_2 = King.new(current_space, 'b')
24
+ expect(king_2.character).to eq "\u{265A}"
25
+ end
26
+ end
29
27
 
30
- it "should return only 16 neighbour when [1,1]" do
28
+ context '#generate_neighbours' do
29
+ it 'should return only 16 neighbour when [1,1]' do
31
30
  king.generate_neighbours(current_space)
32
31
  expect(king.neighbours.count).to eq 3
33
32
  end
34
33
 
35
- it "should return only 14 neighbour when [8,8]" do
36
- current_space = [8,8]
34
+ it 'should return only 14 neighbour when [8,8]' do
35
+ current_space = [8, 8]
37
36
  king.generate_neighbours(current_space)
38
37
  expect(king.neighbours.count).to eq 3
39
38
  end
40
39
 
41
- it "should return only 14 neighbour when in the middle" do
42
- current_space = [3,3]
40
+ it 'should return only 14 neighbour when in the middle' do
41
+ current_space = [3, 3]
43
42
  king.generate_neighbours(current_space)
44
43
  expect(king.neighbours.count).to eq 8
45
- end
46
-
44
+ end
47
45
  end
48
-
49
-
50
46
  end
51
- end
47
+ end
data/spec/knight_spec.rb CHANGED
@@ -1,73 +1,71 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  module ChessVwong
4
- describe Knight do
5
- let (:current_space) {[1,1]}
6
- let (:knight) { Knight.new(current_space, "w")}
7
- context "#initialize" do
8
- it "should return Piece attributes: color" do
9
- expect(knight.color).to eq "w"
4
+ describe Knight do
5
+ let (:current_space) { [1, 1] }
6
+ let (:knight) { Knight.new(current_space, 'w') }
7
+ context '#initialize' do
8
+ it 'should return Piece attributes: color' do
9
+ expect(knight.color).to eq 'w'
10
10
  end
11
11
 
12
- it "should return Piece attributes: current_space" do
12
+ it 'should return Piece attributes: current_space' do
13
13
  expect(knight.current_space).to eq current_space
14
14
  end
15
15
  end
16
16
 
17
- context "#character" do
18
- it "should return a white knight character" do
19
- expect(knight.character).to eq "\u{265E}"
17
+ context '#character' do
18
+ it 'should return a white knight character' do
19
+ expect(knight.character).to eq "\u{2658}"
20
20
  end
21
21
 
22
- it "should return a black knight character" do
23
- knight_2 = Knight.new(current_space,"b")
24
- expect(knight_2.character).to eq "\u{2658}"
25
- end
26
- end
22
+ it 'should return a black knight character' do
23
+ knight_2 = Knight.new(current_space, 'b')
24
+ expect(knight_2.character).to eq "\u{265E}"
25
+ end
26
+ end
27
27
 
28
- context "#generate_neighbours" do
29
- it "should return only 2 neighbour when [1,1]" do
28
+ context '#generate_neighbours' do
29
+ it 'should return only 2 neighbour when [1,1]' do
30
30
  knight.generate_neighbours(current_space)
31
31
  expect(knight.neighbours.count).to eq 2
32
32
  end
33
33
 
34
- it "should return only 2 neighbour when [7,7]" do
35
- current_space = [8,8]
34
+ it 'should return only 2 neighbour when [7,7]' do
35
+ current_space = [8, 8]
36
36
  knight.generate_neighbours(current_space)
37
37
  expect(knight.neighbours.count).to eq 2
38
38
  end
39
39
 
40
- it "should return only 4 neighbour when on left edge" do
41
- current_space = [1,4]
40
+ it 'should return only 4 neighbour when on left edge' do
41
+ current_space = [1, 4]
42
42
  knight.generate_neighbours(current_space)
43
43
  expect(knight.neighbours.count).to eq 4
44
44
  end
45
45
 
46
- it "should return only 4 neighbour when on right edge" do
47
- current_space = [8,4]
46
+ it 'should return only 4 neighbour when on right edge' do
47
+ current_space = [8, 4]
48
48
  knight.generate_neighbours(current_space)
49
49
  expect(knight.neighbours.count).to eq 4
50
50
  end
51
51
 
52
- it "should return only 4 neighbour when on top edge" do
53
- current_space = [4,1]
52
+ it 'should return only 4 neighbour when on top edge' do
53
+ current_space = [4, 1]
54
54
  knight.generate_neighbours(current_space)
55
55
  expect(knight.neighbours.count).to eq 4
56
56
  end
57
57
 
58
- it "should return only 4 neighbour when on right edge" do
59
- current_space = [4,8]
58
+ it 'should return only 4 neighbour when on right edge' do
59
+ current_space = [4, 8]
60
60
  knight.generate_neighbours(current_space)
61
61
  expect(knight.neighbours.count).to eq 4
62
62
  end
63
63
 
64
- it "should return 8 neighbour when in middle" do
65
- current_space = [4,4]
64
+ it 'should return 8 neighbour when in middle' do
65
+ current_space = [4, 4]
66
66
  knight.generate_neighbours(current_space)
67
67
  expect(knight.neighbours.count).to eq 8
68
68
  end
69
69
  end
70
-
71
-
72
70
  end
73
- end
71
+ end
data/spec/node_spec.rb CHANGED
@@ -1,24 +1,23 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  module ChessVwong
4
- describe Node do
5
- let (:node) { Node.new}
6
- let (:knight) { Knight.new(node, "w")}
4
+ describe Node do
5
+ let (:node) { Node.new }
6
+ let (:knight) { Knight.new(node, 'w') }
7
7
 
8
- context "#intialize" do
8
+ context '#intialize' do
9
9
  # it "is initialized with x,y coordinates for its value" do
10
10
  # expect(node.value).to eq [0,0]
11
11
  # end
12
12
 
13
- it "defaults to unoccupied" do
13
+ it 'defaults to unoccupied' do
14
14
  expect(node.occupied).to eq []
15
- end
15
+ end
16
16
 
17
- it "can accept pieces as occupants" do
17
+ it 'can accept pieces as occupants' do
18
18
  node.occupied << knight
19
19
  expect(node.occupied).to eq [knight]
20
- end
20
+ end
21
21
  end
22
-
23
22
  end
24
- end
23
+ end
data/spec/pawn_spec.rb CHANGED
@@ -1,112 +1,110 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  module ChessVwong
4
- describe Pawn do
5
- let (:current_space) { [1,1]}
6
- let (:board) { Board.new}
7
- let (:node) { Node.new}
8
- let (:pawn) { Pawn.new(current_space,"w")}
9
- let (:pawn_2) { Pawn.new(current_space,"b")}
10
- context "#initialize" do
11
- it "should return Piece attributes: color" do
12
- expect(pawn.color).to eq "w"
4
+ describe Pawn do
5
+ let (:current_space) { [1, 1] }
6
+ let (:board) { Board.new }
7
+ let (:node) { Node.new }
8
+ let (:pawn) { Pawn.new(current_space, 'w') }
9
+ let (:pawn_2) { Pawn.new(current_space, 'b') }
10
+ context '#initialize' do
11
+ it 'should return Piece attributes: color' do
12
+ expect(pawn.color).to eq 'w'
13
13
  end
14
14
 
15
- it "should return Piece attributes: current_space" do
15
+ it 'should return Piece attributes: current_space' do
16
16
  expect(pawn.current_space).to eq current_space
17
17
  end
18
18
  end
19
19
 
20
- context "#character" do
21
- it "should return a white pawn character" do
22
- expect(pawn.character).to eq "\u{265F}"
20
+ context '#character' do
21
+ it 'should return a white pawn character' do
22
+ expect(pawn.character).to eq "\u{2659}"
23
23
  end
24
24
 
25
- it "should return a black pawn character" do
26
- expect(pawn_2.character).to eq "\u{2659}"
27
- end
28
- end
25
+ it 'should return a black pawn character' do
26
+ expect(pawn_2.character).to eq "\u{265F}"
27
+ end
28
+ end
29
29
 
30
- context "#generate_neighbours" do
31
- it "should return only 0 neighbour when [1,1] and White" do
30
+ context '#generate_neighbours' do
31
+ it 'should return only 0 neighbour when [1,1] and White' do
32
32
  pawn.generate_neighbours(current_space, node, node)
33
33
  expect(pawn.neighbours.count).to eq 0
34
34
  end
35
35
 
36
- it "should return only 4 neighbours if First move and white" do
37
- current_space = [7,7]
36
+ it 'should return only 4 neighbours if First move and white' do
37
+ current_space = [7, 7]
38
38
  pawn.generate_neighbours(current_space, node, node)
39
39
  expect(pawn.neighbours.count).to eq 2
40
40
  end
41
41
 
42
- it "should return 4 moves if First move and Black" do
43
- current_space = [2,2]
42
+ it 'should return 4 moves if First move and Black' do
43
+ current_space = [2, 2]
44
44
  pawn.generate_neighbours(current_space, node, node)
45
45
  pawn_2.generate_neighbours(current_space, node, node)
46
46
  expect(pawn_2.neighbours.count).to eq 2
47
47
  end
48
48
 
49
- it "should return only 2 neighbour when [8,8] and Black" do
50
- current_space = [8,8]
49
+ it 'should return only 2 neighbour when [8,8] and Black' do
50
+ current_space = [8, 8]
51
51
  pawn_2.generate_neighbours(current_space, node, node)
52
52
  expect(pawn_2.neighbours.count).to eq 0
53
53
  end
54
54
 
55
- it "should return only 3 neighbour when in the middle" do
56
- current_space = [3,3]
55
+ it 'should return only 3 neighbour when in the middle' do
56
+ current_space = [3, 3]
57
57
  pawn.generate_neighbours(current_space, node, node)
58
58
  expect(pawn.neighbours.count).to eq 1
59
- end
59
+ end
60
60
  end
61
61
 
62
- context "kill_move" do
63
- it "should return Kill Moves for Black Pawn" do
64
- current_space = [2,2]
62
+ context 'kill_move' do
63
+ it 'should return Kill Moves for Black Pawn' do
64
+ current_space = [2, 2]
65
65
  enemy_node1 = board.grid[3][3]
66
66
  enemy_node1.occupied << pawn
67
67
  enemy_node2 = board.grid[3][1]
68
68
  enemy_node2.occupied << pawn
69
- expect(pawn_2.generate_neighbours(current_space, enemy_node1, enemy_node2).count).to eq 4
69
+ expect(pawn_2.generate_neighbours(current_space, enemy_node1, enemy_node2).count).to eq 4
70
70
  end
71
71
 
72
- it "should not return Kill Moves for Black Pawn if empty" do
73
- current_space = [2,2]
74
- expect(pawn_2.generate_neighbours(current_space, node, node).count).to eq 2
75
- end
72
+ it 'should not return Kill Moves for Black Pawn if empty' do
73
+ current_space = [2, 2]
74
+ expect(pawn_2.generate_neighbours(current_space, node, node).count).to eq 2
75
+ end
76
76
 
77
- it "should not return Kill Moves for Black Pawn if blocked by same color" do
78
- current_space = [2,2]
77
+ it 'should not return Kill Moves for Black Pawn if blocked by same color' do
78
+ current_space = [2, 2]
79
79
  enemy_node1 = board.grid[3][3]
80
80
  enemy_node1.occupied << pawn_2
81
81
  enemy_node2 = board.grid[3][1]
82
82
  enemy_node2.occupied << pawn_2
83
- expect(pawn_2.generate_neighbours(current_space, enemy_node1, enemy_node2).count).to eq 2
84
- end
83
+ expect(pawn_2.generate_neighbours(current_space, enemy_node1, enemy_node2).count).to eq 2
84
+ end
85
85
 
86
- it "should return Kill Moves for White Pawn" do
87
- current_space = [7,7]
86
+ it 'should return Kill Moves for White Pawn' do
87
+ current_space = [7, 7]
88
88
  enemy_node1 = board.grid[6][6]
89
89
  enemy_node1.occupied << pawn_2
90
90
  enemy_node2 = board.grid[6][8]
91
91
  enemy_node2.occupied << pawn_2
92
- expect(pawn.generate_neighbours(current_space, enemy_node1, enemy_node2).count).to eq 4
93
- end
94
-
95
- it "should not return Kill Moves for White Pawn if empty" do
96
- current_space = [7,7]
97
- expect(pawn.generate_neighbours(current_space, node, node).count).to eq 2
92
+ expect(pawn.generate_neighbours(current_space, enemy_node1, enemy_node2).count).to eq 4
93
+ end
98
94
 
99
- end
95
+ it 'should not return Kill Moves for White Pawn if empty' do
96
+ current_space = [7, 7]
97
+ expect(pawn.generate_neighbours(current_space, node, node).count).to eq 2
98
+ end
100
99
 
101
- it "should not return Kill Moves for White Pawn if blocked by same color" do
102
- current_space = [7,7]
100
+ it 'should not return Kill Moves for White Pawn if blocked by same color' do
101
+ current_space = [7, 7]
103
102
  enemy_node1 = board.grid[6][6]
104
103
  enemy_node1.occupied << pawn
105
104
  enemy_node2 = board.grid[6][8]
106
105
  enemy_node2.occupied << pawn
107
- expect(pawn.generate_neighbours(current_space, enemy_node1, enemy_node2).count).to eq 2
108
- end
106
+ expect(pawn.generate_neighbours(current_space, enemy_node1, enemy_node2).count).to eq 2
107
+ end
109
108
  end
110
-
111
109
  end
112
- end
110
+ end
data/spec/piece_spec.rb CHANGED
@@ -1,53 +1,53 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  module ChessVwong
4
- describe Piece do
5
- let (:current_space) {[1,1]}
6
- let (:piece) { Piece.new(current_space, "w")}
4
+ describe Piece do
5
+ let (:current_space) { [1, 1] }
6
+ let (:piece) { Piece.new(current_space, 'w') }
7
7
 
8
- context "#initialize" do
9
- it "should initialize with current_space" do
8
+ context '#initialize' do
9
+ it 'should initialize with current_space' do
10
10
  expect(piece.current_space).to eq current_space
11
11
  end
12
12
 
13
- it "should initialize with current_space" do
14
- expect(piece.color).to eq "w"
13
+ it 'should initialize with current_space' do
14
+ expect(piece.color).to eq 'w'
15
15
  end
16
16
  end
17
17
 
18
- context "#neighbours" do
19
- it "should contain neighouring spaces" do
20
- neighouring_space = [4,4]
18
+ context '#neighbours' do
19
+ it 'should contain neighouring spaces' do
20
+ neighouring_space = [4, 4]
21
21
  piece.neighbours << neighouring_space
22
- expect(piece.neighbours).to eq [[4,4]]
22
+ expect(piece.neighbours).to eq [[4, 4]]
23
23
  end
24
24
  end
25
25
 
26
- context "#valid_space?" do
27
- it "should return true if valid" do
28
- valid_space = [5,5]
26
+ context '#valid_space?' do
27
+ it 'should return true if valid' do
28
+ valid_space = [5, 5]
29
29
  expect(piece.valid_space?(valid_space)).to eq true
30
30
  end
31
31
 
32
- it "should return nil if x < 0" do
32
+ it 'should return nil if x < 0' do
33
33
  invalid_space = [-1, 5]
34
34
  expect(piece.valid_space?(invalid_space)).to eq nil
35
35
  end
36
36
 
37
- it "should return nil if x > 9" do
38
- invalid_space = [9,5]
37
+ it 'should return nil if x > 9' do
38
+ invalid_space = [9, 5]
39
39
  expect(piece.valid_space?(invalid_space)).to eq nil
40
40
  end
41
41
 
42
- it "should return nil if y < 0" do
43
- invalid_space = [5,-1]
42
+ it 'should return nil if y < 0' do
43
+ invalid_space = [5, -1]
44
44
  expect(piece.valid_space?(invalid_space)).to eq nil
45
45
  end
46
46
 
47
- it "should return nil if y > 9" do
48
- invalid_space = [5,9]
47
+ it 'should return nil if y > 9' do
48
+ invalid_space = [5, 9]
49
49
  expect(piece.valid_space?(invalid_space)).to eq nil
50
50
  end
51
51
  end
52
52
  end
53
- end
53
+ end