35 lines
1.3 KiB
C#
35 lines
1.3 KiB
C#
using System;
|
|
using System.Text.RegularExpressions;
|
|
using GameOfLife.Entities;
|
|
|
|
namespace GameOfLife.IO
|
|
{
|
|
public class ApgcodePatternMetaData : PatternMetadata
|
|
{
|
|
private static readonly Regex HeaderRegex = new Regex(@"(?<prefix>\w{2})(?<suffix>.*)");
|
|
public ApgcodePatternMetaData(string header, string name=null)
|
|
{
|
|
if (name != null)
|
|
Name = name;
|
|
var match = HeaderRegex.Match(header);
|
|
Type = Prefix(match.Groups["prefix"].Value);
|
|
Comments = new [] { match.Groups["suffix"].Value };
|
|
}
|
|
|
|
private PatternType Prefix(string prefix)
|
|
{
|
|
switch (prefix)
|
|
{
|
|
case "xs": return PatternType.StillLife;
|
|
case "xp": return PatternType.Oscillator;
|
|
case "xq": return PatternType.Spaceship;
|
|
case "yl": return PatternType.Periodic;
|
|
case "methuselah" : return PatternType.Methuselah;
|
|
case "messless" : return PatternType.Diehard;
|
|
case "megasized" : return PatternType.Megasized;
|
|
default:
|
|
throw new ArgumentException($"Unknown prefix: {prefix}");
|
|
}
|
|
}
|
|
}
|
|
} |