Margolus Critters rule for Ready

A forum for topics that don't fit elsewhere. Introduce yourselves to other members of the forums, discuss how your name evolves when written out in the Game of Life, or just tell us how you found it. Forum rules still apply.
Post Reply
User avatar
PHPBB12345
Posts: 1150
Joined: August 5th, 2015, 11:55 pm
Contact:

Margolus Critters rule for Ready

Post by PHPBB12345 »

Code: Select all

<?xml version="1.0"?>
<VTKFile type="ImageData" version="0.1" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor">
  <RD format_version="4">
    <description>
    </description>
    <rule name="Critters" type="kernel" neighborhood_type="vertex" neighborhood_range="1" neighborhood_weight="laplacian">
      <kernel number_of_chemicals="1" block_size_x="1" block_size_y="1" block_size_z="1">
        __kernel void rd_compute(__global float *a_in,__global float *a_out)
        {
            const int x = get_global_id(0);
            const int y = get_global_id(1);
            const int X = get_global_size(0);
            const int Y = get_global_size(1);
            const int i_here = X*y + x;
            const float val_table[16] = {
                2.0f, 2.0f, 2.0f, 0.0f, 2.0f, 0.0f, 0.0f, 0.0f,
                0.0f, 2.0f, 2.0f, 0.0f, 2.0f, 0.0f, 2.0f, 0.0f
            };
            int alt_x, alt_y, bits;
            float c1 = a_in[i_here], c_out;
            bool phase = (c1 > 0.5f && c1 < 1.5f) || c1 > 2.5f;
            if ((phase && ((x & 1) == 1)) ||
               (!phase && ((x & 1) == 0)))
            {
                alt_x = ((x+1) & (X-1)); // wrap (assumes X is a power of 2)
            }
            else
            {
                alt_x = ((x-1+X) & (X-1));
            }
            if ((phase && ((y & 1) == 1)) ||
               (!phase && ((y & 1) == 0)))
            {
                alt_y = ((y+1) & (Y-1)); // wrap (assumes Y is a power of 2)
            }
            else
            {
                alt_y = ((y-1+Y) & (Y-1));
            }
            bits = (c1 > 1.5f ? 8 : 0) |
                (a_in[X*y + alt_x] > 1.5f ? 4 : 0) |
                (a_in[X*alt_y + x] > 1.5f ? 2 : 0) |
                (a_in[X*alt_y + alt_x] > 1.5f ? 1 : 0);
        
            c_out = val_table[bits];
            if (!phase)
                c_out += 1.0f;
            a_out[i_here] = c_out;
        }
        
      </kernel>
    </rule>
    <initial_pattern_generator apply_when_loading="false" zero_first="true">
    </initial_pattern_generator>
    <render_settings>
      <surface_color r="1" g="1" b="1">
      </surface_color>
      <color_low r="0.2" g="0.2" b="0.2">
      </color_low>
      <color_high r="1" g="1" b="1">
      </color_high>
      <show_color_scale value="false">
      </show_color_scale>
      <show_multiple_chemicals value="true">
      </show_multiple_chemicals>
      <active_chemical value="a">
      </active_chemical>
      <low value="1">
      </low>
      <high value="2">
      </high>
      <vertical_scale_1D value="30">
      </vertical_scale_1D>
      <vertical_scale_2D value="15">
      </vertical_scale_2D>
      <contour_level value="0.25">
      </contour_level>
      <use_wireframe value="false">
      </use_wireframe>
      <show_cell_edges value="true">
      </show_cell_edges>
      <show_bounding_box value="true">
      </show_bounding_box>
      <slice_3D value="true">
      </slice_3D>
      <slice_3D_axis value="z">
      </slice_3D_axis>
      <slice_3D_position value="0.5">
      </slice_3D_position>
      <show_displacement_mapped_surface value="false">
      </show_displacement_mapped_surface>
      <color_displacement_mapped_surface value="true">
      </color_displacement_mapped_surface>
      <use_image_interpolation value="false">
      </use_image_interpolation>
      <timesteps_per_render value="1">
      </timesteps_per_render>
      <show_phase_plot value="false">
      </show_phase_plot>
      <phase_plot_x_axis value="a">
      </phase_plot_x_axis>
      <phase_plot_y_axis value="b">
      </phase_plot_y_axis>
      <phase_plot_z_axis value="c">
      </phase_plot_z_axis>
    </render_settings>
  </RD>
  <ImageData WholeExtent="0 127 0 127 0 0" Origin="0 0 0" Spacing="1 1 1">
  <Piece Extent="0 127 0 127 0 0">
    <PointData>
      <DataArray type="Float32" Name="a" format="binary" RangeMin="0" RangeMax="0">
        AgAAAACAAAAAAAAANAAAADQAAAA=eJztwQEBAAAAgJD+r+4ICgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYgAAAAXic7cEBAQAAAICQ/q/uCAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGIAAAAE=
      </DataArray>
    </PointData>
    <CellData>
    </CellData>
  </Piece>
  </ImageData>
</VTKFile>
http://conwaylife.com/forums/viewtopic.php?f=11&t=3896
http://conwaylife.com/forums/viewtopic.php?f=11&t=3918
http://conwaylife.com/forums/viewtopic.php?f=11&t=3925
wildmyron
Posts: 1572
Joined: August 9th, 2013, 12:45 am
Location: Western Australia

Re: Margolus Critters rule for Ready

Post by wildmyron »

Nicely done. Seems to work correctly from my brief exploration, but Ready is a bit trickier to exchange patterns with due to the format. It would be nice to have the Generate Pattern function do something (perhaps create a random pattern in a small area of the grid).

A note for others who would like to try this out: If the generation is even then you should draw with states 0 and 2 and conversely if the generation is odd then you should draw with states 1 and 3. If you don't then the pattern won't evolve according to Critters rules. You may also prefer to use a step of 2 to avoid the background flicker.
The 5S project (Smallest Spaceships Supporting Specific Speeds) is now maintained by speedydelete.

Semi-active here - recovering from a severe case of LWTDS.
User avatar
PHPBB12345
Posts: 1150
Joined: August 5th, 2015, 11:55 pm
Contact:

Re: Margolus Critters rule for Ready

Post by PHPBB12345 »

wildmyron wrote:Nicely done. Seems to work correctly from my brief exploration, but Ready is a bit trickier to exchange patterns with due to the format. It would be nice to have the Generate Pattern function do something (perhaps create a random pattern in a small area of the grid).

A note for others who would like to try this out: If the generation is even then you should draw with states 0 and 2 and conversely if the generation is odd then you should draw with states 1 and 3. If you don't then the pattern won't evolve according to Critters rules. You may also prefer to use a step of 2 to avoid the background flicker.

Code: Select all

<?xml version="1.0"?>
<VTKFile type="ImageData" version="0.1" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor">
  <RD format_version="4">
    <description>
    </description>
    <rule name="Critters" type="kernel" neighborhood_type="vertex" neighborhood_range="1" neighborhood_weight="laplacian">
      <kernel number_of_chemicals="2" block_size_x="1" block_size_y="1" block_size_z="1">
        __kernel void rd_compute(__global float *a_in,__global float *b_in,__global float *a_out,__global float *b_out)
        {
            const int x = get_global_id(0);
            const int y = get_global_id(1);
            const int X = get_global_size(0);
            const int Y = get_global_size(1);
            const int i_here = X*y + x;
            const float val_table[16] = {
                1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
                0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f
            };
            int alt_x, alt_y, bits;
            float c1 = a_in[i_here], c_out;
            bool phase = b_in[i_here] > 0.5f;
            if ((phase && ((x & 1) == 1)) ||
                (!phase && ((x & 1) == 0)))
            {
                alt_x = ((x+1) & (X-1)); // wrap (assumes X is a power of 2)
            }
            else
            {
                alt_x = ((x-1+X) & (X-1));
            }
            if ((phase && ((y & 1) == 1)) ||
                (!phase && ((y & 1) == 0)))
            {
                alt_y = ((y+1) & (Y-1)); // wrap (assumes Y is a power of 2)
            }
            else
            {
                alt_y = ((y-1+Y) & (Y-1));
            }
            bits = (c1 > 0.5f ? 8 : 0) |
                (a_in[X*y + alt_x] > 0.5f ? 4 : 0) |
                (a_in[X*alt_y + x] > 0.5f ? 2 : 0) |
                (a_in[X*alt_y + alt_x] > 0.5f ? 1 : 0);
        
            if (phase)
                c_out = val_table[15 - bits];
            else
                c_out = 1.0f - val_table[bits];
        
            a_out[i_here] = c_out;
            b_out[i_here] = phase ? 0.0f : 1.0f;
        }
        
      </kernel>
    </rule>
    <initial_pattern_generator apply_when_loading="true">
      <overlay chemical="a">
        <overwrite>
        </overwrite>
        <white_noise low="0" high="1">
        </white_noise>
        <rectangle>
          <point3D x="0.45" y="0.45" z="0">
          </point3D>
          <point3D x="0.55" y="0.55" z="1">
          </point3D>
        </rectangle>
      </overlay>
    </initial_pattern_generator>
    <render_settings>
      <surface_color r="1" g="1" b="1">
      </surface_color>
      <color_low r="0" g="0" b="0">
      </color_low>
      <color_high r="1" g="1" b="1">
      </color_high>
      <show_color_scale value="false">
      </show_color_scale>
      <show_multiple_chemicals value="false">
      </show_multiple_chemicals>
      <active_chemical value="a">
      </active_chemical>
      <low value="0">
      </low>
      <high value="1">
      </high>
      <vertical_scale_1D value="30">
      </vertical_scale_1D>
      <vertical_scale_2D value="15">
      </vertical_scale_2D>
      <contour_level value="0.25">
      </contour_level>
      <use_wireframe value="false">
      </use_wireframe>
      <show_cell_edges value="false">
      </show_cell_edges>
      <show_bounding_box value="true">
      </show_bounding_box>
      <slice_3D value="true">
      </slice_3D>
      <slice_3D_axis value="z">
      </slice_3D_axis>
      <slice_3D_position value="0.5">
      </slice_3D_position>
      <show_displacement_mapped_surface value="false">
      </show_displacement_mapped_surface>
      <color_displacement_mapped_surface value="true">
      </color_displacement_mapped_surface>
      <use_image_interpolation value="false">
      </use_image_interpolation>
      <timesteps_per_render value="1">
      </timesteps_per_render>
      <show_phase_plot value="false">
      </show_phase_plot>
      <phase_plot_x_axis value="a">
      </phase_plot_x_axis>
      <phase_plot_y_axis value="b">
      </phase_plot_y_axis>
      <phase_plot_z_axis value="c">
      </phase_plot_z_axis>
    </render_settings>
  </RD>
  <ImageData WholeExtent="0 255 0 255 0 0" Origin="0 0 0" Spacing="1 1 1">
  <Piece Extent="0 255 0 255 0 0">
    <PointData>
      <DataArray type="Float32" Name="a" format="binary" RangeMin="0" RangeMax="0">
        CAAAAACAAAAAAAAANAAAADQAAAA0AAAANAAAADQAAAA0AAAANAAAADQAAAA=eJztwQEBAAAAgJD+r+4ICgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYgAAAAXic7cEBAQAAAICQ/q/uCAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGIAAAAF4nO3BAQEAAACAkP6v7ggKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABiAAAABeJztwQEBAAAAgJD+r+4ICgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYgAAAAXic7cEBAQAAAICQ/q/uCAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGIAAAAF4nO3BAQEAAACAkP6v7ggKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABiAAAABeJztwQEBAAAAgJD+r+4ICgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYgAAAAXic7cEBAQAAAICQ/q/uCAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGIAAAAE=
      </DataArray>
      <DataArray type="Float32" Name="b" format="binary" RangeMin="0" RangeMax="0">
        CAAAAACAAAAAAAAANAAAADQAAAA0AAAANAAAADQAAAA0AAAANAAAADQAAAA=eJztwQEBAAAAgJD+r+4ICgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYgAAAAXic7cEBAQAAAICQ/q/uCAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGIAAAAF4nO3BAQEAAACAkP6v7ggKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABiAAAABeJztwQEBAAAAgJD+r+4ICgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYgAAAAXic7cEBAQAAAICQ/q/uCAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGIAAAAF4nO3BAQEAAACAkP6v7ggKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABiAAAABeJztwQEBAAAAgJD+r+4ICgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYgAAAAXic7cEBAQAAAICQ/q/uCAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGIAAAAE=
      </DataArray>
    </PointData>
    <CellData>
    </CellData>
  </Piece>
  </ImageData>
</VTKFile>
wildmyron
Posts: 1572
Joined: August 9th, 2013, 12:45 am
Location: Western Australia

Re: Margolus Critters rule for Ready

Post by wildmyron »

Thanks, it works well.

Edit: For anybody else trying this out -
The representation of states has changed in this version - only 0 and 1 for Off and On. No need to be careful about which state to use when editing. And the flicker has been removed by representing On cells with Off cells in odd generations and vice versa.
The 5S project (Smallest Spaceships Supporting Specific Speeds) is now maintained by speedydelete.

Semi-active here - recovering from a severe case of LWTDS.
Post Reply