-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove.rb
56 lines (45 loc) · 1.61 KB
/
move.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
require 'constants'
class Move
include Constants
include MyTeacherUtils
attr_accessor :piece, :from, :to, :capture, :promotion, :can_castle, :enpassant
def initialize(piece=nil, from=nil, to=nil, capture=nil, promotion=nil, can_castle=nil, enpassant=nil)
@piece = piece # WKING to BPAWN
@from = from
@to = to
@capture = capture # WKING to BPAWN
@promotion = promotion # WQUEEN..WBISHOP AND BQUEEN..BBISHOP
@can_castle = can_castle
@enpassant = enpassant
end
def set(from, to)
@from, @to = from, to
end
def to_s(notation=:legible) # FIXME: promotion can be upcase or downcase, is it a good notation principle ?
case notation
when :legible
"#{piece_to_symbol(@piece)}#{SQUARENAME[@from]}#{@capture == nil ? "":"x"}#{SQUARENAME[@to]}#{@promotion ? SYMBOLS[@promotion].upcase : ""}"
when :xboard
"#{SQUARENAME[@from]}#{SQUARENAME[@to]}#{@promotion ? SYMBOLS[@promotion].upcase : ""}"
end
end
#"#{m.to_s}: capture=#{m.capture.to_s}, promotion=#{m.promotion.to_s}"
def ==(b)
@from == b.from and @to == b.to and @piece == b.piece and @capture == b.capture and
@promotion == b.promotion and @can_castle == b.can_castle
end
def score
return 0 if promotion != nil
return 1 if capture != nil
return 2
end
#def inverse
# m = Move.new
# m.piece = @piece
# m.from = @to
# m.to = @from
# m.capture = @capture
# m.promotion = @promotion
# m
#end
end