-
Notifications
You must be signed in to change notification settings - Fork 0
/
chessgame.rb
55 lines (41 loc) · 847 Bytes
/
chessgame.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# encoding: utf-8
require_relative "board"
require_relative "player"
class Chessgame
attr_accessor :board
def initialize
@board = Board.new()
@player1 = HumanPlayer.new
@player2 = HumanPlayer.new
end
def run
startup
until winner? || @player2.quitter
begin
@player1.take_turn(@board)
break if @player1.quitter
@player2.take_turn(@board)
rescue IllegalMove => e
puts e.message
end
end
game_over
end
def winner?
@board.check_mate?(:white) || @board.check_mate?(:black)
end
def startup
puts "Welcome to Chess"
@board.board_setup
@board.display
end
def game_over
if winner?
puts @board.check_mate?(:white) ? "Black wins!" : "White wins!"
else
puts "You quitter."
end
end
end
a = Chessgame.new
a.run