Permalink
Browse files

Added Brainf-ck Extended Type 3 commands to interpreter to speed up g…

…eneration.

Added results of "cats are evil".
  • Loading branch information...
1 parent 96926bb commit 1e5c22a87a4aecfb324b458e091a027b169ee301 @primaryobjects committed Feb 17, 2013
@@ -116,6 +116,23 @@ public Interpreter(string programCode, Func<byte> input, Action<byte> output)
this.m_InstructionSet.Add('.', () => { if (!m_ExitLoop) this.m_Output(this.m_Memory[this.m_DataPointer]); });
this.m_InstructionSet.Add(',', () => { if (!m_ExitLoop) this.m_Memory[this.m_DataPointer] = this.m_Input(); });
+ this.m_InstructionSet.Add('0', () => { if (!m_ExitLoop) this.m_Memory[this.m_DataPointer] = 0; });
+ this.m_InstructionSet.Add('1', () => { if (!m_ExitLoop) this.m_Memory[this.m_DataPointer] = 16; });
+ this.m_InstructionSet.Add('2', () => { if (!m_ExitLoop) this.m_Memory[this.m_DataPointer] = 32; });
+ this.m_InstructionSet.Add('3', () => { if (!m_ExitLoop) this.m_Memory[this.m_DataPointer] = 48; });
+ this.m_InstructionSet.Add('4', () => { if (!m_ExitLoop) this.m_Memory[this.m_DataPointer] = 64; });
+ this.m_InstructionSet.Add('5', () => { if (!m_ExitLoop) this.m_Memory[this.m_DataPointer] = 80; });
+ this.m_InstructionSet.Add('6', () => { if (!m_ExitLoop) this.m_Memory[this.m_DataPointer] = 96; });
+ this.m_InstructionSet.Add('7', () => { if (!m_ExitLoop) this.m_Memory[this.m_DataPointer] = 112; });
+ this.m_InstructionSet.Add('8', () => { if (!m_ExitLoop) this.m_Memory[this.m_DataPointer] = 128; });
+ this.m_InstructionSet.Add('9', () => { if (!m_ExitLoop) this.m_Memory[this.m_DataPointer] = 144; });
+ this.m_InstructionSet.Add('A', () => { if (!m_ExitLoop) this.m_Memory[this.m_DataPointer] = 160; });
+ this.m_InstructionSet.Add('B', () => { if (!m_ExitLoop) this.m_Memory[this.m_DataPointer] = 176; });
+ this.m_InstructionSet.Add('C', () => { if (!m_ExitLoop) this.m_Memory[this.m_DataPointer] = 192; });
+ this.m_InstructionSet.Add('D', () => { if (!m_ExitLoop) this.m_Memory[this.m_DataPointer] = 208; });
+ this.m_InstructionSet.Add('E', () => { if (!m_ExitLoop) this.m_Memory[this.m_DataPointer] = 224; });
+ this.m_InstructionSet.Add('F', () => { if (!m_ExitLoop) this.m_Memory[this.m_DataPointer] = 240; });
+
this.m_InstructionSet.Add('[', () =>
{
if (!m_ExitLoop && this.m_Memory[this.m_DataPointer] == 0)
@@ -31,5 +31,45 @@ public static string ConvertDoubleArrayToBF(double[] array)
return sb.ToString();
}
+
+ /// <summary>
+ /// Convert a genome (array of doubles) into a Brainfuck program (using Extended Type 3).
+ /// </summary>
+ /// <param name="array">Array of double</param>
+ /// <returns>string - Brainfuck program</returns>
+ public static string ConvertDoubleArrayToBFExtendedType3(double[] array)
+ {
+ StringBuilder sb = new StringBuilder();
+
+ foreach (double d in array)
+ {
+ if (d <= 0.1225) sb.Append('>');
+ else if (d <= 0.245) sb.Append('<');
+ else if (d <= 0.3675) sb.Append('+');
+ else if (d <= 0.49) sb.Append('-');
+ else if (d <= 0.6125) sb.Append('.');
+ else if (d <= 0.735) sb.Append(',');
+ else if (d <= 0.8575) sb.Append('[');
+ else if (d <= 0.98) sb.Append(']');
+ else if (d <= 0.98133) sb.Append('0');
+ else if (d <= 0.98266) sb.Append('1');
+ else if (d <= 0.98399) sb.Append('2');
+ else if (d <= 0.98533) sb.Append('3');
+ else if (d <= 0.98666) sb.Append('4');
+ else if (d <= 0.98799) sb.Append('5');
+ else if (d <= 0.98933) sb.Append('6');
+ else if (d <= 0.99066) sb.Append('7');
+ else if (d <= 0.99199) sb.Append('8');
+ else if (d <= 0.99333) sb.Append('9');
+ else if (d <= 0.99466) sb.Append('A');
+ else if (d <= 0.99599) sb.Append('B');
+ else if (d <= 0.99733) sb.Append('C');
+ else if (d <= 0.99866) sb.Append('D');
+ else if (d <= 0.99999) sb.Append('E');
+ else sb.Append('F');
+ }
+
+ return sb.ToString();
+ }
}
}
Oops, something went wrong.

0 comments on commit 1e5c22a

Please sign in to comment.