aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2024-06-01 19:53:48 +0200
committerMarkus Uhlin <markus@nifty-networks.net>2024-06-01 19:53:48 +0200
commita016d4f270ad85aa13053388c10997c008c99bcd (patch)
tree0f3bfbcb0e830d23f119afcf2db186cba153c481
parentb9b2244a042ceb8fe97fab1210bc8b59e59c0321 (diff)
Added and made use of brand()
-rw-r--r--FICS/board.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/FICS/board.c b/FICS/board.c
index 01ffc03..d0c5913 100644
--- a/FICS/board.c
+++ b/FICS/board.c
@@ -30,6 +30,7 @@
#include "common.h"
#include <err.h>
+#include <limits.h>
#include "board.h"
#include "gamedb.h"
@@ -83,6 +84,15 @@ PRIVATE int orient;
PRIVATE int forPlayer;
PRIVATE int myTurn;
+PRIVATE int
+brand(void)
+{
+#if RAND_MAX < 32767 || RAND_MAX > INT_MAX
+#error RAND_MAX unacceptable
+#endif
+ return ((int) arc4random_uniform(RAND_MAX));
+}
+
PUBLIC int
board_init(game_state_t *b, char *category, char *board)
{
@@ -1175,9 +1185,9 @@ place_piece(board_t b, int piece, int squareColor)
while (!placed) {
if (squareColor == ANY_SQUARE) {
- f = (rand() % 8);
+ f = (brand() % 8);
} else {
- f = (rand() % 4) * 2;
+ f = (brand() % 4) * 2;
if (SquareColor(f, r) != squareColor)
f++;
@@ -1208,14 +1218,14 @@ wild_update(int style)
switch (style) {
case 1:
- if (rand() & 0x01) {
+ if (brand() & 0x01) {
b[4][0] = W_KING;
b[3][0] = W_QUEEN;
} else {
b[3][0] = W_KING;
b[4][0] = W_QUEEN;
}
- if (rand() & 0x01) {
+ if (brand() & 0x01) {
b[4][7] = B_KING;
b[3][7] = B_QUEEN;
} else {
@@ -1262,7 +1272,7 @@ wild_update(int style)
for (i = 0; i < 8; i++) {
if (b[i][0] != W_KING) {
- b[i][0] = (rand() % 4) + 2;
+ b[i][0] = (brand() % 4) + 2;
}
}
@@ -1279,7 +1289,7 @@ wild_update(int style)
for (i = 0; i < 8; i++) {
if (b[i][0] != W_KING)
- b[i][0] = (rand() % 4) + 2;
+ b[i][0] = (brand() % 4) + 2;
}
/*