/ Vijos / 讨论 / 游戏 /

取火柴

#include <iostream>
#include <windows.h>
#include <cstdlib>
#include <time.h>
using namespace std;
int main(){
    MessageBox(NULL,"游戏规则:\n1.每次只能取1~4根火柴\n2.取到最后一根为败","游戏规则",MB_OK);
    srand(time(0));
    int n=rand()%49+1;
    while(n>0){
        cout << "目前还有火柴" << n << "根\n";
        cout << "=============================\n";
        cout << "你想拿走多少根火柴:";
        int x;
        cin >> x;
        if(x<1||x>4){
            cout << "你犯规了,you lose!!!\n";
            system("pause");
            exit(3322234);
        }
        n-=x;
        if(n<=0){
            cout << "你拿了最后一根!!you lose!!!\n";
            system("pause");
            exit(2356487);
        }
        int x2=rand()%4+1;
        n-=x2;
        cout << "电脑想拿走" << x2 << "根火柴\n";
        cout << "============================\n";
    }
    cout << "you win!!!^_^\n";
    system("pause");
    return 0;
}

7 条评论

  • @ 2020-04-27 21:01:00


    • @ 2020-05-16 18:25:22

      ??????????

  • @ 2020-03-30 13:55:45
  • @ 2020-03-30 13:53:20

    如果你能赢这个AI,我马上去造神贴。

    #include <iostream>
    #include <windows.h>
    #include <cstdlib>
    #include <time.h>
    using namespace std;
    int main(){
        MessageBox(NULL,"游戏规则:\n1.每次只能取1~4根火柴\n2.取到最后一根为败","游戏规则",MB_OK);
        srand(time(0));
        int n=rand()%85+6;
        if(n%5!=1)n+=(6-n%5)%5;
        while(n>0){
            cout << "目前还有火柴" << n << "根\n";
            cout << "=============================\n";
            cout << "你想拿走多少根火柴:";
            int x,flg=0;
            cin >> x;
            if(x<1||x>4){
                cout << "你犯规了,爪巴!!!\n";
                system("pause");
                exit(19260817);
            }
            n-=x;
            if(n<=0){
                cout << "你拿了最后一根!!爪巴!!!\n";
                system("pause");
                exit(114514);
            }
            int x2=5-x;
            n-=x2;
            cout << "电脑想拿走" << x2 << "根火柴\n";
            cout << "============================\n";
        }
        cout << "you win!!!^_^\n";
        system("pause");
        return 0;
    }
    
    • @ 2020-04-15 10:34:34

      根据数学,这个赢不了,我不去做不可能完成的事,浪费时间

  • @ 2020-03-20 16:50:45

    这很正常啊

  • @ 2020-03-20 16:50:30

    你们发运行结果干嘛??

  • @ 2020-03-08 08:58:34

    偶的运行结果:

    目前还有火柴6根

    你想拿走多少根火柴:1

    电脑想拿走1根火柴

    目前还有火柴4根

    你想拿走多少根火柴:3

    电脑想拿走2根火柴

    you win!!!^_^
    请按任意键继续. . .


    Process exited with return value 0
    Press any key to continue . . .

  • @ 2020-03-08 08:48:04

    运行结果:

    There are still matches42root

    How many matches do you want to take:3

    The computer wants to take it away1Root matches

    There are still matches38root

    How many matches do you want to take:1

    The computer wants to take it away3Root matches

    There are still matches34root

    How many matches do you want to take:4

    The computer wants to take it away4Root matches

    There are still matches26root

    How many matches do you want to take:2

    The computer wants to take it away4Root matches

    There are still matches20root

    How many matches do you want to take:3

    The computer wants to take it away4Root matches

    There are still matches13root

    How many matches do you want to take:4

    The computer wants to take it away1Root matches

    There are still matches8root

    How many matches do you want to take:3

    The computer wants to take it away2Root matches

    There are still matches3root

    How many matches do you want to take:3
    You took the last one!!you lose!!!
    Press any key to continue . . .

  • 1