如果骰子落在某个数字上,骰子滚动程序不会将我的分数重置为0

时间:2019-02-10 22:51:44

标签: c++

我已经基本完成了程序,并且运行良好,但是当我同时为播放器和AI滚动并滚动1(无效数字)时,并没有将我的底池设置为0。它只是保持运行数字并继续前进。这里有我不理解的逻辑吗? PS-它不会让我发布整个代码,所以我只发布了一部分

import { createStore, applyMiddleware, combineReducers } from 'redux';
import { batchedSubscribe } from 'redux-batched-subscribe';
import thunk from 'redux-thunk';
import reduxMulti from 'redux-multi';
import logger from 'redux-logger';

import auth from './reducers/auth';

const rootReducer = combineReducers({
  auth,
});

const createStoreWithMiddleware = applyMiddleware(thunk, reduxMulti, logger)(
  createStore
);

const createStoreWithBatching = batchedSubscribe(fn => fn())(
  createStoreWithMiddleware
);

export default createStoreWithBatching(rootReducer);

1 个答案:

答案 0 :(得分:1)

IMHO (count < 20 && AI < 50)不正确,对于您指定的规格,它应该为((count < 20) || (AI < 50))。请参考以下代码进行进一步修改。

#include <iostream>
#include <cstdio>
#include <cstdlib>

using std::cout;
using std::endl;

int diceRoll() { return rand() % 6 + 1; }

int aiTurn(int AI) {
    int pot = 0;
    int AI_value_to_be_returned = 0;
    //char choice;
    cout << "AI turn\n";
    //While loop until AI turn reaches 20 or score >=50

    int count = 0;
    while ((count < 20) || (AI < 50)) {
        int rollValue = diceRoll();
    printf("dice roll {%d}\n", rollValue);
        //Incrementing turn

        //Checking for bust
        if (rollValue == 1) {
            cout << "Die Roll " << rollValue << " : BUST" << endl << endl;
            pot = 0;
        AI_value_to_be_returned = AI;
        cout << "Die Roll " << rollValue << " : BUST Pot Value = " << pot << endl;
        break;
        } else {
            pot += rollValue;
            cout << "Die Roll : " << rollValue << "   Pot : " << pot << endl;
            AI += rollValue;
        }
    count++;
    }
    return AI_value_to_be_returned;
}

int main() { printf("aiTurn {%d}\n", aiTurn(50)); return 0; }

输出:

AI turn
dice roll {2}
Die Roll : 2   Pot : 2
dice roll {5}
Die Roll : 5   Pot : 7
dice roll {4}
Die Roll : 4   Pot : 11
dice roll {2}
Die Roll : 2   Pot : 13
dice roll {6}
Die Roll : 6   Pot : 19
dice roll {2}
Die Roll : 2   Pot : 21
dice roll {5}
Die Roll : 5   Pot : 26
dice roll {1}
Die Roll 1 : BUST

Die Roll 1 : BUST Pot Value = 0