Added stuff
This commit is contained in:
33
blackjack/Makefile
Normal file
33
blackjack/Makefile
Normal file
@@ -0,0 +1,33 @@
|
||||
PREFIX=/usr
|
||||
|
||||
#OBJS specifies which files to compile as part of the project
|
||||
OBJS = blackjack.c
|
||||
|
||||
#CC specifies which compiler to use
|
||||
CC = clang
|
||||
|
||||
#COMPILER_FLAGS specifies the additional compilation options we're using
|
||||
# -w suppress all warnings
|
||||
COMPILER_FLAGS = -Wall
|
||||
|
||||
#LINKER_FLAGS specifies the libraries we're linking against
|
||||
LINKER_FLAGS =
|
||||
|
||||
#OBJ_NAME specifies the name of our executable
|
||||
OBJ_NAME= blackjack
|
||||
|
||||
#This is the target that compiles our executable
|
||||
all : $(OBJS)
|
||||
$(CC) $(OBJS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME)
|
||||
install :
|
||||
mkdir -p ${PREFIX}/share/${OBJ_NAME}tuxc
|
||||
cp tuxc ${PREFIX}/share/${OBJ_NAME}/
|
||||
cp -R package_managers ${PREFIX}/share/${OBJ_NAME}/
|
||||
ln -si ${PREFIX}/share/${OBJ_NAME}/${OBJ_NAME} ${PREFIX}/bin/${OBJ_NAME}
|
||||
uninstall :
|
||||
rm ${PREFIX}/bin/${OBJ_NAME}
|
||||
rm ${PREFIX}/share/${OBJ_NAME}/${OBJ_NAME}
|
||||
rm -r ${PREFIX}/share/${OBJ_NAME}
|
||||
clean :
|
||||
rm ${OBJ_NAME}
|
||||
|
BIN
blackjack/blackjack
Executable file
BIN
blackjack/blackjack
Executable file
Binary file not shown.
76
blackjack/blackjack.c
Normal file
76
blackjack/blackjack.c
Normal file
@@ -0,0 +1,76 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<math.h>
|
||||
#include<time.h>
|
||||
|
||||
#define CARD_MAX 51
|
||||
#define len(x) sizeof(x)/sizeof(x[0])
|
||||
|
||||
void print_deck (int *deckOfCards);
|
||||
void shuffel (int *array, int n);
|
||||
|
||||
static int rand_int(int n);
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
int deckOfCards[CARD_MAX];
|
||||
|
||||
time_t t;
|
||||
srand((unsigned) time(&t));
|
||||
|
||||
|
||||
/* Clubs > Diamonds > Hearts > Spades
|
||||
* 0-12 13-25 26-38 39-51
|
||||
*/
|
||||
|
||||
for (i = 0; i<CARD_MAX; i++){
|
||||
deckOfCards[i]=i;
|
||||
}
|
||||
|
||||
shuffel(deckOfCards, CARD_MAX);
|
||||
|
||||
print_deck(deckOfCards);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Add a starting position. I can have a variable that simply means "continue drawing/printing cards from here"
|
||||
void print_deck(int *deckOfCards){
|
||||
int i;
|
||||
|
||||
for (i = 0; i<CARD_MAX; i++){
|
||||
printf("%d\n", deckOfCards[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void shuffel (int *array, int n){
|
||||
|
||||
int i, j, tmp;
|
||||
|
||||
|
||||
for (i=n; i>-1 ;i--){
|
||||
|
||||
j = rand_int(i + 1);
|
||||
|
||||
tmp = array[j];
|
||||
array[j] = array[i];
|
||||
array[i] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
static int rand_int(int n){
|
||||
|
||||
int limit = RAND_MAX - RAND_MAX % n;
|
||||
|
||||
int rnd;
|
||||
|
||||
do {
|
||||
rnd=rand();
|
||||
}
|
||||
while (rnd >= limit);
|
||||
|
||||
return rnd % n;
|
||||
}
|
||||
|
||||
|
79
blackjack/copy_pasta_test.c
Normal file
79
blackjack/copy_pasta_test.c
Normal file
@@ -0,0 +1,79 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int rand_int(int n) {
|
||||
|
||||
int limit = RAND_MAX - RAND_MAX % n;
|
||||
|
||||
int rnd;
|
||||
|
||||
|
||||
|
||||
do {
|
||||
|
||||
rnd = rand();
|
||||
|
||||
}
|
||||
|
||||
while (rnd >= limit);
|
||||
|
||||
return rnd % n;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void shuffle(int *array, int n) {
|
||||
|
||||
int i, j, tmp;
|
||||
|
||||
|
||||
|
||||
for (i = n - 1; i > 0; i--) {
|
||||
|
||||
j = rand_int(i + 1);
|
||||
|
||||
tmp = array[j];
|
||||
|
||||
array[j] = array[i];
|
||||
|
||||
array[i] = tmp;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
||||
{
|
||||
time_t t;
|
||||
srand((unsigned) time(&t));
|
||||
|
||||
|
||||
int i = 0;
|
||||
|
||||
int numbers[50];
|
||||
|
||||
for (i = 0; i < 50; i++)
|
||||
|
||||
numbers[i]= i;
|
||||
|
||||
shuffle(numbers, 50);
|
||||
|
||||
printf("\nArray after shuffling is: \n");
|
||||
|
||||
for ( i = 0; i < 50; i++)
|
||||
|
||||
printf("%d\n", numbers[i]);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
Reference in New Issue
Block a user