Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C, 5 card reader

Name: Tim 2012-12-31 8:41

Looking for some to write a c program for me and possibly e-mail it to me, willing to pay and all and it must not be copied from somewhere else.

It is a program that reads one line of text input contain 2 characters for cards and a total of 5 cards. It will then post an output with a description of each card, the hand the 5 cards make and the amount of points that hand makes. It must also show an error if the input is not supported by the program.

I could write it myself but have other coursework to do and I'm quite simply lazy. Willing to pay.

Name: Anonymous 2012-12-31 19:33

card.c


#include <stdio.h>
#include <stdlib.h>
#include "magic.h"

HAX MY ANUS



magic.h


#define suit(card) (card & 0x30)
#define value(card) (card & 0x0F)
#define swap(i1, i2, h) h[i1] = h[i1] ^ h[i2]; h[i2] = h[i1] ^ h[i2]; h[i1] = h[i1] ^ h[i2];
#define step(i1, i2, h) if(value(h[i1]) > value(h[i2])) {swap(i1, i2, h)}
#define sort(h) step(0, 1, h) step(0, 2, h) step(0, 3, h) step(0, 4, h) step(1, 2, h) step(1, 3, h) step(1, 4, h) step(2, 3, h) step(2, 4, h) step(3, 4, h)
#define max(a, b) ((a > b) ? a : b)
#define cardmax(h) (max( value(h[4]), max( value(h[3]), max( value(h[2]), max( value(h[0]), value(h[1]))))))
#define connected(a, b, h) ((value(h[a]) + 1) == value(h[b]))
#define equalv(a, b, h) (value(h[a]) == value(h[b]))
#define flush(h) ((suit(h[0]) == suit(h[1])) && (suit(h[1]) == suit(h[2])) && (suit(h[2]) == suit(h[3])) && (suit(h[3]) == suit(h[4])))
#define straight(h) (connected(0, 1, h) && connected(1, 2, h) && connected(2, 3, h) && connected(3, 4, h))
#define fullhouse(h) ((equalv(0, 1, h) && equalv(1, 2, h) && equalv(3, 4, h)) || (equalv(0, 1, h) && equalv(2, 3, h) && equalv(3, 4, h)))
#define fourofakind(h) ((equalv(0, 1, h) && equalv(1, 2, h) && equalv(2, 3, h)) || (equalv(1, 2, h) && equalv(2, 3, h) && equalv(3, 4, h)))
#define threeofakind(h) ((equalv(0, 1, h) && equalv(1, 2, h)) || (equalv(1, 2, h) && equalv(2, 3, h)) || (equalv(2, 3, h) && equalv(3, 4, h)))
#define twopair(h) ((equalv(0, 1, h) && (equalv(2, 3, h) || equalv(3, 4, h))) || (equalv(1, 2, h) && equalv(3, 4, h)))
#define pair(h) (equalv(0, 1, h) || equalv(1, 2, h) || equalv(2, 3, h) || equalv(3, 4, h))
#define royalflush(h) (flush(h) && straight(h) && (cardmax(h) == 0x0E))
#define straightflush(h) (flush(h) && straight(h))
#define highcard(h) (cardmax(h) > 0x0A)
#define po(p, s) else if(p) {puts(s);}
#define ppoints(h) printf(" ---- \r\n"); if(royalflush(h)) {puts("Royal Flush: 100 poitns");} po(straightflush(h), "Straight Flush: 75 points") po(fourofakind(h), "Four of a Kind: 50 points") \
    po(fullhouse(h), "Full House: 25 points") po(flush(h), "Flush: 20 points") po(straight(h), "Straight 15 points") po(threeofakind(h), "Three of a Kind: 10 points") po(twopair(h), "Two Pair: 5 points") \
    po(pair(h), "Pair: 2 points") po(highcard(h), "High Card: 1 point") else {puts("No combinations: 0 points");}
#define pcase(n, s) case n: printf(s); break;
#define pvalue(card) switch(value(card)){pcase(0x0A, "10") pcase(0x0B, "Jack") pcase(0x0C, "Queen") pcase(0x0D, "King") pcase(0x0E, "Ace") default: putchar(value(card)+48);}
#define psuit(card) switch(suit(card)){pcase(0x00, "Clubs") pcase(0x10, "Diamonds") pcase(0x20, "Hearts") pcase(0x30, "Spades")}
#define pcard(card) pvalue(card) printf(" of "); psuit(card) putchar('\r'); putchar('\n');
#define print(hand) pcard(hand[0]) pcard(hand[1]) pcard(hand[2]) pcard(hand[3]) pcard(hand[4]) ppoints(hand)
#define error puts("Input string not of form 'VS VS VS VS VS' where V is the value of the card {0-9 J Q K A} and S is the suit of the card {C D H S}"); exit(EXIT_FAILURE);
#define icase(c, n, p) case n: c = c | p; break;
#define icard(c) switch(getchar()){icase(c, '2', 2) icase(c, '3', 3) icase(c, '4', 4) icase(c, '5', 5) icase(c, '6', 6) icase(c, '7', 7) icase(c, '8', 8) icase(c, '9', 9) icase(c, '0', 10) icase(c, 'J', 11) \
    icase(c, 'Q', 12) icase(c, 'K', 13) icase(c, 'A', 14) default: error} switch(getchar()){icase(c, 'C', 0x00) icase(c, 'D', 0x10) icase(c, 'H', 0x20) icase(c, 'S', 0x30) default: error}
#define cspace if(getchar() != ' ') {error}
#define gcard(c) icard(c) cspace
#define get(h) gcard(h[0]) gcard(h[1]) gcard(h[2]) gcard(h[3]) icard(h[4])
#define c(a,b,h) h[a] == h[b]
#define check(h) if(c(0,1,h)||c(0,2,h)||c(0,3,h)||c(0,4,h)||c(1,2,h)||c(1,3,h)||c(1,4,h)||c(2,3,h)||c(2,4,h)||c(3,4,h)) {puts("You cannot have two of the same card in a hand."); exit(EXIT_FAILURE);}
#define HAX main(){
#define MY char hand[] = {0,0,0,0,0};get(hand);check(hand);sort(hand);print(hand);
#define ANUS }

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List