Unfinished ca editor

A forum where anything goes. 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. This is the forum for "non-academic" content.
Post Reply
User avatar
pzq_alex
Posts: 792
Joined: May 1st, 2021, 9:00 pm
Location: tell me if you know

Unfinished ca editor

Post by pzq_alex » November 10th, 2022, 4:17 am

Code: Select all

#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <curses.h>

struct cell
{
    int state;
};
char statechar[3] = {' ', 'o'};

const size_t N = 20;
cell patt[N][N];

inline void upd()
{
    int x, y; getyx(stdscr, y, x);
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
        {
            move(i, j);
            addch(statechar[patt[i][j].state]);
        }
    refresh();
    move(y, x);
}

inline cell nxt(cell a, cell b, cell c, cell d, cell e, cell f, cell g, cell h, cell i)
{
    int cnt = int(a.state) + b.state + c.state + d.state + e.state + f.state + g.state + h.state + i.state;
    if (e.state) return (cell){cnt == 3 || cnt == 4};
    else return (cell){cnt == 3};
}

int main()
{
    initscr(); cbreak(); noecho();
    nonl(); intrflush(stdscr, FALSE); keypad(stdscr, TRUE);

    int x = 0, y = 0; int gen = 0;
    bool repl = false;
    while (true)
    {
        move(y, x);
        upd();

        int c = getch();
        if (c == ERR)
            continue;

        if (repl)
        {
            if (c == 'b' || c == '.' || isspace(c))
                patt[y][x].state = false;
            else
                patt[y][x].state = true;
            repl = false;
            continue;
        }

        if (c == 'q') break;
        if (c == 'h') if (x > 0) x--;
        if (c == 'l') if (x < N - 1) x++;
        if (c == 'j') if (y < N - 1) y++;
        if (c == 'k') if (y > 0) y--;
        if (c == 'r') repl = true;
    }

    nocbreak(); echo();
    endwin();
}
\sum_{n=1}^\infty H_n/n^2 = \zeta(3)

How much of current CA technology can I redevelop "on a desert island"?

Citation needed
Posts: 173
Joined: April 1st, 2021, 1:03 am

Re: Unfinished ca editor

Post by Citation needed » November 10th, 2022, 11:39 pm

The computer programs should be posted here. By the way, if you really wish to talk to ColorfulGalaxy without me as a medium, please beware that he has gone to another website. He is still a Life enthusiast at the moment.

Post Reply