1
0
mirror of https://github.com/abakh/nbsdgames.git synced 2025-01-03 14:56:23 -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; byte l;
for(byte type=2;type<7;type++){ for(byte type=2;type<7;type++){
SetLocation: SetLocation:
realy=random()%10; realy=rand()%10;
realx=random()%10; realx=rand()%10;
invain=0; invain=0;
SetDirection: SetDirection:
y=realy; y=realy;
x=realx; 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 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 ){ if( y<0 || x<0 || y>=10 || x>=10 || game[side][y][x] != SEA ){
genocide(side,type); genocide(side,type);
@ -294,7 +294,7 @@ void set_the_board(bool side){
void turn_shift(void){ void turn_shift(void){
if(!multiplayer) if(!multiplayer)
return; return;
char key = 'a'+(random()%ENGLISH_LETTERS); char key = 'a'+(rand()%ENGLISH_LETTERS);
int input1,input2,input3; int input1,input2,input3;
input1=input2=input3=0; input1=input2=input3=0;
erase(); erase();
@ -393,13 +393,13 @@ void decide(bool side){// sink_announce is responsible for unsetting the global
byte y,x,r; byte y,x,r;
Again: Again:
if( firstinrowy == NOTHING ){ 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); cheat(side);
return; return;
} }
while(1){ while(1){
y = random()%10; y = rand()%10;
x = random()%10; x = rand()%10;
r = shoot(side,y,x); r = shoot(side,y,x);
if(r == 1){ if(r == 1){
firstinrowy=y; firstinrowy=y;
@ -411,7 +411,7 @@ void decide(bool side){// sink_announce is responsible for unsetting the global
} }
else if( lastinrowy ==NOTHING ){ else if( lastinrowy ==NOTHING ){
if(goindirection == NOTHING) if(goindirection == NOTHING)
goindirection = random()%4; goindirection = rand()%4;
while(1){ while(1){
y= firstinrowy;//we know there is hit already y= firstinrowy;//we know there is hit already
x= firstinrowx; x= firstinrowx;
@ -536,7 +536,7 @@ int main(void){
shotinvain=0; shotinvain=0;
sunk[0]=sunk[1]=0; sunk[0]=sunk[1]=0;
memset(game,SEA,200); memset(game,SEA,200);
srandom(time(NULL)%UINT_MAX); srand(time(NULL)%UINT_MAX);
erase(); erase();
set_the_board(0); 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) if(fj)
game[(toy+y)/2][(tox+x)/2]=captured; 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; besty=y;
bestx=x; bestx=x;
besttoy=toy; besttoy=toy;
@ -537,7 +537,7 @@ int main(int argc,char** argv){
} }
signal(SIGINT,sigint_handler); signal(SIGINT,sigint_handler);
Start: Start:
srandom(time(NULL)%UINT_MAX); srand(time(NULL)%UINT_MAX);
fill(); fill();
cy=cx=-1; cy=cx=-1;
py=px=0; 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]){ void shuffle(char board[size][size]){
for(int m=0;m<1000;m++){ for(int m=0;m<1000;m++){
switch(random()%4){ switch(rand()%4){
case 0: case 0:
slide_one(board,ey,ex+1); slide_one(board,ey,ex+1);
break; break;
@ -187,7 +187,7 @@ int main(int argc, char** argv){
} }
} }
signal(SIGINT,sigint_handler); signal(SIGINT,sigint_handler);
srandom(time(NULL)%UINT_MAX); srand(time(NULL)%UINT_MAX);
initscr(); initscr();
mousemask(ALL_MOUSE_EVENTS,NULL); mousemask(ALL_MOUSE_EVENTS,NULL);
noecho(); noecho();

View File

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

View File

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

View File

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

View File

@ -11,7 +11,6 @@
#define LEFT 8 #define LEFT 8
#define CROSSOVER 15 #define CROSSOVER 15
#define FILLED 16 #define FILLED 16
#define SPILL 13
#define FLOWDELAY 5 #define FLOWDELAY 5
#define DELAY 3 #define DELAY 3
#define SAVE_TO_NUM 10 #define SAVE_TO_NUM 10
@ -207,16 +206,16 @@ void rectangle(void){
} }
//this generates the pipes... //this generates the pipes...
bitbox pipegen(void){ bitbox pipegen(void){
if(random()%17){//17 so all forms have the same chance if(rand()%17){//17 so all forms have the same chance
byte a=random()%4; byte a=rand()%4;
byte b; byte b;
do{ do{
b=random()%4; b=rand()%4;
}while(b==a); }while(b==a);
return (1 << a) | ( 1 << b); return (1 << a) | ( 1 << b);
} }
else else
return CROSSOVER;//sum of all directions, the crossover return CROSSOVER;//could not be generated like that
} }
//.. and this is only for display //.. and this is only for display
@ -364,7 +363,7 @@ int main(int argc, char** argv){
initscr(); initscr();
mousemask(ALL_MOUSE_EVENTS,NULL); mousemask(ALL_MOUSE_EVENTS,NULL);
time_t tstart , now, lasttime, giventime=len*wid/4; time_t tstart , now, lasttime, giventime=len*wid/4;
srandom(time(NULL)%UINT_MAX); srand(time(NULL)%UINT_MAX);
bitbox direction,board[len][wid]; bitbox direction,board[len][wid];
int input; int input;
byte foo; byte foo;
@ -375,9 +374,9 @@ int main(int argc, char** argv){
score=0; score=0;
memset(error,0,150); memset(error,0,150);
memset(board,0,len*wid); memset(board,0,len*wid);
fy=1+(random()%(len-2) ); fy=1+(rand()%(len-2) );
fx=1+(random()%(wid-2) ); fx=1+(rand()%(wid-2) );
board[fy][fx]= 1 << (random()%4); board[fy][fx]= 1 << (rand()%4);
direction= board[fy][fx]; direction= board[fy][fx];
board[fy][fx]|=FILLED; board[fy][fx]|=FILLED;
for(foo=0;foo<5;foo++) 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){ void make_maze(bitbox board[len][wid],point f){
byte ds_tried=0; byte ds_tried=0;
byte dnumber=random()%4; byte dnumber=rand()%4;
bitbox direction= 1 << (dnumber); bitbox direction= 1 << (dnumber);
while( direction == board[f.y][f.x] ) 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); point pt = MID(f.y,f.x,direction);
while(ds_tried<4){ 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){ void carrotify(bitbox board[len][wid],int count){
int y,x,c=count; int y,x,c=count;
while(c){ while(c){
y=random()%len; y=rand()%len;
x=random()%wid; x=rand()%wid;
while( board[y][x] & CARROT ){ while( board[y][x] & CARROT ){
y=random()%len; y=rand()%len;
x=random()%wid; x=rand()%wid;
} }
board[y][x] |= CARROT; board[y][x] |= CARROT;
c--; c--;
@ -208,7 +208,7 @@ int main(int argc, char** argv){
int carrot_count= (len*wid)/50; int carrot_count= (len*wid)/50;
int carrots_found; int carrots_found;
time_t tstart , now, giventime=len*wid/5; time_t tstart , now, giventime=len*wid/5;
srandom(time(NULL)%UINT_MAX); srand(time(NULL)%UINT_MAX);
point start={0,0}; point start={0,0};
bitbox board[len][wid]; bitbox board[len][wid];
int sy,sx; 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){ void randmove(int* y,int* x,byte* c){
*y=random()%len; *y=rand()%len;
*x=random()%wid; *x=rand()%wid;
*c=random()%2; *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 decide ( char board[len][wid],byte colored[len][wid], byte depth , byte side ){ //the move is imaginary if side is negative
int adv,bestadv; int adv,bestadv;
@ -265,7 +265,7 @@ int main(int argc, char** argv){
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} }
srandom(time(NULL)%UINT_MAX); srand(time(NULL)%UINT_MAX);
int input; int input;
initscr(); initscr();
mousemask(ALL_MOUSE_EVENTS,NULL); 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) if (tries>s)
return 1; 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 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){ while(1){
if(!board[y][x]){ if(!board[y][x]){
board[y][x]=fillwith; 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 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 void mkpuzzle(char board[s][s],char empty[s][s],char game[s][s]){//makes a puzzle to solve
byte y,x; byte y,x;
for(y=0;y<s;y++){ for(y=0;y<s;y++){
for(x=0;x<s;x++){ for(x=0;x<s;x++){
if( !(random()%diff) ){ if( !(rand()%diff) ){
empty[y][x]=board[y][x]; empty[y][x]=board[y][x];
game[y][x]=board[y][x]; game[y][x]=board[y][x];
} }
@ -327,7 +327,7 @@ int main(int argc,char** argv){
noecho(); noecho();
cbreak(); cbreak();
keypad(stdscr,1); keypad(stdscr,1);
srandom(time(NULL)%UINT_MAX); srand(time(NULL)%UINT_MAX);
if( has_colors() ){ if( has_colors() ){
start_color(); start_color();
use_default_colors(); use_default_colors();