Conway's Game of Life

· · 个人记录

#include<bits/stdc++.h>
#include <stdio.h>
#include <conio.h>
#include<windows.h>
#define LL long long
#define F(x,y,z) for(int x=y;x<=z;++x)
#define D(x,y,z) for(int x=y;x>=z;--x)
using namespace std;
const int M=20;
int n,m;
int a[1100][1100],b[1100][1100];
const int fx[8]={-1,-1,-1,0,0,1,1,1};
const int fy[8]={-1,0,1,-1,1,-1,0,1};
LL Min(LL x,LL y){return x<y?x:y;}
LL Max(LL x,LL y){return x>y?x:y;}
LL R(){
    LL ans=0,f=1;char c=' ';
    for(;c<'0'||c>'9';c=getchar()) if (c=='-') f=-1;
    for(;c>='0'&&c<='9';c=getchar()) ans=ans*10+c-'0';
    return ans*f;
}
void Next(){
    F(i,1,1000)F(j,1,1000){
        b[i][j]=0;
        F(k,0,7)
            b[i][j]+=a[i+fx[k]][j+fy[k]];
    }
    F(i,1,1000)F(j,1,1000){
        if (b[i][j]==3){a[i][j]=1;continue;}
        if (b[i][j]!=2) a[i][j]=0;
    }
}
void prr(){
    system("cls");
    F(i,M,M+M){
        F(j,M,M+M+M+M) putchar(a[i][j]?('*'):(' '));
        putchar('\n');
    }
}
void Mk(int x,int y){
    a[x][y]=1;
    a[x][y+1]=1;
    a[x+1][y]=1;
    a[x+1][y+2]=1;
    a[x+2][y+1]=1;
}
int main(){
    //srand(time(0));F(i,M,M+M)F(j,M,M+M+M) a[i][j]=rand()<8000;
    //Mk(M+M-5,M+M-5);
    while(1){

        Next();
        while((rand()*1000+rand())%10000000<9999999); a[rand()%80+2][rand()%80+2]=1;
        prr();
        char c='!';
        if (kbhit())c=getch();
        if (c == ' '){
            while (!kbhit()){
                if (GetAsyncKeyState(1)){
                    POINT a;
                    GetCursorPos(&a);
                }
            }
            //Sleep(500);
            if (kbhit())c=getch();
        }

        Sleep(100);
    }
    return 0;
}
#include<bits/stdc++.h>
#include <stdio.h>
#include <conio.h>
#include<windows.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0) //必要的,我是背下来的   
using namespace std;  
int main(){  
while(1){  
POINT a;
GetCursorPos(&a);//鼠标坐标 
HWND hhh=GetForegroundWindow();//屏幕坐标 
ScreenToClient(hhh,&a);//系统转屏幕 
cout<<a.x;
cout<<(GetAsyncKeyState(1)&0x8000);//鼠标点击,左1右2 
Sleep(20);
system("cls");
}  
return 0;  
}