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.
8 require_bundle 'ics', 'icsapi'
12 # Style 12 was designed by Daniel Sleator
13 # (sleator+@cs.cmu.edu) Darooha@ICC
17 ([qkbnrpQKBNRP-]{8})\s+ # chessboard
18 ([qkbnrpQKBNRP-]{8})\s+ # chessboard
19 ([qkbnrpQKBNRP-]{8})\s+ # chessboard
20 ([qkbnrpQKBNRP-]{8})\s+ # chessboard
21 ([qkbnrpQKBNRP-]{8})\s+ # chessboard
22 ([qkbnrpQKBNRP-]{8})\s+ # chessboard
23 ([qkbnrpQKBNRP-]{8})\s+ # chessboard
24 ([qkbnrpQKBNRP-]{8})\s+ # chessboard
25 ([BW])\s+ # black/white
26 (-1|[0-7])\s+ # passing pawn
27 ([01])\s+ # castle rights
28 ([01])\s+ # castle rights
29 ([01])\s+ # castle rights
30 ([01])\s+ # castle rights
31 (-?\d+)\s+ # 50 moves made
32 (\d+)\s+ # game number
35 (-[1-4]|[0-2])\s+ # status
51 WHITE_KING_CASTLING = 11
52 WHITE_QUEEN_CASTLING = 12
53 BLACK_KING_CASTLING = 13
54 BLACK_QUEEN_CASTLING = 14
61 STARTING_INCREMENT = 21
65 LAST_MOVE_VERBOSE = 27
72 ISOLATED_POSITION = -3
73 OBSERVING_EXAMINED = -2
80 def self.from_match(match, games)
81 game_number = match[GAME_NUMBER].to_i
82 current_game = games[game_number]
86 :white => { :name => match[WHITE_PLAYER] },
87 :black => { :name => match[BLACK_PLAYER] },
88 :number => game_number,
90 :icsapi => ICSApi.new(game)
92 games[game_number] = current_game
94 icsapi = current_game[:icsapi]
96 icsapi.new_state(:turn => match[TURN] == 'W' ? :white : :black,
97 :en_passant => match[EN_PASSANT].to_i,
98 :wk_castling => match[WHITE_KING_CASTLING].to_i == 1,
99 :wq_castling => match[WHITE_QUEEN_CASTLING].to_i == 1,
100 :bk_castling => match[BLACK_KING_CASTLING].to_i == 1,
101 :bq_castling => match[BLACK_QUEEN_CASTLING].to_i == 1)
102 match[CHESSBOARD..CHESSBOARD+8].each_with_index do |row, i|
103 row.split(//).each_with_index do |p, j|
104 piece = icsapi.new_piece(p)
105 state.board[Point.new(j, i)] = piece
109 style12 = new(:state => state,
110 :game_number => match[GAME_NUMBER].to_i,
111 :move_index => match[MOVE_ORDINAL].to_i,
112 :white_player => match[WHITE_PLAYER],
113 :black_player => match[BLACK_PLAYER],
114 :relation => match[RELATION].to_i,
115 :last_move => match[LAST_MOVE_VERBOSE],
116 :last_move_san => match[LAST_MOVE],
118 :white => match[WHITE_TIME].to_i,
119 :black => match[BLACK_TIME].to_i },
120 :match_info => current_game
128 def method_missing(field)
129 if @opts.has_key?(field)
137 (@opts[:move_index] - 1) * 2 +
138 (state.turn == :white ? 0 : 1)