Method: Uci#set_board
- Defined in:
- lib/uci.rb
#set_board(fen) ⇒ Object
set the board using Forsyth–Edwards Notation (FEN), LONG format including move, castling, etc.
Attributes
-
fen - rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1 (Please
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/uci.rb', line 262 def set_board(fen) # rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1 fen_pattern = /^[a-zA-Z0-9\/]+\s[bw]\s[kqKQ-]+\s[a-h0-8-]+\s\d+\s\d+$/ unless fen =~ fen_pattern raise FenFormatError, "Fenstring not correct: #{fen}. Expected to match #{fen_pattern}" end reset_board! fen.split(' ').first.split('/').reverse.each_with_index do |rank, rank_index| file_index = 0 rank.split('').each do |file| if file.to_i > 0 file_index += file.to_i else @board[rank_index][file_index] = file file_index += 1 end end end new_game! @fen = fen send_position_to_engine end |