跳到正文

剪贴板

剪贴板 fuzkimal

原文
剪贴板信息

剪贴板信息

收录
更新
C++
#include <bits/stdc++.h>
using namespace std;
char a[1005][1005];//'b'board 'w'window '#'wall '.'ground
char rec[1005][1005];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int tx=1,ty=1,rx=1,ry=1;
int n,m;
int bl=2,p=2;
bool t=0;
int tr=0,rr=0;
int rp=0,tp=0;
void mat(int bl){
    if (bl==2) cout<<"healthy";
    if (bl==1) cout<<"hurt";
    cout<<endl;
}
void print(){
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            if (i==tx&&j==ty) cout<<'t';
            else if (i==rx&&j==ry) cout<<'r';
            else cout<<a[i][j];
        }
        cout<<endl;
    }
}
int c2i(char c){
    if (c=='w') return 3;
    if (c=='s') return 2;
    if (c=='a') return 1;
    return 0;
}
void move_(char op,bool t){
    if (t){
        tx+=dx[c2i(op)];
        ty+=dy[c2i(op)];
    }
    else{
        rx+=dx[c2i(op)];
        ry+=dy[c2i(op)];
    }
}
void move_in(char op,bool t){
    if (op=='n'){
        p--;
        return;
    }
    if (t){
        tx+=dx[c2i(op)];
        ty+=dy[c2i(op)];
        if (tx==rx&&ty==ry){
            bl--;
            tx-=dx[c2i(op)];
            ty-=dy[c2i(op)];
            tr++;
            rp++;
            p=0;
        }
        p--;
        if (a[tx][ty]=='w'){
            p-=2;
            tx+=dx[c2i(op)];
            ty+=dy[c2i(op)];
        }
        if (a[tx][ty]=='B'){
            a[tx][ty]='.';
            tx-=dx[c2i(op)];
            ty-=dy[c2i(op)];
            p-=2;
        }
    }
    else{
        if (op=='e'){
            for (int i=0;i<4;i++){
                if (a[rx+dx[i]][ry+dy[i]]=='b'){
                    a[rx+dx[i]][ry+dy[i]]='B';
                }
            }
        }
        else{
            rx+=dx[c2i(op)];
            ry+=dy[c2i(op)];
            if (a[rx][ry]=='w'||a[rx][ry]=='B'){
                rx+=dx[c2i(op)];
                ry+=dy[c2i(op)];
            }
        }
        p--;
    }
    return;
}
int main(){
    //freopen("game.txt","r",stdin);
    cin>>n>>m;
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            cin>>rec[i][j];

        }
    }
    while (1){
        for (int i=1;i<=n;i++){
            for (int j=1;j<=m;j++){
                a[i][j]=rec[i][j];
            }
        }
        char op;
        while (1){
            print();
            cin>>op;
            if (op=='!') break;
            move_(op,1);
        }
        while (1){
            print();
            cin>>op;
            if (op=='!') break;
            move_(op,0);
        }
        int turn=1;
        while (bl>0){
            cout<<"turn:"<<turn<<endl;
            mat(bl);
            print();
            if (p<=0) {
                if (t==0){
                    if (tr>0){
                        tr--;
                        t=0;
                        p=2+rp;
                        rp=0;
                        turn++;
                    }
                    else{
                        t=1;
                        p=3+tp;
                        tp=0;
                    }
                }
                else{
                    if (rr>0){
                        rr--;
                        t=1;
                        p=3+tp;
                        tp=0;
                    }
                    else{
                        t=0;
                        p=2+rp;
                        rp=0;
                        turn++;
                    }
                }
            }
            if (t==0) cout<<'r';
            else cout<<'t';
            cout<<':'<<p<<endl;
            cin>>op;
            move_in(op,t);
        }
        cout<<turn<<endl;
        bl=2;
        tx=ty=rx=ry=1;
    }
    return 0;
}
/*
14 41
.........................................
.#...........###.##b#.#####.####w###.....
.#....#......#........#............#..#..
.#....b......b...#....#..####b###..#..#..
.b....#.....##...##...w..#............b..
.##.###...............#..b.....#......#..
.............##b#.....#######..#.........
................#........................
..##b####.......#.......####w#########...
........#.....#b#.......#............#...
...#....b.....#.............###b#....#...
...#b####.....####b#....#.......#....b...
........#...............#.......b....#...
........................##############...
*/