I need an stdin symmetry to enumerate all three-boxes collisions in Stopbox - call it 3box-collision-stdin.
FWKnightship wrote: January 23rd, 2025, 6:19 am
Here is a C++ script that generates basiknight collisions continuously, can be used as the input of apgsearch stdin symmetry:
I tried to modify the script to use boxes instead of basiknights, but I doesn't know much of C++ :
Code: Select all
#include <iostream>
#include <vector>
#include <string>
#include <random>
#include <cstring>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
char grid[60][60];
char get(int x, int y)
{
if (x < 0 || x >= 60) return -1;
if (y < 0 || y >= 60) return -1;
return grid[y][x];
}
vector<string> v{
"BBB$BA.$BBB$",
"BBB$BBA$BBB$",
"BBB$BAB$B.B$"",
"BBB$BBB$BAB$",
"BBB$.AB$BBB$",
"BBB$ABB$BBB$",
"B.B$BAB$BBB$",
"BAB$BBB$BBB$"
};
void clear()
{
memset(grid, 0, sizeof(grid));
}
void putship(int x, int y, int i)
{
int xx = x, yy = y;
for (char c: v[i])
{
if (c == '$')
{
xx = x;
++yy;
}
else
{
grid[yy][xx] = c - '0';
++xx;
}
}
}
bool check(int x, int y, int sz)
{
for (int i = 0; i < sz; ++i)
{
for (int j = 0; j < sz; ++j)
{
if (get(x+i, y+j) != 0) return 0;
}
}
return 1;
}
const char* s = "bo";
bool output_line(char *ss)
{
vector<pair<char, int>> vv;
for (int i = 0; i < 60; ++i)
{
if (vv.empty() || vv.back().first != ss[i])
{
vv.emplace_back(ss[i], 1);
}
else
{
vv.back().second++;
}
}
if (vv.back().first == 0) vv.pop_back();
for (auto p : vv)
{
if (p.second > 1) printf("%d", p.second);
putchar(s[p.first]);
}
return !vv.empty();
}
signed main(int argc, char **argv)
{
mt19937 rand(time(0));
while (1)
{
clear();
int w = rand() % 15 + 5;
for (int i = 0; i < w; ++i)
{
for (int j = 0; j < 10; ++j)
{
int x = rand() % 60, y = rand() % 60;
if (check(x, y, 9))
{
putship(x+3, y+3, rand() % (v.size()));
goto W;
}
}
break;
W:;
}
puts("x = 60, y = 60, rule = Stopbox");
for (int i = 0; i < 60; ++i)
{
output_line(grid[i]);
putchar(i == 59 ? '!' : '$');
}
putchar('\n');
}
}
Need to enforce the script to use only 3 boxes, or change the name of the symmetry to box-collision-stdin.