summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2008-05-13 18:32:42 +0000
committerDimitri Sokolyuk <demon@dim13.org>2008-05-13 18:32:42 +0000
commit38a0bf1e114aa95600b127c2604e5b54ae41cf27 (patch)
tree0bde5e8340b7183145d4bb7c14f30e1b7a9cbb70
dice
-rw-r--r--dice.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/dice.c b/dice.c
new file mode 100644
index 0000000..513a08a
--- /dev/null
+++ b/dice.c
@@ -0,0 +1,69 @@
+/* $Id$ */
+/*
+ * Copyright (c) 2008 Dimitri Sokolyuk <sokolyuk@gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <assert.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+
+enum {BORDER, EMPTY, LEFT, MIDDLE, RIGHT, BOTH};
+
+char *dice[] = {
+ [BORDER] = " ----- ",
+ [EMPTY] = "| |",
+ [LEFT] = "|O |",
+ [MIDDLE] = "| O |",
+ [RIGHT] = "| O|",
+ [BOTH] = "|O O|"
+};
+
+int row[][5] = {
+ {BORDER, EMPTY, MIDDLE, EMPTY, BORDER},
+ {BORDER, RIGHT, EMPTY, LEFT, BORDER},
+ {BORDER, RIGHT, MIDDLE, LEFT, BORDER},
+ {BORDER, BOTH, EMPTY, BOTH, BORDER},
+ {BORDER, BOTH, MIDDLE, BOTH, BORDER},
+ {BORDER, BOTH, BOTH, BOTH, BORDER}
+};
+
+int
+main(int argc, char **argv)
+{
+ int i, j, *r, n;
+
+ n = (argc == 2) ? atoi(argv[1]) : 2;
+ if (n < 0)
+ n = -n;
+
+ r = calloc(n, sizeof(int));
+ assert(r);
+
+ srand(time(NULL) + getpid());
+
+ for (i = 0; i < n; i++)
+ r[i] = rand() % 6;
+
+ for (j = 0; j < 5; j++) {
+ for (i = 0; i < n; i++)
+ printf("%s ", dice[row[r[i]][j]]);
+ printf("\n");
+ }
+
+ return 0;
+}