chess_vwong 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +4 -0
- data/bin/chess_vwong +21 -0
- data/chess_vwong.gemspec +24 -0
- data/example/example_game.rb +20 -0
- data/lib/chess_vwong/bishop.rb +22 -0
- data/lib/chess_vwong/board.rb +207 -0
- data/lib/chess_vwong/game.rb +73 -0
- data/lib/chess_vwong/king.rb +17 -0
- data/lib/chess_vwong/knight.rb +17 -0
- data/lib/chess_vwong/node.rb +9 -0
- data/lib/chess_vwong/pawn.rb +44 -0
- data/lib/chess_vwong/piece.rb +34 -0
- data/lib/chess_vwong/player.rb +12 -0
- data/lib/chess_vwong/preload.rb +65 -0
- data/lib/chess_vwong/queen.rb +28 -0
- data/lib/chess_vwong/rook.rb +22 -0
- data/lib/chess_vwong/version.rb +3 -0
- data/lib/chess_vwong.rb +23 -0
- data/spec/bishop_spec.rb +50 -0
- data/spec/board_spec.rb +293 -0
- data/spec/game_spec.rb +38 -0
- data/spec/king_spec.rb +51 -0
- data/spec/knight_spec.rb +73 -0
- data/spec/node_spec.rb +24 -0
- data/spec/pawn_spec.rb +112 -0
- data/spec/piece_spec.rb +53 -0
- data/spec/player_spec.rb +21 -0
- data/spec/queen_spec.rb +50 -0
- data/spec/rook_spec.rb +50 -0
- data/spec/spec_helper.rb +1 -0
- metadata +133 -0
data/spec/pawn_spec.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
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"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return Piece attributes: current_space" do
|
16
|
+
expect(pawn.current_space).to eq current_space
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "#character" do
|
21
|
+
it "should return a white pawn character" do
|
22
|
+
expect(pawn.character).to eq "\u{265F}"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return a black pawn character" do
|
26
|
+
expect(pawn_2.character).to eq "\u{2659}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "#generate_neighbours" do
|
31
|
+
it "should return only 0 neighbour when [1,1] and White" do
|
32
|
+
pawn.generate_neighbours(current_space, node, node)
|
33
|
+
expect(pawn.neighbours.count).to eq 0
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return only 4 neighbours if First move and white" do
|
37
|
+
current_space = [7,7]
|
38
|
+
pawn.generate_neighbours(current_space, node, node)
|
39
|
+
expect(pawn.neighbours.count).to eq 2
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return 4 moves if First move and Black" do
|
43
|
+
current_space = [2,2]
|
44
|
+
pawn.generate_neighbours(current_space, node, node)
|
45
|
+
pawn_2.generate_neighbours(current_space, node, node)
|
46
|
+
expect(pawn_2.neighbours.count).to eq 2
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should return only 2 neighbour when [8,8] and Black" do
|
50
|
+
current_space = [8,8]
|
51
|
+
pawn_2.generate_neighbours(current_space, node, node)
|
52
|
+
expect(pawn_2.neighbours.count).to eq 0
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return only 3 neighbour when in the middle" do
|
56
|
+
current_space = [3,3]
|
57
|
+
pawn.generate_neighbours(current_space, node, node)
|
58
|
+
expect(pawn.neighbours.count).to eq 1
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "kill_move" do
|
63
|
+
it "should return Kill Moves for Black Pawn" do
|
64
|
+
current_space = [2,2]
|
65
|
+
enemy_node1 = board.grid[3][3]
|
66
|
+
enemy_node1.occupied << pawn
|
67
|
+
enemy_node2 = board.grid[3][1]
|
68
|
+
enemy_node2.occupied << pawn
|
69
|
+
expect(pawn_2.generate_neighbours(current_space, enemy_node1, enemy_node2).count).to eq 4
|
70
|
+
end
|
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
|
76
|
+
|
77
|
+
it "should not return Kill Moves for Black Pawn if blocked by same color" do
|
78
|
+
current_space = [2,2]
|
79
|
+
enemy_node1 = board.grid[3][3]
|
80
|
+
enemy_node1.occupied << pawn_2
|
81
|
+
enemy_node2 = board.grid[3][1]
|
82
|
+
enemy_node2.occupied << pawn_2
|
83
|
+
expect(pawn_2.generate_neighbours(current_space, enemy_node1, enemy_node2).count).to eq 2
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should return Kill Moves for White Pawn" do
|
87
|
+
current_space = [7,7]
|
88
|
+
enemy_node1 = board.grid[6][6]
|
89
|
+
enemy_node1.occupied << pawn_2
|
90
|
+
enemy_node2 = board.grid[6][8]
|
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
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should not return Kill Moves for White Pawn if blocked by same color" do
|
102
|
+
current_space = [7,7]
|
103
|
+
enemy_node1 = board.grid[6][6]
|
104
|
+
enemy_node1.occupied << pawn
|
105
|
+
enemy_node2 = board.grid[6][8]
|
106
|
+
enemy_node2.occupied << pawn
|
107
|
+
expect(pawn.generate_neighbours(current_space, enemy_node1, enemy_node2).count).to eq 2
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
data/spec/piece_spec.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module ChessVwong
|
4
|
+
describe Piece do
|
5
|
+
let (:current_space) {[1,1]}
|
6
|
+
let (:piece) { Piece.new(current_space, "w")}
|
7
|
+
|
8
|
+
context "#initialize" do
|
9
|
+
it "should initialize with current_space" do
|
10
|
+
expect(piece.current_space).to eq current_space
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should initialize with current_space" do
|
14
|
+
expect(piece.color).to eq "w"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "#neighbours" do
|
19
|
+
it "should contain neighouring spaces" do
|
20
|
+
neighouring_space = [4,4]
|
21
|
+
piece.neighbours << neighouring_space
|
22
|
+
expect(piece.neighbours).to eq [[4,4]]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "#valid_space?" do
|
27
|
+
it "should return true if valid" do
|
28
|
+
valid_space = [5,5]
|
29
|
+
expect(piece.valid_space?(valid_space)).to eq true
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return nil if x < 0" do
|
33
|
+
invalid_space = [-1, 5]
|
34
|
+
expect(piece.valid_space?(invalid_space)).to eq nil
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return nil if x > 9" do
|
38
|
+
invalid_space = [9,5]
|
39
|
+
expect(piece.valid_space?(invalid_space)).to eq nil
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return nil if y < 0" do
|
43
|
+
invalid_space = [5,-1]
|
44
|
+
expect(piece.valid_space?(invalid_space)).to eq nil
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return nil if y > 9" do
|
48
|
+
invalid_space = [5,9]
|
49
|
+
expect(piece.valid_space?(invalid_space)).to eq nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/spec/player_spec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module ChessVwong
|
4
|
+
describe Player do
|
5
|
+
|
6
|
+
context "#color" do
|
7
|
+
it "returns color" do
|
8
|
+
player = Player.new("Van Damme", "w")
|
9
|
+
expect(player.color).to eq "w"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "#name" do
|
14
|
+
it "returns name" do
|
15
|
+
player = Player.new("Van Damme", "w")
|
16
|
+
expect(player.name).to eq "Van Damme"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/spec/queen_spec.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module ChessVwong
|
4
|
+
describe Queen do
|
5
|
+
let (:current_space) { [1,1]}
|
6
|
+
let (:queen) { Queen.new(current_space,"w")}
|
7
|
+
context "#initialize" do
|
8
|
+
it "should return Piece attributes: color" do
|
9
|
+
expect(queen.color).to eq "w"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return Piece attributes: current_space" do
|
13
|
+
expect(queen.current_space).to eq current_space
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "#character" do
|
18
|
+
it "should return a white queen character" do
|
19
|
+
expect(queen.character).to eq "\u{265B}"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return a black queen character" do
|
23
|
+
queen_2 = Queen.new(current_space,"b")
|
24
|
+
expect(queen_2.character).to eq "\u{2655}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "#generate_neighbours" do
|
29
|
+
it "should return only 21 neighbour when [1,1]" do
|
30
|
+
queen.generate_neighbours(current_space)
|
31
|
+
expect(queen.neighbours.count).to eq 21
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return only 21 neighbour when [8,8]" do
|
35
|
+
current_space = [8,8]
|
36
|
+
queen.generate_neighbours(current_space)
|
37
|
+
expect(queen.neighbours.count).to eq 21
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return only 14 neighbour when in the middle" do
|
41
|
+
current_space = [4,4]
|
42
|
+
queen.generate_neighbours(current_space)
|
43
|
+
expect(queen.neighbours.count).to eq 27
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
data/spec/rook_spec.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module ChessVwong
|
4
|
+
describe Rook do
|
5
|
+
let (:current_space) { [1,1]}
|
6
|
+
let (:rook) { Rook.new(current_space,"w")}
|
7
|
+
context "#initialize" do
|
8
|
+
it "should return Piece attributes: color" do
|
9
|
+
expect(rook.color).to eq "w"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return Piece attributes: current_space" do
|
13
|
+
expect(rook.current_space).to eq current_space
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "#character" do
|
18
|
+
it "should return a white rook character" do
|
19
|
+
expect(rook.character).to eq "\u{265C}"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return a black rook character" do
|
23
|
+
rook_2 = Rook.new(current_space,"b")
|
24
|
+
expect(rook_2.character).to eq "\u{2656}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "#generate_neighbours" do
|
29
|
+
it "should return only 14 neighbour when [1,1]" do
|
30
|
+
rook.generate_neighbours(current_space)
|
31
|
+
expect(rook.neighbours.count).to eq 14
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return only 14 neighbour when [8,8]" do
|
35
|
+
current_space = [8,8]
|
36
|
+
rook.generate_neighbours(current_space)
|
37
|
+
expect(rook.neighbours.count).to eq 14
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return only 14 neighbour when in the middle" do
|
41
|
+
current_space = [4,4]
|
42
|
+
rook.generate_neighbours(current_space)
|
43
|
+
expect(rook.neighbours.count).to eq 14
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "../lib/chess_vwong.rb"
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chess_vwong
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vincent Wong
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: 2-player CLI Chess
|
56
|
+
email:
|
57
|
+
- wingyu64@gmail.com
|
58
|
+
executables:
|
59
|
+
- chess_vwong
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/chess_vwong
|
69
|
+
- chess_vwong.gemspec
|
70
|
+
- example/example_game.rb
|
71
|
+
- lib/chess_vwong.rb
|
72
|
+
- lib/chess_vwong/bishop.rb
|
73
|
+
- lib/chess_vwong/board.rb
|
74
|
+
- lib/chess_vwong/game.rb
|
75
|
+
- lib/chess_vwong/king.rb
|
76
|
+
- lib/chess_vwong/knight.rb
|
77
|
+
- lib/chess_vwong/node.rb
|
78
|
+
- lib/chess_vwong/pawn.rb
|
79
|
+
- lib/chess_vwong/piece.rb
|
80
|
+
- lib/chess_vwong/player.rb
|
81
|
+
- lib/chess_vwong/preload.rb
|
82
|
+
- lib/chess_vwong/queen.rb
|
83
|
+
- lib/chess_vwong/rook.rb
|
84
|
+
- lib/chess_vwong/version.rb
|
85
|
+
- spec/bishop_spec.rb
|
86
|
+
- spec/board_spec.rb
|
87
|
+
- spec/game_spec.rb
|
88
|
+
- spec/king_spec.rb
|
89
|
+
- spec/knight_spec.rb
|
90
|
+
- spec/node_spec.rb
|
91
|
+
- spec/pawn_spec.rb
|
92
|
+
- spec/piece_spec.rb
|
93
|
+
- spec/player_spec.rb
|
94
|
+
- spec/queen_spec.rb
|
95
|
+
- spec/rook_spec.rb
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
homepage: ''
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.4.3
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: 2-player CLI Chess
|
121
|
+
test_files:
|
122
|
+
- spec/bishop_spec.rb
|
123
|
+
- spec/board_spec.rb
|
124
|
+
- spec/game_spec.rb
|
125
|
+
- spec/king_spec.rb
|
126
|
+
- spec/knight_spec.rb
|
127
|
+
- spec/node_spec.rb
|
128
|
+
- spec/pawn_spec.rb
|
129
|
+
- spec/piece_spec.rb
|
130
|
+
- spec/player_spec.rb
|
131
|
+
- spec/queen_spec.rb
|
132
|
+
- spec/rook_spec.rb
|
133
|
+
- spec/spec_helper.rb
|