1
0
mirror of https://github.com/abakh/nbsdgames.git synced 2024-12-04 14:46:22 -05:00

replaced random() with rand()

This commit is contained in:
untakenstupidnick 2019-07-30 22:43:10 +04:30
parent a70209e5f3
commit f27eb28a8c
10 changed files with 52 additions and 53 deletions

View File

@ -187,13 +187,13 @@ void autoset(bool side){
byte l;
for(byte type=2;type<7;type++){
SetLocation:
realy=random()%10;
realx=random()%10;
realy=rand()%10;
realx=rand()%10;
invain=0;
SetDirection:
y=realy;
x=realx;
direction=random()%4;
direction=rand()%4;
for(l=0;(type != 6 && l<type) || (type==6 && l<3) ; l++){//there are two kinds of ship sized 3 tiles
if( y<0 || x<0 || y>=10 || x>=10 || game[side][y][x] != SEA ){
genocide(side,type);
@ -294,7 +294,7 @@ void set_the_board(bool side){
void turn_shift(void){
if(!multiplayer)
return;
char key = 'a'+(random()%ENGLISH_LETTERS);
char key = 'a'+(rand()%ENGLISH_LETTERS);
int input1,input2,input3;
input1=input2=input3=0;
erase();
@ -393,13 +393,13 @@ void decide(bool side){// sink_announce is responsible for unsetting the global
byte y,x,r;
Again:
if( firstinrowy == NOTHING ){
if( score[side] > 14 && score[side]<score[!side] && random()%2 ){
if( score[side] > 14 && score[side]<score[!side] && rand()%2 ){
cheat(side);
return;
}
while(1){
y = random()%10;
x = random()%10;
y = rand()%10;
x = rand()%10;
r = shoot(side,y,x);
if(r == 1){
firstinrowy=y;
@ -411,7 +411,7 @@ void decide(bool side){// sink_announce is responsible for unsetting the global
}
else if( lastinrowy ==NOTHING ){
if(goindirection == NOTHING)
goindirection = random()%4;
goindirection = rand()%4;
while(1){
y= firstinrowy;//we know there is hit already
x= firstinrowx;
@ -536,7 +536,7 @@ int main(void){
shotinvain=0;
sunk[0]=sunk[1]=0;
memset(game,SEA,200);
srandom(time(NULL)%UINT_MAX);
srand(time(NULL)%UINT_MAX);
erase();
set_the_board(0);

View File

@ -388,7 +388,7 @@ double decide(byte side,byte depth,byte s){//s is the type of move, it doesn't s
if(fj)
game[(toy+y)/2][(tox+x)/2]=captured;
if(besty<0 || adv>bestadv || (adv==bestadv && ( random()%2 )) ){
if(besty<0 || adv>bestadv || (adv==bestadv && ( rand()%2 )) ){
besty=y;
bestx=x;
besttoy=toy;
@ -537,7 +537,7 @@ int main(int argc,char** argv){
}
signal(SIGINT,sigint_handler);
Start:
srandom(time(NULL)%UINT_MAX);
srand(time(NULL)%UINT_MAX);
fill();
cy=cx=-1;
py=px=0;

View File

@ -112,7 +112,7 @@ bool issolved(char board[size][size],char check[size][size]){
}
void shuffle(char board[size][size]){
for(int m=0;m<1000;m++){
switch(random()%4){
switch(rand()%4){
case 0:
slide_one(board,ey,ex+1);
break;
@ -187,7 +187,7 @@ int main(int argc, char** argv){
}
}
signal(SIGINT,sigint_handler);
srandom(time(NULL)%UINT_MAX);
srand(time(NULL)%UINT_MAX);
initscr();
mousemask(ALL_MOUSE_EVENTS,NULL);
noecho();

View File

@ -314,9 +314,9 @@ int main(void){
}
}
srandom(time(NULL)%UINT_MAX);
byte ran1= random()%6;
byte ran2= random()%6;
srand(time(NULL)%UINT_MAX);
byte ran1= rand()%6;
byte ran2= rand()%6;
next1= colors[ran1]|jwstr[ran1];
next2= colors[ran2]|jwstr[ran2];
while(1){
@ -331,8 +331,8 @@ int main(void){
kx=-1;
board[jy][jx]=next2;
board[jy+ky][jx+kx]=next1;
ran1= random()%6;
ran2= random()%6;
ran1= rand()%6;
ran2= rand()%6;
next1=colors[ran1]|jwstr[ran1];
next2=colors[ran2]|jwstr[ran2];
falls = 1;

View File

@ -99,10 +99,10 @@ void shuffle(chtype board[size][size2]){
chtype a;
byte ay,ax,by,bx;
for(int m=0;m<n;m++){
ay=random()%size;
ax=random()%(size2);
by=random()%size;
bx=random()%(size2);
ay=rand()%size;
ax=rand()%(size2);
by=rand()%size;
bx=rand()%(size2);
a=board[ay][ax];
board[ay][ax]=board[by][bx];
board[by][bx]=a;
@ -171,7 +171,7 @@ int main(int argc, char** argv){
}
}
signal(SIGINT,sigint_handler);
srandom(time(NULL)%UINT_MAX);
srand(time(NULL)%UINT_MAX);
initscr();
mousemask(ALL_MOUSE_EVENTS,NULL);
noecho();

View File

@ -83,12 +83,12 @@ void drawmines(int sy,int sx,byte board[len][wid],bool mines[len][wid]){
}
//place mines
void mine(bool mines[len][wid]){
int y=random()%len;
int x=random()%wid;
int y=rand()%len;
int x=rand()%wid;
for(int n=0;n<mscount;n++){
while(mines[y][x]){
y=random()%len;
x=random()%wid;
y=rand()%len;
x=rand()%wid;
}
mines[y][x]=true;
}
@ -234,7 +234,7 @@ int main(int argc, char** argv){
}
else
mscount = len*wid/6;
srandom(time(NULL)%UINT_MAX);
srand(time(NULL)%UINT_MAX);
initscr();
mousemask(ALL_MOUSE_EVENTS,NULL);
noecho();
@ -322,7 +322,7 @@ int main(int argc, char** argv){
}
if(input=='\n' && board[py][px] < 9){
if(mines[py][px]){
switch( random()%3){
switch( rand()%3){
case 0:
strcpy(result,"You lost The Game.");
break;

View File

@ -11,7 +11,6 @@
#define LEFT 8
#define CROSSOVER 15
#define FILLED 16
#define SPILL 13
#define FLOWDELAY 5
#define DELAY 3
#define SAVE_TO_NUM 10
@ -207,16 +206,16 @@ void rectangle(void){
}
//this generates the pipes...
bitbox pipegen(void){
if(random()%17){//17 so all forms have the same chance
byte a=random()%4;
if(rand()%17){//17 so all forms have the same chance
byte a=rand()%4;
byte b;
do{
b=random()%4;
b=rand()%4;
}while(b==a);
return (1 << a) | ( 1 << b);
}
else
return CROSSOVER;//sum of all directions, the crossover
return CROSSOVER;//could not be generated like that
}
//.. and this is only for display
@ -364,7 +363,7 @@ int main(int argc, char** argv){
initscr();
mousemask(ALL_MOUSE_EVENTS,NULL);
time_t tstart , now, lasttime, giventime=len*wid/4;
srandom(time(NULL)%UINT_MAX);
srand(time(NULL)%UINT_MAX);
bitbox direction,board[len][wid];
int input;
byte foo;
@ -375,9 +374,9 @@ int main(int argc, char** argv){
score=0;
memset(error,0,150);
memset(board,0,len*wid);
fy=1+(random()%(len-2) );
fx=1+(random()%(wid-2) );
board[fy][fx]= 1 << (random()%4);
fy=1+(rand()%(len-2) );
fx=1+(rand()%(wid-2) );
board[fy][fx]= 1 << (rand()%4);
direction= board[fy][fx];
board[fy][fx]|=FILLED;
for(foo=0;foo<5;foo++)

View File

@ -94,10 +94,10 @@ void draw(int sy,int sx,bitbox board[len][wid]){
}
void make_maze(bitbox board[len][wid],point f){
byte ds_tried=0;
byte dnumber=random()%4;
byte dnumber=rand()%4;
bitbox direction= 1 << (dnumber);
while( direction == board[f.y][f.x] )
direction= 1 << (dnumber=random()%4);
direction= 1 << (dnumber=rand()%4);
point pt = MID(f.y,f.x,direction);
while(ds_tried<4){
@ -116,11 +116,11 @@ void make_maze(bitbox board[len][wid],point f){
void carrotify(bitbox board[len][wid],int count){
int y,x,c=count;
while(c){
y=random()%len;
x=random()%wid;
y=rand()%len;
x=rand()%wid;
while( board[y][x] & CARROT ){
y=random()%len;
x=random()%wid;
y=rand()%len;
x=rand()%wid;
}
board[y][x] |= CARROT;
c--;
@ -208,7 +208,7 @@ int main(int argc, char** argv){
int carrot_count= (len*wid)/50;
int carrots_found;
time_t tstart , now, giventime=len*wid/5;
srandom(time(NULL)%UINT_MAX);
srand(time(NULL)%UINT_MAX);
point start={0,0};
bitbox board[len][wid];
int sy,sx;

View File

@ -119,9 +119,9 @@ void color_sos(char board[len][wid],byte colored[len][wid], int y , int x ,bool
}
}
void randmove(int* y,int* x,byte* c){
*y=random()%len;
*x=random()%wid;
*c=random()%2;
*y=rand()%len;
*x=rand()%wid;
*c=rand()%2;
}
int decide ( char board[len][wid],byte colored[len][wid], byte depth , byte side ){ //the move is imaginary if side is negative
int adv,bestadv;
@ -265,7 +265,7 @@ int main(int argc, char** argv){
return EXIT_FAILURE;
}
}
srandom(time(NULL)%UINT_MAX);
srand(time(NULL)%UINT_MAX);
int input;
initscr();
mousemask(ALL_MOUSE_EVENTS,NULL);

View File

@ -105,7 +105,7 @@ bool fill_with(char board[s][s],char fillwith){//returns 1 on failure
if (tries>s)
return 1;
for(byte y=0;y<s;y++){//there should be only one occurence of a number in a row, and this function makes use of this fact to improve generation speed
firstx=x=random()%s;
firstx=x=rand()%s;
while(1){
if(!board[y][x]){
board[y][x]=fillwith;
@ -179,13 +179,13 @@ void justfill(char board[s][s]){//sometimes fill() gets too much , and you just
}
}
for(byte n=0;n<s*2;n++)//randomize
swap(board,int2sgn(1+(random()%s)),int2sgn(1+(random()%s)) );
swap(board,int2sgn(1+(rand()%s)),int2sgn(1+(rand()%s)) );
}
void mkpuzzle(char board[s][s],char empty[s][s],char game[s][s]){//makes a puzzle to solve
byte y,x;
for(y=0;y<s;y++){
for(x=0;x<s;x++){
if( !(random()%diff) ){
if( !(rand()%diff) ){
empty[y][x]=board[y][x];
game[y][x]=board[y][x];
}
@ -327,7 +327,7 @@ int main(int argc,char** argv){
noecho();
cbreak();
keypad(stdscr,1);
srandom(time(NULL)%UINT_MAX);
srand(time(NULL)%UINT_MAX);
if( has_colors() ){
start_color();
use_default_colors();