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.
13 def initialize(piece_factory, size)
14 @piece_factory = piece_factory
18 def from_scanner(scanner)
19 if scanner.scan(/(\+?[A-Z])?(\d[a-z])?([-*x])?(\d[a-z])([+=])?/)
20 { :type => (@piece_factory.type_from_symbol(scanner[1]) if scanner[1]),
21 :src => point_from_coord(scanner[2]),
22 :drop => scanner[3] == '*',
23 :dst => point_from_coord(scanner[4]),
24 :promote => scanner[5] == '+' }
29 from_scanner(StringScanner.new(str))
42 def each_alternative(notation)
43 yield notation.dup.tap{|n| n[:src] = nil }
46 def point_from_coord(coord)
47 if coord =~ /^(\d)([a-z])$/
48 Point.new(@size.x - $1.to_i, $2[0] - ?a)
53 "#{@size.x - p.x}#{(p.y + ?a).chr}"