search.rb
# Adds a move object to the move list.
#   adds respective ordering score and separate index for sorting by score, determines
#   changes to game related variables that the move causes, so that the data stored in the
#   move object will reflect the current gamestate once the move has been made
Adds a move object to the move list.
adds respective ordering score and separate index for sorting by score, determines
changes to game related variables that the move causes, so that the data stored in the
move object will reflect the current gamestate once the move has been made
Adds a move object to the move list . adds respective ordering score and separate index for sorting by score determines changes to game related variables that the move causes so that the data stored in the move object will reflect the current gamestate once the move has been made
def add_move(from, to, piece, capture = false)
    idx = @on_mv[@ply - 1]
    c, t, h, e, f = @mv[idx].castling, @squares[to], 0, 0, @mx == BLACK ? @mv[idx].full_moves + 1 : @mv[idx].full_moves
    if capture
      s = (t == EMPTY ? 100000 : ((t + 1) * 100) + 99999 - piece)
      if t == R
        if RQSC[@mn] == to && c[QSC[@mn]] == 1
          c -= REMOVE_QSC[@mn]
        elsif RKSC[@mn] == to && c[KSC[@mn]] == 1
          c -= REMOVE_KSC[@mn]
        end
      end
    else
      s = (@rpt[@root][piece][to] * (@ppt[@ply][piece][to] + @pt[piece][to])) / (@rtn[@root][to] * @ptn[piece][to])
      if piece == @mv[@k1[@ply]].piece && to == @mv[@k1[@ply]].to
        s += 5000
      elsif piece == @mv[@k2[@ply]].piece && to == @mv[@k2[@ply]].to
        s += 3500
      end
      if piece == P
        e = from + DIR[@mx] if (from - to).abs == 20
      else
        h = @mv[idx].half_moves + 1
      end
    end
    if piece == R
      c -= REMOVE_QSC[@mx] if c[QSC[@mx]] == 1 && RQSC[@mx] == from
      c -= REMOVE_KSC[@mx] if c[KSC[@mx]] == 1 && RKSC[@mx] == from
    elsif piece == K
      c -= REMOVE_QSC[@mx] if c[QSC[@mx]] == 1
      c -= REMOVE_KSC[@mx] if c[KSC[@mx]] == 1
    end
    @mv_idx[@mv_n] = @mv_n
    @mv[@mv_n] = Move.new(from, to, piece, t, @mn, c, e, h, f)
    @mv_score[@mv_n] = s
    @mv_n += 1
    nil
  end
def add_move ( from , to , piece , capture = false ) idx = @on_mv [ @ply - 1 ] c , t , h , e , f = @mv [ idx ] . castling , @squares [ to ] , 0 , 0 , @mx == BLACK ? @mv [ idx ] . full_moves + 1 : @mv [ idx ] . full_moves if capture s = ( t == EMPTY ? 100000 : ( ( t + 1 ) * 100 ) + 99999 - piece ) if t == R if RQSC [ @mn ] == to && c [ QSC [ @mn ] ] == 1 c -= REMOVE_QSC [ @mn ] elsif RKSC [ @mn ] == to && c [ KSC [ @mn ] ] == 1 c -= REMOVE_KSC [ @mn ] end end else s = ( @rpt [ @root ] [ piece ] [ to ] * ( @ppt [ @ply ] [ piece ] [ to ] + @pt [ piece ] [ to ] ) ) / ( @rtn [ @root ] [ to ] * @ptn [ piece ] [ to ] ) if piece == @mv [ @k1 [ @ply ] ] . piece && to == @mv [ @k1 [ @ply ] ] . to s += 5000 elsif piece == @mv [ @k2 [ @ply ] ] . piece && to == @mv [ @k2 [ @ply ] ] . to s += 3500 end if piece == P e = from + DIR [ @mx ] if ( from - to ) . abs == 20 else h = @mv [ idx ] . half_moves + 1 end end if piece == R c -= REMOVE_QSC [ @mx ] if c [ QSC [ @mx ] ] == 1 && RQSC [ @mx ] == from c -= REMOVE_KSC [ @mx ] if c [ KSC [ @mx ] ] == 1 && RKSC [ @mx ] == from elsif piece == K c -= REMOVE_QSC [ @mx ] if c [ QSC [ @mx ] ] == 1 c -= REMOVE_KSC [ @mx ] if c [ KSC [ @mx ] ] == 1 end @mv_idx [ @mv_n ] = @mv_n @mv [ @mv_n ] = Move . new ( from , to , piece , t , @mn , c , e , h , f ) @mv_score [ @mv_n ] = s @mv_n += 1 nil end
Adds a move object to the move list.
Adds a move object to the move list .
from
<not_specific>
to
<not_specific>
piece
<not_specific>
capture
<not_specific>