aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorboa <boa@pm.me>2021-01-30 23:20:04 +0100
committerboa <boa@pm.me>2021-01-30 23:20:04 +0100
commit7693bafd5e16ce14e89d53fb04948de98f13c0c8 (patch)
tree473bad7d2b6fa4706a6812368db176640413e61d
downloadajedrez-7693bafd5e16ce14e89d53fb04948de98f13c0c8.tar.gz
init
-rwxr-xr-xchessbin0 -> 16800 bytes
-rw-r--r--chess.c89
2 files changed, 89 insertions, 0 deletions
diff --git a/chess b/chess
new file mode 100755
index 0000000..1f01f4a
--- /dev/null
+++ b/chess
Binary files differ
diff --git a/chess.c b/chess.c
new file mode 100644
index 0000000..3442c86
--- /dev/null
+++ b/chess.c
@@ -0,0 +1,89 @@
+#include <arpa/inet.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#define PRINT_ALL(f_, ...) \
+ do { \
+ dprintf(w_fd, (f_), ##__VA_ARGS__); \
+ dprintf(b_fd, (f_), ##__VA_ARGS__); \
+ } while (0)
+
+typedef enum color { c_w = 34, c_b = 31 } color;
+
+typedef enum piece_type {
+ p_no,
+ p_pawn = 'P',
+ p_rook = 'R',
+ p_knight = 'N',
+ p_bishop = 'B',
+ p_queen = 'Q',
+ p_king = 'K'
+} piece_type;
+
+typedef struct piece {
+ piece_type p;
+ color c;
+} piece;
+
+piece table[8][8];
+
+void print_table();
+
+void print_table() {
+ printf(" BLACK\n |");
+ for (int x = 0; x < 8; x++)
+ printf("%c", 'a' + x);
+ printf("|\n-+");
+ for (int x = 0; x < 8; x++)
+ printf("-");
+ printf("+-\n");
+ for (int y = 0; y < 8; y++) {
+ printf("%d|", y + 1);
+ for (int x = 0; x < 8; x++)
+ if (table[x][y].p)
+ printf("\x1B[%dm%c\x1B[0m", table[x][y].c, table[x][y].p);
+ else
+ printf(".");
+ printf("|%d\n", y + 1);
+ }
+ printf("-+");
+ for (int x = 0; x < 8; x++)
+ printf("-");
+ printf("+-\n |");
+ for (int x = 0; x < 8; x++)
+ printf("%c", 'a' + x);
+ printf("|\n WHITE\n");
+}
+
+void setup_table() {
+ table[0][0] = (piece){p_rook, c_b};
+ table[1][0] = (piece){p_knight, c_b};
+ table[2][0] = (piece){p_bishop, c_b};
+ table[3][0] = (piece){p_king, c_b};
+ table[4][0] = (piece){p_queen, c_b};
+ table[5][0] = (piece){p_bishop, c_b};
+ table[6][0] = (piece){p_knight, c_b};
+ table[7][0] = (piece){p_rook, c_b};
+ for (int x = 0; x < 8; x++)
+ table[x][1] = (piece){p_pawn, c_b};
+
+ table[0][7] = (piece){p_rook, c_w};
+ table[1][7] = (piece){p_knight, c_w};
+ table[2][7] = (piece){p_bishop, c_w};
+ table[3][7] = (piece){p_king, c_w};
+ table[4][7] = (piece){p_queen, c_w};
+ table[5][7] = (piece){p_bishop, c_w};
+ table[6][7] = (piece){p_knight, c_w};
+ table[7][7] = (piece){p_rook, c_w};
+ for (int x = 0; x < 8; x++)
+ table[x][6] = (piece){p_pawn, c_w};
+}
+
+int main() {
+ setup_table();
+ print_table();
+ return 0;
+}
Un proyecto texto-plano.xyz