1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
24 state = @game.state.new
25 state.turn = opts[:turn]
26 state.en_passant_square =
27 if opts[:en_passant] != -1
28 Point.new(opts[:en_passant],
29 state.turn == :white ?
30 state.board.size.y - 3 : 2)
32 state.castling_rights.cancel_king(:white) unless opts[:wk_castling]
33 state.castling_rights.cancel_queen(:white) unless opts[:wq_castling]
34 state.castling_rights.cancel_king(:black) unless opts[:bk_castling]
35 state.castling_rights.cancel_queen(:black) unless opts[:bq_castling]
40 return nil if p == '-'
41 color = p =~ /[a-z]/ ? :black : :white
42 type = PIECES[p.downcase]
43 @game.piece.new(color, type)
46 def same_state(state1, state2)
47 (state1.board == state2.board).tap{|x| puts "boards differ" unless x } &&
48 (state1.turn == state2.turn).tap{|x| puts "turns differ" unless x }
51 def amend_state(state1, state2)
52 state1.dup.tap do |result|
53 result.board = state2.board.dup
54 result.turn = state2.turn