public WireWorld(int width, int height, int scale) : base(width, height, scale) { Name = "Wire World"; ColorMapping.Add(WIRE, Color.Yellow); ColorMapping.Add(POSITIVE, Color.Red); ColorMapping.Add(NEGATIVE, Color.Blue); ActionMapping.Add(POSITIVE, (x, y) => { Write(x, y, NEGATIVE); }); ActionMapping.Add(NEGATIVE, (x, y) => { Write(x, y, WIRE); }); ActionMapping.Add(WIRE, (x, y) => { int numPositive = 0; for (int xx = x - 1; xx <= x + 1; xx++) { for (int yy = y - 1; yy <= y + 1; yy++) { if (Read(xx, yy) == POSITIVE) { numPositive++; } } } if (numPositive == 1 || numPositive == 2) { Write(x, y, POSITIVE); } }); LeftPlace = WIRE; Refreshrate = 6; }
public GameOfLife(int width, int height, int scale) : base(width, height, scale) { Name = "Conways Game of Life"; ColorMapping.Add(NULL, Color.Black); ColorMapping.Add(ALIVE, Color.White); ActionMapping.Add(ALIVE, (x, y) => { int numNeighbors = GetNumNeightbors(x, y); if(numNeighbors < 2 || numNeighbors > 3) { Write(x, y, NULL); } }); ActionMapping.Add(NULL, (x, y) => { if (GetNumNeightbors(x, y) == 3) { Write(x, y, ALIVE); } }); LeftPlace = ALIVE; Refreshrate = 30; }
public SandBox(int width, int height, int scale) : base(width, height, scale) { Name = "Sandbox Simulation"; LeftPlace = SOLID; //define colours ColorMapping.Add(SAND, Color.Yellow); ColorMapping.Add(SOLID, Color.Gray); ColorMapping.Add(WATER, Color.Blue); ColorMapping.Add(ICE, Color.LightSkyBlue); ColorMapping.Add(SMOKE, Color.LightGray); //define callbacks ActionMapping.Add(SAND, (x, y) => { if (Read(x, y + 1) != NULL) { if (Read(x, y + 1) == WATER) { Write(x, y + 1, SAND); Write(x, y, WATER); return; } if (Random.Chance(0.5f)) { if (Read(x + 1, y + 1) == NULL) { //prevent clipping through diagonals if (Read(x + 1, y) == NULL) { //move right down Write(x + 1, y + 1, Read(x, y)); Write(x, y, NULL); } } } else { if (Read(x - 1, y + 1) == NULL) { //prevent clipping through diagonals if (Read(x - 1, y) == NULL) { //move left down Write(x - 1, y + 1, Read(x, y)); Write(x, y, NULL); } } } } else { //move downwards Write(x, y + 1, Read(x, y)); Write(x, y, NULL); } }); ActionMapping.Add(ICE, (x, y) => { if (Read(x, y + 1) != NULL) { if (Read(x, y + 1) == WATER) { Write(x, y + 1, ICE); Write(x, y, ICE); return; } if (Random.Chance(0.5f)) { if (Read(x + 1, y + 1) == NULL) { //prevent clipping through diagonals if (Read(x + 1, y) == NULL) { //move right down Write(x + 1, y + 1, Read(x, y)); Write(x, y, NULL); } } } else { if (Read(x - 1, y + 1) == NULL) { //prevent clipping through diagonals if (Read(x - 1, y) == NULL) { //move left down Write(x - 1, y + 1, Read(x, y)); Write(x, y, NULL); } } } } else { //move downwards Write(x, y + 1, Read(x, y)); Write(x, y, NULL); } }); ActionMapping.Add(WATER, (x, y) => { if (Read(x, y + 1) != NULL) { if (Read(x + 1, y + 1) == NULL) { //prevent clipping through diagonals if (Read(x + 1, y) == NULL) { //move right down Write(x + 1, y + 1, Read(x, y)); Write(x, y, NULL); } } else { if (Random.Chance(0.5f)) { if (Read(x + 1, y) == NULL) { //move right Write(x + 1, y, Read(x, y)); Write(x, y, NULL); } } else { if (Read(x - 1, y) == NULL) { //move left Write(x - 1, y, Read(x, y)); Write(x, y, NULL); } } } } else { //move downwards Write(x, y + 1, Read(x, y)); Write(x, y, NULL); } }); ActionMapping.Add(SMOKE, (x, y) => { if (Read(x, y - 1) != NULL) { if (Random.Chance(0.5f)) { if (Read(x + 1, y) == NULL) { //move right Write(x + 1, y, Read(x, y)); Write(x, y, NULL); } } else { if (Read(x - 1, y) == NULL) { //move left Write(x - 1, y, Read(x, y)); Write(x, y, NULL); } } } else { //move up Write(x, y - 1, Read(x, y)); Write(x, y, NULL); } }); FillBorder(SOLID); }
public WirererWorlder(int width, int height, int scale) : base(width, height, scale) { Name = "Wire World"; ColorMapping.Add(WIRE, Color.Yellow); ColorMapping.Add(POSITIVE, Color.Red); ColorMapping.Add(NEGATIVE, Color.Blue); ColorMapping.Add(DEADWIRE, Color.DarkOrange); ColorMapping.Add(WIRECUTTER, Color.Green); ColorMapping.Add(BRIDGE, Color.Gray); ColorMapping.Add(PULSAR, Color.LightCoral); ActionMapping.Add(POSITIVE, (x, y) => { Write(x, y, NEGATIVE); }); ActionMapping.Add(NEGATIVE, (x, y) => { Write(x, y, WIRE); }); ActionMapping.Add(WIRE, (x, y) => { int numPositive = GetNumNeightbors(x, y, POSITIVE); if (numPositive == 1 || numPositive == 2) { Write(x, y, POSITIVE); } }); ActionMapping.Add(BRIDGE, (x, y) => { List <Tuple <Point, Point> > tuples = new List <Tuple <Point, Point> >(); Point top = new Point(x, y - 1); Point bottom = new Point(x, y + 1); Point left = new Point(x - 1, y); Point right = new Point(x + 1, y); tuples.Add(new Tuple <Point, Point>(top, bottom)); tuples.Add(new Tuple <Point, Point>(bottom, top)); tuples.Add(new Tuple <Point, Point>(left, right)); tuples.Add(new Tuple <Point, Point>(right, left)); foreach (Tuple <Point, Point> tuple in tuples) { if (Read(tuple.Item1) == POSITIVE) { Point delta = tuple.Item2 - tuple.Item1; delta.X /= 2; delta.Y /= 2; Point newPoint = tuple.Item1 + delta; while (Read(newPoint) == BRIDGE) { newPoint += delta; } if (Read(newPoint) == WIRE) { Write(newPoint, POSITIVE); } } } }); ActionMapping.Add(WIRECUTTER, (x, y) => { List <Tuple <Point, Point> > tuples = new List <Tuple <Point, Point> >(); Point top = new Point(x, y - 1); Point bottom = new Point(x, y + 1); Point left = new Point(x - 1, y); Point right = new Point(x + 1, y); tuples.Add(new Tuple <Point, Point>(top, bottom)); tuples.Add(new Tuple <Point, Point>(bottom, top)); tuples.Add(new Tuple <Point, Point>(left, right)); tuples.Add(new Tuple <Point, Point>(right, left)); foreach (Tuple <Point, Point> tuple in tuples) { if (Read(tuple.Item1) == POSITIVE) { if (Read(tuple.Item2) == WIRE) { Write(tuple.Item2, DEADWIRE); } else if (Read(tuple.Item2) == DEADWIRE) { Write(tuple.Item2, WIRE); } } } }); ActionMapping.Add(PULSAR, (x, y) => { if (Read(x + 1, y) == WIRE) { Write(x + 1, y, POSITIVE); } if (Read(x - 1, y) == WIRE) { Write(x - 1, y, POSITIVE); } if (Read(x, y + 1) == WIRE) { Write(x, y + 1, POSITIVE); } if (Read(x, y - 1) == WIRE) { Write(x, y - 1, POSITIVE); } }); LeftPlace = WIRE; Refreshrate = 6; }