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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0fef94857588ea8e0075792e5d00e17bdcb59027
4
- data.tar.gz: 0ce26be57dff21eac0ccdcd316f7e1b57ca6d807
3
+ metadata.gz: cb647ae34dfaa1eaa314c5ad0cf0701d0f0168c4
4
+ data.tar.gz: 0228a61d3ca95cf530ee2a18e5d349f6a6af5c87
5
5
  SHA512:
6
- metadata.gz: 2d7d20933510dbe53257fc26c64d49a6b7027a1464762b1d3d151914f952f2a45e83d4c41f9c53030b7861ccd277c26480f68401aaa12b299932475e2b98d45b
7
- data.tar.gz: 3e8d19fac4928cad5b852093e61b8efdb8d6c7264f390c77659faf28eb2b51cbecebfce185cf89a31dd37143698cbe0d830c8001b35c072b871d313085a8e887
6
+ metadata.gz: c902df6af2f44d4c80cee1bb94876c874a0d11fa17e218e29efaf04d7acc8cab86cfbf60b940da679f68ac64d50c5748b5a4347e5ec2c7f0564e90fe4eee0a2f
7
+ data.tar.gz: 91fdd57b4579d629b0f4caa6e0114830e843dc0b74226ea638ead07a51d3b09385f7d83f1e5e29d004d2d33b084f486f0c38400501ffbde5b6ec9c03f7206f53
data/.DS_Store ADDED
Binary file
data/README.md CHANGED
@@ -1,35 +1,42 @@
1
1
  # Chess
2
2
 
3
- A barebones version of command-line Chess for 2 players.
3
+ A barebones version of command-line Chess for 2 players.
4
+
5
+ Although currently missing the feature that declares Check, it is completely playable and includes all special moves(castling, en passant, promotion, and a pawn's double step on its first move).
4
6
 
5
7
  TODO:
6
- 1. Alert Check/Mate
7
- 2. Castling & En-Passant Moves
8
+ 1. Declare Check/Mate
9
+ 2. En-Passant(first-turn) bug
8
10
 
9
11
  ##Gameplay
10
- The game is played on a standard 8 by 8 board as show below.
12
+ The game is played on a standard 8x8 board as shown below.
11
13
 
12
14
  A B C D E F G H
13
- 8
14
- 7
15
+ 8
16
+ 7
15
17
  6 _ _ _ _ _ _ _ _
16
18
  5 _ _ _ _ _ _ _ _
17
19
  4 _ _ _ _ _ _ _ _
18
20
  3 _ _ _ _ _ _ _ _
19
- 2
20
- 1
21
+ 2
22
+ 1
21
23
 
22
24
  A user will first be prompted to select a chess piece belonging to his/her color. Once a the chess piece has been chosen, he/she will then be prompted to select a space to move that chess piece.
23
25
 
24
- To enter a command, simply type in the X and Y coordinate without any spaces or commas seperating the two, for example:
25
- * A2
26
- * H7
27
-
28
- (Lowercases are also accepted)
26
+ ###Basic Commands
27
+ To enter a command, simply type in the X and Y coordinate without any spaces or commas seperating the two. Eg. A2, H7 or B6 (Lowercases are also accepted).
29
28
 
30
29
  If a command is invalid, the use will be alerted and prompted again until a valid command is entered.
31
30
 
31
+ ###Special moves
32
+
33
+ All special moves in a chess game (castling, en passant, promotion, and a pawn's double step on its first move) are recognized and allowed during game play.
34
+
35
+ Note:
32
36
 
37
+ i) To initialize Castling, select Rook THEN select King. Restricted by Check not applied yet.
38
+
39
+ ii) Restriction of En-Passant as first turn since double-stepped not applied yet.
33
40
 
34
41
  ## Installation
35
42
 
@@ -39,7 +46,13 @@ To install:
39
46
 
40
47
  ## Usage
41
48
 
42
- TODO: Write usage instructions here
49
+ Once gem has successfully installed, simply type:
50
+
51
+ $ chess_vwong
52
+
53
+ Or clone the repo locally and run:
54
+
55
+ $ rake play
43
56
 
44
57
  ## Contributing
45
58
 
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- desc "Play Chess"
1
+ desc 'Play Chess'
2
2
  task :play do
3
- ruby "-w bin/chess_vwong.rb"
4
- end
3
+ ruby '-w bin/chess_vwong'
4
+ end
data/bin/chess_vwong CHANGED
@@ -1,21 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'chess_vwong'
3
3
 
4
- puts "Welcome to Chess"
5
- puts "Player 1, please Enter your name:"
4
+ puts 'Welcome to Chess'
5
+ puts 'Player 1, please Enter your name:'
6
6
  name_1 = gets.chomp
7
- puts "Player 2, please Enter your name:"
7
+ puts 'Player 2, please Enter your name:'
8
8
  name_2 = gets.chomp
9
- puts ""
9
+ puts ''
10
10
 
11
- puts "---------------------------"
11
+ puts '---------------------------'
12
12
  puts "#{name_1} will be White"
13
13
  puts "#{name_2} will be Black"
14
- puts "---------------------------"
15
- puts ""
14
+ puts '---------------------------'
15
+ puts ''
16
16
  puts "Let's begin!"
17
17
 
18
- bob = ChessVwong::Player.new(name_1, "w")
19
- peter = ChessVwong::Player.new(name_2, "b")
18
+ bob = ChessVwong::Player.new(name_1, 'w')
19
+ peter = ChessVwong::Player.new(name_2, 'b')
20
20
  players = [bob, peter]
21
- ChessVwong::Game.new(players).play
21
+ ChessVwong::Game.new(players).play
Binary file
data/chess_vwong.gemspec CHANGED
@@ -4,21 +4,21 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'chess_vwong/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "chess_vwong"
7
+ spec.name = 'chess_vwong'
8
8
  spec.version = ChessVwong::VERSION
9
- spec.authors = ["Vincent Wong"]
10
- spec.email = ["wingyu64@gmail.com"]
11
- spec.summary = %q{2-player CLI Chess}
12
- spec.description = %q{2-player CLI Chess}
13
- spec.homepage = ""
14
- spec.license = "MIT"
9
+ spec.authors = ['Vincent Wong']
10
+ spec.email = ['wingyu64@gmail.com']
11
+ spec.summary = '2-player CLI Chess'
12
+ spec.description = '2-player CLI Chess'
13
+ spec.homepage = 'https://github.com/wingyu/chess_vwong'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = "chess_vwong"#spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.executables = 'chess_vwong' # spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.7"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "rspec"
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec'
24
24
  end
@@ -1,20 +1,20 @@
1
- require_relative "../lib/chess_vwong.rb"
2
-
3
- puts "Welcome to Chess"
4
- puts "Player 1, please Enter your name:"
5
- name_1 = gets.chomp
6
- puts "Player 2, please Enter your name:"
7
- name_2 = gets.chomp
8
- puts ""
1
+ require_relative '../lib/chess_vwong.rb'
9
2
 
10
- puts "---------------------------"
11
- puts "#{name_1} will be White"
12
- puts "#{name_2} will be Black"
13
- puts "---------------------------"
14
- puts ""
15
- puts "Let's begin!"
3
+ puts 'Welcome to Chess'
4
+ # puts "Player 1, please Enter your name:"
5
+ # name_1 = gets.chomp
6
+ # puts "Player 2, please Enter your name:"
7
+ # name_2 = gets.chomp
8
+ # puts ""
16
9
 
17
- bob = ChessVwong::Player.new(name_1, "w")
18
- peter = ChessVwong::Player.new(name_2, "b")
10
+ # puts "---------------------------"
11
+ # puts "#{name_1} will be White"
12
+ # puts "#{name_2} will be Black"
13
+ # puts "---------------------------"
14
+ # puts ""
15
+ # puts "Let's begin!"
16
+
17
+ bob = ChessVwong::Player.new('WHITE', 'w')
18
+ peter = ChessVwong::Player.new('BLACK', 'b')
19
19
  players = [bob, peter]
20
- ChessVwong::Game.new(players).play
20
+ ChessVwong::Game.new(players).play
data/lib/chess_vwong.rb CHANGED
@@ -1,23 +1,19 @@
1
- # require "chess_vwong/version"
1
+ require 'chess_vwong/version'
2
2
 
3
3
  module ChessVwong
4
4
  # Your code goes here...
5
5
  end
6
6
 
7
+ require_relative './chess_vwong/node.rb'
8
+ require_relative './chess_vwong/player.rb'
9
+ require_relative './chess_vwong/piece.rb'
10
+ require_relative './chess_vwong/knight.rb'
11
+ require_relative './chess_vwong/rook.rb'
12
+ require_relative './chess_vwong/king.rb'
13
+ require_relative './chess_vwong/bishop.rb'
14
+ require_relative './chess_vwong/queen.rb'
15
+ require_relative './chess_vwong/pawn.rb'
16
+ require_relative './chess_vwong/board.rb'
17
+ require_relative './chess_vwong/preload.rb'
18
+ require_relative './chess_vwong/game.rb'
7
19
 
8
- require_relative "./chess_vwong/node.rb"
9
- require_relative "./chess_vwong/player.rb"
10
- require_relative "./chess_vwong/piece.rb"
11
- require_relative "./chess_vwong/knight.rb"
12
- require_relative "./chess_vwong/rook.rb"
13
- require_relative "./chess_vwong/king.rb"
14
- require_relative "./chess_vwong/bishop.rb"
15
- require_relative "./chess_vwong/queen.rb"
16
- require_relative "./chess_vwong/pawn.rb"
17
- require_relative "./chess_vwong/board.rb"
18
- require_relative "./chess_vwong/preload.rb"
19
- require_relative "./chess_vwong/game.rb"
20
-
21
- # board = ChessVwong::Board.new
22
- # board.preload_pieces
23
- # board.formatted_grid
@@ -1,22 +1,19 @@
1
1
  module ChessVwong
2
2
  class Bishop < Piece
3
-
4
3
  def character
5
- color == "w" ? "\u{265D}" : "\u{2657}"
4
+ color == 'w' ? "\u{2657}" : "\u{265D}"
6
5
  end
7
6
 
8
7
  # Generate all possible Neighbouring Nodes
9
8
  def generate_neighbours(current_space)
10
9
  moves = []
11
- (1..8).each {|i| moves << [i, i]}
12
- (1..8).each {|i| moves << [i, -i]}
13
- (1..8).each {|i| moves << [-i, i]}
14
- (1..8).each {|i| moves << [-i, -i]}
10
+ (1..8).each { |i| moves << [i, i] }
11
+ (1..8).each { |i| moves << [i, -i] }
12
+ (1..8).each { |i| moves << [-i, i] }
13
+ (1..8).each { |i| moves << [-i, -i] }
15
14
  moves.each do |move|
16
15
  neigbour_helper(current_space, move[0], move[1])
17
16
  end
18
- end
19
-
17
+ end
20
18
  end
21
19
  end
22
-
@@ -7,86 +7,75 @@ module ChessVwong
7
7
  @grid = default_grid
8
8
  end
9
9
 
10
- # Convert letter/number input into grid coordinates, if improper coordinates: empty array is returned
10
+ # Convert letter/number input into grid coordinates, if improper coordinates: empty array is returned (bandaid fix) so loop continues
11
11
  def process_input(input)
12
12
  if input[0] =~ /[A-Za-z]/
13
- grid_values = input.tr!("87654321", "12345678")
14
- grid_values = input.upcase.tr!("ABCDEFGH", "12345678")
15
- grid_values = grid_values.split("")
16
- grid_values.map! {|i|i.to_i}
13
+ grid_values = input.tr!('87654321', '12345678')
14
+ grid_values = input.upcase.tr!('ABCDEFGH', '12345678')
15
+ grid_values = grid_values.split('')
16
+ grid_values.map!(&:to_i)
17
17
  else
18
18
  return []
19
- end
19
+ end
20
20
  end
21
21
 
22
22
  # Get piece & generate neighbours, extra helper-methods required for Pawns due to unique nature
23
- def get_piece(input=gets.chomp, player)
23
+ def get_piece(input = gets.chomp, player)
24
24
  @get_value = process_input(input)
25
- if get_value.count ==2
25
+ if get_value.count == 2
26
26
  chosen_node = grid[get_value[1]][get_value[0]]
27
27
  unless chosen_node.occupied.empty? || chosen_node.occupied.first.color != player.color
28
- @chosen_piece = chosen_node.occupied.pop()
29
- chosen_piece.instance_of?(Pawn) ? pawn_kill_helper(chosen_piece, get_value) : @chosen_piece.generate_neighbours(get_value)
30
- return @chosen_piece
31
- end
28
+ @chosen_piece = chosen_node.occupied.pop
29
+ pawn_moves_helper(chosen_piece) #if pawn selected, check if unique moves apply
30
+ return chosen_piece
31
+ end
32
32
  end
33
33
  end
34
34
 
35
- # Sets piece if within neighbour range & valid, also checks if pawn can beome Queen
36
- def set_piece(input=gets.chomp, player)
35
+
36
+
37
+ # Sets piece if within neighbour range & valid, also checks for unique moves
38
+ def set_piece(input = gets.chomp, player)
37
39
  value = process_input(input)
38
- if value.count ==2
40
+ if value.count == 2
39
41
  chosen_node = grid[value[1]][value[0]]
42
+ #Castling
43
+ return apply_castling(chosen_piece) if chosen_piece.instance_of?(Rook) && chosen_node.occupied.first.instance_of?(King) && clear_path?(get_value, value)
44
+ #En Passant
45
+ return en_pass_kill(chosen_piece, player, chosen_node) if chosen_piece.instance_of?(Pawn) && chosen_node.occupied.empty? && !chosen_piece.ep_kill.empty?
46
+ #Standard & Promotion
40
47
  if chosen_piece.neighbours.include?(value) && valid_path?(@get_value, value)
41
- chosen_piece.current_space = value
42
- chosen_node.occupied << chosen_piece
43
- player.kill_list << chosen_node.occupied.shift() if chosen_node.occupied.count > 1
48
+ standard_move(chosen_piece, chosen_node, value, player)
44
49
  pawn_to_queen(chosen_piece, chosen_node) if chosen_piece.instance_of?(Pawn)
45
50
  return chosen_node.occupied
46
- end
47
- end
48
- end
49
-
50
- # Print's out Board
51
- def formatted_grid
52
- grid.each do |row|
53
- puts row.map { |node| node.occupied.empty? ? "_" : node.occupied.first.character}.join(" ")
51
+ end
54
52
  end
55
53
  end
56
54
 
57
-
58
-
59
- #Checks if path is valid
55
+ # Checks if path is valid
60
56
  def valid_path?(start, dest)
61
- #if End node is empty OR end_node is occupied with enemy_piece then check if path is clear
62
- if grid[dest[1]][dest[0]].occupied.empty? || !grid[dest[1]][dest[0]].occupied.empty? && grid[dest[1]][dest[0]].occupied.first.color != chosen_piece.color
57
+ # if End node is empty OR end_node is occupied with enemy_piece then check if path is clear
58
+ if grid[dest[1]][dest[0]].occupied.empty? || !grid[dest[1]][dest[0]].occupied.empty? && grid[dest[1]][dest[0]].occupied.first.color != chosen_piece.color
63
59
  chosen_piece.instance_of?(Knight) ? true : clear_path?(start, dest)
64
60
  else
65
61
  false
66
62
  end
67
63
  end
68
64
 
69
-
70
- def scan_for_check
71
- # execute it for selected piece that was most recently moves AND every king move
72
- end
73
-
74
- #Checks if path is clear [x,y] = grid[y][x]
65
+ # Checks if path is clear. [x,y] = grid[y][x]
75
66
  def clear_path?(start, dest)
76
67
  if (start[0] < dest[0] && start[1] > dest[1]) || (start[0] > dest[0] && start[1] < dest[1])
77
- rising_path(start, dest)
68
+ rising_path(start, dest)
78
69
  elsif (start[0] < dest[0] && start[1] < dest[1]) || (start[0] > dest[0] && start[1] > dest[1])
79
- falling_path(start, dest)
70
+ falling_path(start, dest)
80
71
  elsif start[1] != dest[1]
81
72
  vertical_path(start, dest)
82
73
  elsif start[0] != dest[0]
83
74
  horizontal_path(start, dest)
84
- end
85
- return process_path
75
+ end
76
+ process_path
86
77
  end
87
78
 
88
-
89
-
90
79
  def vertical_path(start, dest)
91
80
  @node_path = []
92
81
  # DOWN
@@ -96,7 +85,7 @@ module ChessVwong
96
85
  end
97
86
  # UP
98
87
  elsif start[1] > dest[1]
99
- start[1].step(dest[1]+1, -1) do |i|
88
+ start[1].step(dest[1] + 1, -1) do |i|
100
89
  node_path << grid[i][start[0]]
101
90
  end
102
91
  end
@@ -112,7 +101,7 @@ module ChessVwong
112
101
  end
113
102
  # LEFT
114
103
  elsif start[0] > dest[0]
115
- start[0].step(dest[0]+1, -1) do |i|
104
+ start[0].step(dest[0] + 1, -1) do |i|
116
105
  node_path << grid[start[1]][i]
117
106
  end
118
107
  end
@@ -122,21 +111,21 @@ module ChessVwong
122
111
  def rising_path(start, dest)
123
112
  @node_path = []
124
113
  i = 0
125
- j = start[0]
126
- #UP_RIGHT
114
+ j = start[0]
115
+ # UP_RIGHT
127
116
  if start[0] < dest[0] && start[1] > dest[1]
128
117
  while j < dest[0]
129
- node_path << grid[start[1] - i][start[0]+i]
118
+ node_path << grid[start[1] - i][start[0] + i]
130
119
  i += 1
131
120
  j += 1
132
- end
133
- #DOWN_LEFT
121
+ end
122
+ # DOWN_LEFT
134
123
  elsif start[0] > dest[0] && start[1] < dest[1]
135
124
  while j > dest[0]
136
- node_path << grid[start[1] + i][start[0]-i]
125
+ node_path << grid[start[1] + i][start[0] - i]
137
126
  i += 1
138
127
  j -= 1
139
- end
128
+ end
140
129
  end
141
130
  node_path
142
131
  end
@@ -144,64 +133,137 @@ module ChessVwong
144
133
  def falling_path(start, dest)
145
134
  @node_path = []
146
135
  i = 0
147
- j = start[0]
148
- # DOWN_RIGHT
136
+ j = start[0]
137
+ # DOWN_RIGHT
149
138
  if start[0] < dest[0] && start[1] < dest[1]
150
139
  while j < dest[0]
151
- node_path << grid[start[1] + i][start[0]+i]
140
+ node_path << grid[start[1] + i][start[0] + i]
152
141
  i += 1
153
142
  j += 1
154
- end
143
+ end
155
144
  # UP_LEFT
156
145
  elsif start[0] > dest[0] && start[1] > dest[1]
157
146
  while j > dest[0]
158
- node_path << grid[start[1]-i][start[0]-i]
147
+ node_path << grid[start[1] - i][start[0] - i]
159
148
  i += 1
160
149
  j -= 1
161
- end
150
+ end
162
151
  end
163
- node_path
152
+ node_path
164
153
  end
165
154
 
155
+ def apply_castling(rook)
156
+ king = grid[rook.current_space[1]][5].occupied.pop
157
+ if king.turns == 0 && rook.turns == 0
158
+ if rook.current_space[0] == 1 # Long Castle
159
+ switch_rook_castle(rook, king, 4, 3)
160
+ elsif rook.current_space[0] == 8 # Short Castle
161
+ switch_rook_castle(rook, king, 6, 7)
162
+ end
163
+ end
164
+ end
166
165
 
167
- private
168
- def default_grid
169
- Array.new(9) { Array.new(9) { Node.new } }
166
+ # Print's out Board
167
+ def formatted_grid
168
+ grid.each do |row|
169
+ puts row.map { |node| node.occupied.empty? ? '_' : node.occupied.first.character }.join(' ')
170
170
  end
171
+ end
172
+
173
+ private
174
+
175
+ def default_grid
176
+ Array.new(9) { Array.new(9) { Node.new } }
177
+ end
171
178
 
172
- # Goes through each node to see if it's Blocked
173
- def process_path
174
- node_path.each do |node|
175
- unless node.occupied.empty?
176
- return false
177
- end
179
+ # Goes through each node to see if it's Blocked
180
+ def process_path
181
+ node_path.each do |node|
182
+ unless node.occupied.empty?
183
+ return false
178
184
  end
179
185
  end
186
+ end
180
187
 
181
- # if Pawn is selected, nearby spaces analyzed if enemries are present, if so they have additional moves
182
- def pawn_kill_helper(chosen_piece, get_value)
183
- if chosen_piece.color == "w"
184
- node1 = grid[get_value[1] - 1][get_value[0] - 1]
185
- node2 = grid[get_value[1] - 1][get_value[0] + 1]
186
- @chosen_piece.generate_neighbours(get_value, node1, node2)
187
- else
188
- node1 = grid[get_value[1] + 1][get_value[0] - 1]
189
- node2 = grid[get_value[1] + 1][get_value[0] + 1]
190
- @chosen_piece.generate_neighbours(get_value, node1, node2)
191
- end
188
+ def standard_move(piece, node, value, player)
189
+ piece.ep_kill =[] #resetting ability to En Passant
190
+ piece.current_space = value
191
+ piece.turns += 1
192
+ node.occupied << piece
193
+ player.kill_list << node.occupied.shift if node.occupied.count > 1
194
+ end
195
+
196
+ # ######UNIQUE MOVES##############
197
+
198
+ # Check for en_passant or normal kill moves
199
+ def pawn_moves_helper(piece)
200
+ if piece.instance_of?(Pawn)
201
+ en_pass_check(piece, piece.current_space[0], piece.current_space[1])
202
+ pawn_kill_helper(piece, get_value)
203
+ else
204
+ @chosen_piece.generate_neighbours(get_value)
205
+ end
206
+ end
207
+
208
+ # if Pawn is selected, nearby spaces analyzed if enemies are present, if so they have additional moves
209
+ def pawn_kill_helper(chosen_piece, get_value)
210
+ if chosen_piece.color == 'w'
211
+ node1 = grid[get_value[1] - 1][get_value[0] - 1]
212
+ node2 = grid[get_value[1] - 1][get_value[0] + 1]
213
+ @chosen_piece.generate_neighbours(get_value, node1, node2)
214
+ else
215
+ node1 = grid[get_value[1] + 1][get_value[0] - 1]
216
+ node2 = grid[get_value[1] + 1][get_value[0] + 1]
217
+ @chosen_piece.generate_neighbours(get_value, node1, node2)
192
218
  end
219
+ end
193
220
 
194
- def pawn_to_queen(pawn, current_node)
195
- if pawn.color == "w" && pawn.current_space[1] == 1
196
- current_node.occupied.pop()
197
- current_node.occupied << Queen.new(pawn.current_space, "w")
198
- elsif pawn.color == "b" && pawn.current_space[1] == 8
199
- current_node.occupied.pop()
200
- current_node.occupied << Queen.new(pawn.current_space, "b")
201
- end
221
+ def pawn_to_queen(pawn, current_node)
222
+ if pawn.color == 'w' && pawn.current_space[1] == 1
223
+ current_node.occupied.pop
224
+ current_node.occupied << Queen.new(pawn.current_space, 'w')
225
+ elsif pawn.color == 'b' && pawn.current_space[1] == 8
226
+ current_node.occupied.pop
227
+ current_node.occupied << Queen.new(pawn.current_space, 'b')
202
228
  end
229
+ end
203
230
 
204
- end
205
- end
231
+
232
+ def en_pass_kill(pawn, player, node)
233
+ x = pawn.current_space[0]
234
+ y = pawn.current_space[1]
235
+ if pawn.ep_kill.last == "L"
236
+ player.kill_list << grid[y][x-1].occupied.pop()
237
+ node.occupied << pawn
238
+ elsif pawn.ep_kill.last == "R"
239
+ player.kill_list << grid[y][x+1].occupied.pop()
240
+ node.occupied << pawn
241
+ end
242
+ pawn.ep_kill =[] #resetting ability to En Passant
243
+ end
244
+
245
+ def en_pass_check(pawn, x, y)
246
+ l_piece = grid[y][x-1].occupied.first
247
+ r_piece = grid[y][x+1].occupied.first
248
+ en_pass_helper(pawn, l_piece, "L") #adjacent enemy on left
249
+ en_pass_helper(pawn, r_piece, "R") #adjacent enemy on right
250
+ end
206
251
 
252
+ def en_pass_helper(pawn, piece, side)
253
+ if piece.instance_of?(Pawn) && piece.color != pawn.color
254
+ pawn.color == 'w' ? set_en_pass(pawn, piece, 4, side) : set_en_pass(pawn, piece, 5, side) #set row depending on color
255
+ end
256
+ end
257
+
258
+ def set_en_pass(pawn, piece, row, side)
259
+ pawn.ep_kill << side if piece.turns == 1 && piece.current_space[1] == row #if enemy pawn has double-stepped, add ep_kill to pawn
260
+ end
207
261
 
262
+ def switch_rook_castle(rook, king, rook_space, king_space)
263
+ rook.current_space[0] = rook_space
264
+ grid[rook.current_space[1]][rook_space].occupied << rook
265
+ king.current_space[0] = king_space
266
+ grid[rook.current_space[1]][king_space].occupied << king
267
+ end
268
+ end
269
+ end