@@ -9,7 +9,7 @@ def initialize
99 @chessboard = ChessBoard . new
1010
1111 end
12- def play_with_two_humans
12+ def human_vs_human
1313 puts "Player-1 What is your name?"
1414 name1 = gets . chomp
1515 player_1 = Player . new ( name1 , "white" )
@@ -26,6 +26,7 @@ def play_with_two_humans
2626
2727
2828 current_player = player_1
29+ do_break = false
2930 loop do
3031 @chessboard . display
3132 current_player . show_captured_piece
@@ -70,10 +71,12 @@ def play_with_two_humans
7071 the_attacked_piece = @chessboard . data . dig ( array_indexes_of_new_positions [ 0 ] , array_indexes_of_new_positions [ 1 ] )
7172
7273 if the_attacked_piece . class . name == "King"
74+ do_break = true
7375 puts "CHECKMATE" . light_green
7476 puts "Congratulations #{ current_player . name } , you win!!!" . light_green
75- break 2
77+ break
7678 end
79+
7780
7881
7982 # Capture the enemy's piece
@@ -117,12 +120,13 @@ def play_with_two_humans
117120 redo
118121
119122 end
123+ break if do_break
120124 current_player == player_1 ? current_player = player_2 : current_player = player_1
121125 end
122126 end
123127
124128
125- def play_between_human_and_ai
129+ def human_vs_ai
126130 puts "Player-1 What is your name?"
127131 name1 = gets . chomp
128132 player_1 = Player . new ( name1 , "white" )
@@ -139,6 +143,7 @@ def play_between_human_and_ai
139143
140144
141145 current_player = player_1
146+ do_break = false
142147 loop do
143148 @chessboard . display
144149 current_player . show_captured_piece
@@ -191,11 +196,12 @@ def play_between_human_and_ai
191196 the_attacked_piece = @chessboard . data . dig ( array_indexes_of_new_positions [ 0 ] , array_indexes_of_new_positions [ 1 ] )
192197
193198 if the_attacked_piece . class . name == "King"
199+ do_break = true
194200 puts "CHECKMATE" . light_green
195201 puts "Congratulations #{ current_player . name } , you win!!!" . light_green
196- break 2
202+ break
197203 end
198-
204+
199205
200206 # Capture the enemy's piece
201207 @chessboard . remove ( the_attacked_piece )
@@ -238,12 +244,13 @@ def play_between_human_and_ai
238244 redo
239245
240246 end
247+ break if do_break
241248 current_player == player_1 ? current_player = player_2 : current_player = player_1
242249 end
243250 end
244251
245252
246- def play_with_two_ai
253+ def ai_vs_ai
247254
248255 player_1 = AI . new ( "Siri" , "white" )
249256
@@ -257,6 +264,7 @@ def play_with_two_ai
257264
258265 puts "Let's start playing chess right now" . light_blue
259266 current_player = player_1
267+ do_break = false
260268 loop do
261269 @chessboard . display
262270 current_player . show_captured_piece
@@ -270,7 +278,6 @@ def play_with_two_ai
270278
271279 @chessboard . display
272280 current_player . show_captured_piece
273- do_break = false
274281 loop do
275282 new_position = current_player . choose_a_position_to_move ( @chessboard . active_piece )
276283 sleep ( 1 )
0 commit comments