Nasal-Interpreter/test/wavecollapse.nas

104 lines
2.6 KiB
Plaintext
Raw Normal View History

2022-04-10 15:34:20 +08:00
# wave collapse function 2022/4/10
# by ValKmjolnir
srand();
2022-04-10 16:47:27 +08:00
var interval=1/60;
2022-04-10 15:34:20 +08:00
var table=[
# c ,w,a,s,d
["═",0,1,0,1],
2022-04-13 19:08:06 +08:00
["═",0,1,0,1],
["═",0,1,0,1],
2022-04-10 15:34:20 +08:00
["║",1,0,1,0],
["╔",0,0,1,1],
["╗",0,1,1,0],
["╚",1,0,0,1],
["╝",1,1,0,0],
2022-04-10 16:47:27 +08:00
# ["╠",1,0,1,1],
# ["╣",1,1,1,0],
# ["╦",0,1,1,1],
# ["╩",1,1,0,1],
# ["╬",1,1,1,1],
2022-04-10 15:34:20 +08:00
[" ",0,0,0,0],
[" ",0,0,0,0],
[" ",0,0,0,0],
[" ",0,0,0,0],
[" ",0,0,0,0],
[" ",0,0,0,0]
];
var map=func(){
2022-04-10 16:47:27 +08:00
var (vec,x,s)=(nil,nil,size(table));
var generator=func(){
2022-04-10 15:34:20 +08:00
var tmp=[];
foreach(var elem;table)
2022-04-10 16:47:27 +08:00
if(elem[1]==vec[0][0][3] and elem[2]==0)
2022-04-10 15:34:20 +08:00
append(tmp,elem);
2022-04-10 16:47:27 +08:00
vec[1][0]=tmp[rand()*size(tmp)];
2022-04-10 15:34:20 +08:00
for(var j=1;j<x;j+=1){
2022-04-10 16:47:27 +08:00
if(vec[0][j][3]==0 and vec[1][j-1][4]==0 and rand()>0.5){
vec[1][j]=table[-1];
continue;
}
tmp=[];
2022-04-10 15:34:20 +08:00
foreach(var elem;table)
2022-04-10 16:47:27 +08:00
if(elem[2]==vec[1][j-1][4] and elem[1]==vec[0][j][3]){
if((j==x-1 and elem[4]==0) or j<x-1)
append(tmp,elem);
}
vec[1][j]=tmp[rand()*size(tmp)];
2022-04-10 15:34:20 +08:00
}
}
return {
2022-04-10 16:47:27 +08:00
new:func(_x=10){
x=_x;
vec=[[],[]];
for(var i=0;i<2;i+=1){
2022-04-10 15:34:20 +08:00
setsize(vec[i],x);
2022-04-10 16:47:27 +08:00
for(var j=0;j<x;j+=1)
vec[i][j]=table[-1];
2022-04-10 15:34:20 +08:00
}
2022-04-10 16:47:27 +08:00
var tmp=[];
foreach(var elem;table)
if(elem[1]==0 and elem[2]==0)
append(tmp,elem);
vec[0][0]=tmp[rand()*size(tmp)];
2022-04-10 15:34:20 +08:00
for(var i=1;i<x;i+=1){
2022-04-10 16:47:27 +08:00
tmp=[];
2022-04-10 15:34:20 +08:00
foreach(var elem;table)
2022-04-10 16:47:27 +08:00
if(elem[2]==vec[0][i-1][4] and elem[1]==0){
if((i==x-1 and elem[4]==0) or i<x-1)
append(tmp,elem);
}
2022-04-10 15:34:20 +08:00
vec[0][i]=tmp[rand()*size(tmp)];
}
2022-04-10 16:47:27 +08:00
me.print(0);
generator();
2022-04-10 15:34:20 +08:00
},
2022-04-10 16:47:27 +08:00
print:func(index){
var str="";
foreach(var _x;vec[index])
str~=_x[0];
str~="\n";
2022-04-10 15:34:20 +08:00
print(str);
},
next:func(){
2022-04-10 16:47:27 +08:00
(vec[0],vec[1])=(vec[1],vec[0]);
generator();
2022-04-10 15:34:20 +08:00
}
}
}();
2022-04-13 19:08:06 +08:00
if(os.platform()=="windows")
system("chcp 65001");
map.new(80);
for(var iter=0;iter<100;iter+=1){
2022-04-10 16:47:27 +08:00
map.print(1);
2022-04-10 15:34:20 +08:00
map.next();
2022-04-10 16:47:27 +08:00
unix.sleep(interval);
2022-04-10 15:34:20 +08:00
}