mo

· · 个人记录

#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#include<stdlib.h>
using namespace std;
int num[19][109][109],tj[19],td[19],h,l,ml,bs,tx[4]= {0,0,-1,1},ty[4]= {-1,1,0,0},dd[20][20];
int jc(int x,int y) {
    for(int i=1; i<=ml; i++) {
        if(num[i][x][y]) return i;
    }
    return 0;
}
void sc(int x,int y,int z) {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x);
    int xx=num[x][y][z];
    if(!xx) {
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
        cout<<"   ";
    } else if(xx<10) cout<<"0"<<xx<<" ";
    else if(xx<100)cout<<xx<<" ";
    else if(xx<1000) cout<<xx/100<<"e ";
    else if(xx<10000) cout<<xx/1000<<"k ";
    else if(xx<100000) cout<<xx/10000<<"w ";
    else cout<<"ju ";
}
void ss(int x,int y) {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x);
    int xx=y;
    if(!xx) {
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
        cout<<"   ";
    } else {
        int z=log10(y);

        cout<<(int)(y/pow(10,z))<<char('a'+z)<<" ";
    }
}
void cls() {
    COORD pos;
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    pos.X = 0;
    pos.Y = 0;
    SetConsoleCursorPosition(hOut, pos);
}
int main() {
    srand(time(0));
    cin>>h>>l>>ml;
    for(int i=1; i<=ml; i++)num[i][rand()%h][rand()%l]++;
    while(1) {
        cls();
        bs++;
        for(int i=1; i<=ml; i++) tj[i]=td[i]=0;
        for(int i=0; i<h; i++) {
            for(int j=0; j<l; j++) {
                int x=jc(i,j);
                if(jc(i,j)) {
                    num[x][i][j]+=rand()%(int)ceil(sqrt(bs));
                    tj[jc(i,j)]+=num[jc(i,j)][i][j];
                    td[jc(i,j)]++;
                }
                sc(x,i,j);
            }
            cout<<endl;
        }
        for(int i=1; i<=ml; i++) ss(i,tj[i]),ss(i,td[i]);
        for(int i=1; i<=sqrt(bs); i++) {
            int x=rand()%h,y=rand()%l,s=rand()%4;
            int xx=x+tx[s],yy=y+ty[s];
            if(xx<0||xx>=h||yy<0||yy>=l||!jc(x,y)) continue;
            int z=jc(x,y),z1=jc(xx,yy);
            if(dd[z][z1]) continue;
            if(z==z1||z1==0) {
                int k=num[z][xx][yy]+num[z][x][y];
                num[z][xx][yy]=ceil(1.0*k/50*49);
                num[z][x][y]=ceil(1.0*k/50);
            } else {
                if(num[z1][xx][yy]>num[z][x][y]) continue;
                int k=num[z][x][y]-num[z1][xx][yy];
                num[z][xx][yy]=ceil(1.0*k/50*49);
                num[z][x][y]=ceil(1.0*k/50);
                num[z1][xx][yy]=0;
            }
        }
        if(bs%30==0) {
            int x=rand()%ml+1,y=rand()%ml+1;
            while(y==x) y=rand()%ml+1;
            dd[x][y]^=1,dd[y][x]^=1;
        }
        if(_kbhit()) {
            char x=_getch();
            if(x==32) {
                while(1) {
                    if(_kbhit()) {
                        char x=_getch();
                        if(x==32) break;
                    }
                }
            }
        }
    }
    return 0;
}
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
int mp[209][209],tx[4]= {1,-1,0,0},ty[4]= {0,0,-1,1};
void cls() {
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD topLeft = {0, 0};
    SetConsoleCursorPosition(hConsole, topLeft);
}
struct zd {
    int fx,x,y,fl,tm;
} d[1000009];
int nd=0;
void jd(int fx,int x,int y){
    d[++nd]={fx,x,y,1,clock()};
}
int main() {
    srand(time(0));
    int fx=rand()%20,sx=rand()%20,fy=rand()%20,sy=rand()%20,fms=0,sms=0;
    while(1) {
        cls();
        for(int i=0; i<=20; i++) for(int j=0; j<=20; j++) mp[i][j]=0;
        for(int i=1;i<=nd;i++) if(d[i].fl)mp[d[i].x][d[i].y]=3;
        mp[fx][fy]=1,mp[sx][sy]=2;
        for(int i=0; i<=19; i++) {
            for(int j=0; j<=19; j++) {
                if(mp[i][j]==1) cout<<'#';
                if(mp[i][j]==2) cout<<'%';
                if(mp[i][j]==3) cout<<'o';
                if(!mp[i][j])cout<<'.';
            }
            cout<<endl;
        }
        if(_kbhit()) {
            int x=_getch();
            if(x=='0')fms^=1;
            if(x=='q')sms^=1;
            if(x==224) {
                x=_getch();
                if(!fms) {
                    if(x==75) fy--;
                    if(x==77) fy++;
                    if(x==72) fx--;
                    if(x==80) fx++;
                } else {
                    if(x==75) jd(2,fx,fy);
                    if(x==77) jd(3,fx,fy);
                    if(x==72) jd(1,fx,fy);
                    if(x==80) jd(0,fx,fy);
                }
            } else {
                if(!sms) {
                    if(x==97) sy--;
                    if(x==100) sy++;
                    if(x==119) sx--;
                    if(x==115) sx++;
                }else{
                    if(x==97) jd(2,sx,sy);
                    if(x==100) jd(3,sx,sy);
                    if(x==119) jd(1,sx,sy);
                    if(x==115) jd(0,sx,sy);
                }
            }
        }
        sx=(sx+20)%20,sy=(sy+20)%20;
        fx=(fx+20)%20,fy=(fy+20)%20;
        for(int i=1;i<=nd;i++){
            if(d[i].fl&&clock()-d[i].tm>100){
                d[i].x+=tx[d[i].fx];
                d[i].y+=ty[d[i].fx];
                if(d[i].x<0||d[i].x>19||d[i].y<0||d[i].y>19)d[i].fl=0;
                d[i].tm=clock();
                if(d[i].x==fx&&d[i].y==fy){
                    cout<<"\n玩家2赢了";
                    return 0; 
                }
                if(d[i].x==sx&&d[i].y==sy){
                    cout<<"\n玩家1赢了";
                    return 0; 
                }
            }
        }
    }
    return 0;
}