Deal cards for FreeCell: Difference between revisions
Content added Content deleted
(Save the page again.) |
No edit summary |
||
Line 27: | Line 27: | ||
Deals can be checked against [http://freecellgamesolutions.com/ FreeCell solutions to 1000000 games]. (Summon a video solution, and it displays the initial deal.) |
Deals can be checked against [http://freecellgamesolutions.com/ FreeCell solutions to 1000000 games]. (Summon a video solution, and it displays the initial deal.) |
||
=={{header|C}}== |
|||
<lang c>#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#include <locale.h> |
|||
wchar_t s_suits[] = L"♣♦♥♠", s_nums[] = L"A23456789TJQK"; |
|||
#define RMAX32 ((1U << 31) - 1) |
|||
#define RMAX ((1U << 15) - 1) |
|||
static int seed = 1; |
|||
int rnd(void) { return (seed = (seed * 214013 + 2531011) & RMAX32) >> 16; } |
|||
void srnd(int x) { seed = x; } |
|||
int card[52]; |
|||
void show(void) |
|||
{ |
|||
int i; |
|||
for (i = 0; i < 52; i ++) |
|||
printf("%lc%lc%s", |
|||
s_suits[card[i] % 4], s_nums[card[i] / 4], |
|||
((i + 1) % 8) ? " " : "\n"); |
|||
putchar('\n'); |
|||
} |
|||
void deal(int s) |
|||
{ |
|||
int i, j, n, t[52]; |
|||
for (i = 0; i < 52; i++) t[i] = i; |
|||
srnd(s); |
|||
for (j = 0, n = 52; n; ) { |
|||
i = rnd() % n--; |
|||
card[j++] = t[i]; |
|||
t[i] = t[n]; |
|||
} |
|||
printf("Deal %d\n", s); |
|||
show(); |
|||
} |
|||
int main(int c, char **v) |
|||
{ |
|||
int s; |
|||
setlocale(LC_ALL, ""); |
|||
if (c < 2 || (s = atoi(v[1])) <= 0) s = 11982; |
|||
deal(s); |
|||
return 0; |
|||
}</lang> |