search.rb
# Moves a piece back to where it was
Moves a piece back to where it was
Moves a piece back to where it was
def unmake_move
    @mx = @mn
    @mn = @mx + 1 & 1
    @ply -= 1
    m = @mv[@on_mv[@ply]]
    @squares[m.from], @colors[m.from] = m.piece, @mx
    if m.target != EMPTY
      @squares[m.to], @colors[m.to] = m.target, @mn
    else
      @squares[m.to], @colors[m.to] = EMPTY, EMPTY
    end
    if m.piece == P
      if (m.to - m.from) % 10 != 0
        if m.target == EMPTY
          @squares[m.to - DIR[@mx]], @colors[m.to - DIR[@mx]] = P, @mn
        end
      elsif m.to > 90 || m.to < 30
        @squares[m.to] = P if @squares[m.to] == Q
      end
    elsif m.piece == K
      @kings[@mx] = m.from
      if m.to - m.from == 2
        @squares[m.to - 1], @colors[m.to - 1] = EMPTY, EMPTY
        @squares[m.to + 1], @colors[m.to + 1] = R, @mx
      elsif m.from - m.to == 2
        @squares[m.to + 1], @colors[m.to + 1] = EMPTY, EMPTY
        @squares[m.to - 2], @colors[m.to - 2] = R, @mx
      end
    end
    nil
  end
def unmake_move @mx = @mn @mn = @mx + 1 & 1 @ply -= 1 m = @mv [ @on_mv [ @ply ] ] @squares [ m . from ] , @colors [ m . from ] = m . piece , @mx if m . target != EMPTY @squares [ m . to ] , @colors [ m . to ] = m . target , @mn else @squares [ m . to ] , @colors [ m . to ] = EMPTY , EMPTY end if m . piece == P if ( m . to - m . from ) % 10 != 0 if m . target == EMPTY @squares [ m . to - DIR [ @mx ] ] , @colors [ m . to - DIR [ @mx ] ] = P , @mn end elsif m . to > 90 || m . to < 30 @squares [ m . to ] = P if @squares [ m . to ] == Q end elsif m . piece == K @kings [ @mx ] = m . from if m . to - m . from == 2 @squares [ m . to - 1 ] , @colors [ m . to - 1 ] = EMPTY , EMPTY @squares [ m . to + 1 ] , @colors [ m . to + 1 ] = R , @mx elsif m . from - m . to == 2 @squares [ m . to + 1 ] , @colors [ m . to + 1 ] = EMPTY , EMPTY @squares [ m . to - 2 ] , @colors [ m . to - 2 ] = R , @mx end end nil end
Moves a piece back to where it was
Moves a piece back to where it was