-
Notifications
You must be signed in to change notification settings - Fork 2
/
player.rb
189 lines (148 loc) · 3.14 KB
/
player.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
=begin
ruby_chess
The Chess Board game implemented in the metalanguage ruby
Using the mighty GTK2 library
Copyright (C) 2006 Sébastien Boisvert
http://sebhtml.blogspot.com/
Sebastien.Boisvert<AT>USherbrooke<DOT>CA
This software is released under the GPL version 2 (1991)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
An online plain text version is available here:
http://www.gnu.org/licenses/gpl.txt
=end
require_relative 'color'
require_relative 'artificial_intelligence'
require_relative 'queen'
require_relative 'knight'
require_relative 'king'
require_relative 'pawn'
require_relative 'rook'
require_relative 'bishop'
class Player
def to_s
@color
end
def initial_king_row
if @color == Color::BLACK
Board::ROW_8
else
Board::ROW_1
end
end
def pawn_row
if @color == Color::BLACK
Board::ROW_7
else
Board::ROW_2
end
end
def human?
@intelligence.class == Human
end
def intelligence
@intelligence
end
def initialize color, intelligence
@intelligence = intelligence.new self
@color = color
@moves_history = Array.new
@king = King.new self
@queen = Queen.new self
@pawn_a = Pawn.new self
@pawn_b = Pawn.new self
@pawn_c = Pawn.new self
@pawn_d = Pawn.new self
@pawn_e = Pawn.new self
@pawn_f = Pawn.new self
@pawn_g = Pawn.new self
@pawn_h = Pawn.new self
@rook_a = Rook.new self
@rook_h = Rook.new self
@knight_b = Knight.new self
@knight_g = Knight.new self
@bishop_c = Bishop.new self
@bishop_f = Bishop.new self
@extra_stuff = []
end
def add_man man
@extra_stuff << man
end
def opponent= opponent
@opponent = opponent
end
def opponent
@opponent
end
def ai?
@intelligence.class == ArtificialIntelligence
end
def play board, moves_list
@intelligence.choose board, moves_list, self
end
def color
@color
end
def king
@king
end
def black?
@color == Color::BLACK
end
def king
@king
end
def queen
@queen
end
def pawn_a
@pawn_a
end
def pawn_b
@pawn_b
end
def pawn_c
@pawn_c
end
def pawn_d
@pawn_d
end
def pawn_e
@pawn_e
end
def pawn_f
@pawn_f
end
def pawn_g
@pawn_g
end
def pawn_h
@pawn_h
end
def rook_a
@rook_a
end
def rook_h
@rook_h
end
def knight_b
@knight_b
end
def knight_g
@knight_g
end
def bishop_c
@bishop_c
end
def bishop_f
@bishop_f
end
end