Commit 9d514d22 authored by Laurent Montel's avatar Laurent Montel 😁

Port KRandom::random

parent c7ee76a6
......@@ -10,6 +10,7 @@
#include "KBlocksDummyAI.h"
#include <QtGlobal>
#include <QRandomGenerator>
KBlocksDummyAI::KBlocksDummyAI()
{
......@@ -48,8 +49,9 @@ void KBlocksDummyAI::think(GamePlayer_ActionList *actionList)
return;
}
int rotation = qrand() % (mRotateCount + 1) - mRotateCount / 2;
int motionx = qrand() % (mFieldWidth + 1) - mFieldWidth / 2;
auto random = QRandomGenerator::global();
int rotation = random->bounded(mRotateCount + 1) - mRotateCount / 2;
int motionx = random->bounded(mFieldWidth + 1) - mFieldWidth / 2;
if (rotation > 0) {
for (int i = 0; i < rotation; i++) {
......
......@@ -8,6 +8,7 @@
* (at your option) any later version. *
***************************************************************************/
#include "KBlocksGameLogic.h"
#include <QRandomGenerator>
KBlocksGameLogic::KBlocksGameLogic(int capacity, bool record)
......@@ -177,7 +178,7 @@ int KBlocksGameLogic::updateGame(int *lineList)
lineList[i] = tmpTotal;
if ((mPunishFlag) && (tmpPunishCount > 0)) {
int punishSeed = qrand() % 256;
int punishSeed = QRandomGenerator::global()->bounded(256);
for (int j = 0; j < i; j++) {
maGameList[j]->punishGame(tmpPunishCount, punishSeed);
}
......@@ -283,9 +284,8 @@ void KBlocksGameLogic::createSingleGames(int gameCount)
int *seedList = new int[mGameCount];
if (mGameSeed < 0) {
mGameSeed = -mGameSeed;
qsrand(mGameSeed);
for (int i = 0; i < mGameCount; i++) {
seedList[i] = qrand() % 256;
seedList[i] = QRandomGenerator::global()->bounded(256);
}
} else {
for (int i = 0; i < mGameCount; i++) {
......
......@@ -10,6 +10,7 @@
#include "KBlocksPieceGenerator.h"
#include <QtGlobal>
#include <QRandomGenerator>
#include <stdio.h>
#include "KBlocksPiece.h"
......@@ -28,10 +29,9 @@ KBlocksPieceGenerator::~KBlocksPieceGenerator()
void KBlocksPieceGenerator::genList(int seed)
{
qsrand(seed);
auto random = QRandomGenerator::global();
for (int i = 0; i < maxCapacity; i++) {
maPieceList[i] = qrand() % PieceType_Detail_Max_Count;
maPieceList[i] = random->bounded(PieceType_Detail_Max_Count);
}
pieceIndex = 0;
......
......@@ -11,6 +11,7 @@
#include "KBlocksField.h"
#include "KBlocksPiece.h"
#include "utils.h"
#include <QRandomGenerator>
KBlocksSingleGame::KBlocksSingleGame(int gameIndex, int fieldWidth, int fieldHeight, int showPieceCount, int messagePoolSize)
{
......@@ -124,11 +125,11 @@ int KBlocksSingleGame::punishGame(int lineCount, int punishSeed)
mpGameRecorder->append(mGameIndex, RecordDataType_PunishLineSeed, punishSeed);
}
qsrand(punishSeed);
int punishIndex = 0;
auto random = QRandomGenerator::global();
for (int i = 0; i < lineCount; i++) {
setCurrentPiece(0, -1, 0);
punishIndex = qrand() % width;
punishIndex = random->bounded(width);
mpField->addPunishLine(lineCount, punishIndex);
}
......
......@@ -25,6 +25,7 @@
#include <QPixmapCache>
#include <QPointer>
#include <QLabel>
#include <QRandomGenerator>
#define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API
#include <libkdegamesprivate/kgamethemeselector.h>
......@@ -101,8 +102,7 @@ void KBlocksWin::addScore(int gameIndex, int lineCount)
void KBlocksWin::startGame()
{
qsrand(time(0));
mpGameLogic->setGameSeed(qrand());
mpGameLogic->setGameSeed(QRandomGenerator::global()->generate());
if (mpGameLogic->startGame(mGameCount)) {
mpPlayManager->startGame();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment