-
Notifications
You must be signed in to change notification settings - Fork 0
/
chess.rb
84 lines (84 loc) · 2.29 KB
/
chess.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
require './board'
require './minimax'
require './evaluate'
class Chess
board=Board.new
board.createStandardBoard
board.build
puts "1 or 2 players?"
choice=gets
choice=choice.chomp
puts "Use Standard Algebraic Notation"
if(choice=='1')
eval=Evaluate.new
mini=Minimax.new
puts board
player=board.getCurrentPlayer
while(!player.isGameDone)
puts "#{player} Enter move,? to see moves, or ? and square to see moves from square"
input=gets
input=input.chomp
if(input=='?')
player.printLegalMoves
elsif(input.start_with?('?'))
player.printMoves(input[1..-1])
else
res=player.move(input)
if(res.is_a?(Board))
board=res
player=board.getCurrentPlayer
puts board
#eval.printEval(player,0)
#eval.printEval(player.getOpponent,0)
if(!player.isGameDone)
compMove=mini.execute(board,1)
board=player.makeMove(compMove)
player=board.getCurrentPlayer
puts "Computer played #{compMove}"
puts board
#eval.printEval(player,0)
#eval.printEval(player.getOpponent,0)
end
else
puts res
end
end
end
if player.isInCheckMate
puts "Checkmate! #{player.getOpponent} wins!"
elsif player.isInStaleMate
puts "Draw! #{player} is in Stalemate"
else
puts "Draw! insufficient material! "
end
else
puts board
player=board.getCurrentPlayer
while(!player.isGameDone)
puts "#{player} Enter move,? to see moves, or ? and square to see moves from square"
input=gets
input=input.chomp
if(input=='?')
player.printLegalMoves
elsif(input.start_with?('?'))
player.printMoves(input[1..-1])
else
res=player.move(input)
if(res.is_a?(Board))
board=res
player=board.getCurrentPlayer
puts board
else
puts res
end
end
end
if player.isInCheckMate
puts "Checkmate! #{player.getOpponent} wins!"
elsif player.isInStaleMate
puts "Draw! #{player} is in Stalemate"
else
puts "Draw! insufficient material! "
end
end
end