|
| 1 | +#include <stdio.h> |
| 2 | +#include <ncurses.h> |
| 3 | +#include <string.h> |
| 4 | +#include <stdlib.h> |
| 5 | + |
| 6 | +int start(); |
| 7 | +int ins(); |
| 8 | +void display(char* piece[8][8]); |
| 9 | +void cmd(int turn, char* piece[8][8]); |
| 10 | +//void check(); |
| 11 | + |
| 12 | +char * piece[8][8] = { |
| 13 | + {"x", "♞", "♝", "♛", "♚", "♝", "♞", "♜"}, |
| 14 | + {"♟", "♟", "♟", "♟", "♟", "♟", "♟", "♟"}, |
| 15 | + {" ", " ", " ", " ", " ", " ", " ", " "}, |
| 16 | + {" ", " ", " ", " ", " ", " ", " ", " "}, |
| 17 | + {" ", " ", " ", " ", " ", " ", " ", " "}, |
| 18 | + {" ", " ", " ", " ", " ", " ", " ", " "}, |
| 19 | + {"♙", "♙", "♙", "♙", "♙", "♙", "♙", "♙"}, |
| 20 | + {"♖", "♘", "♗", "♔", "♕", "♗", "♘", "♖"} |
| 21 | +}; |
| 22 | + |
| 23 | + |
| 24 | +//=============================================================================================================================================================== |
| 25 | + |
| 26 | +int main(){ |
| 27 | + int choice = start(), win=0, turn=1; |
| 28 | + |
| 29 | + // int l = strlen("♜"); |
| 30 | + // printf("%d\n", l); |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + if (choice == 1) |
| 35 | + { |
| 36 | + system("clear"); |
| 37 | + display(piece); |
| 38 | + } |
| 39 | + if (choice == 2) |
| 40 | + { |
| 41 | + system("clear"); |
| 42 | + ins(); |
| 43 | + display(piece); |
| 44 | + } |
| 45 | + |
| 46 | + cmd(turn, piece); |
| 47 | + system("clear"); |
| 48 | + display(piece); |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | + return 0; |
| 53 | +} |
| 54 | +//=============================================================================================================================================================== |
| 55 | + |
| 56 | +void cmd(int turn, char *piece[8][8]){ |
| 57 | + |
| 58 | + int x, y, x1, y1; |
| 59 | + char temp1[3]; |
| 60 | + char temp2[3]; |
| 61 | + |
| 62 | + if (turn % 2 != 0) |
| 63 | + { |
| 64 | + |
| 65 | + printf("Player 1's Turn\n"); |
| 66 | + printf("Enter the x coordinate of your piece: "); |
| 67 | + scanf("%d", &x); |
| 68 | + printf("Enter the y coordinate of your piece: "); |
| 69 | + scanf("%d", &y); |
| 70 | + printf("Enter the x coordinate of your desired location: "); |
| 71 | + scanf("%d", &x1); |
| 72 | + printf("Enter the y coordinate of your desired location: "); |
| 73 | + scanf("%d", &y1); |
| 74 | + |
| 75 | + //============================== |
| 76 | + |
| 77 | + |
| 78 | + // strcpy(temp1, piece[y-1][x-1]); |
| 79 | + // printf("%s check1\n", temp1); |
| 80 | + // |
| 81 | + // strcpy(temp2, piece[y1-1][x1-1]); |
| 82 | + // printf("%s check2\n", temp2); |
| 83 | + // |
| 84 | + // strcpy(piece[y1-1][x1-1], "x"); |
| 85 | + // printf("%s check3\n", piece[y1-1][x1-1]); |
| 86 | + // |
| 87 | + // printf("check4 %s\n", piece[y1-1][x1-1]); // not working |
| 88 | + // |
| 89 | + // strcpy((piece[y-1][x-1]), (piece[y1-1][x1-1])); |
| 90 | + // |
| 91 | + // |
| 92 | + // |
| 93 | + // printf("check3\n"); |
| 94 | + // printf("%s\n", piece[y-1][x-1]); |
| 95 | + // |
| 96 | + // strcpy(piece[x1-1][y1-1], temp1); |
| 97 | + // printf("%s\n", piece[x1-1][y1-1]); |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | + } |
| 102 | + /* |
| 103 | + else |
| 104 | + { |
| 105 | + printf("Player 2's Turn\n"); |
| 106 | + printf("Enter the coordinates of your piece in format <x coordinate><y coordinate>: "); |
| 107 | + scanf("%d", &cmd); |
| 108 | + |
| 109 | + }*/ |
| 110 | + |
| 111 | +} |
| 112 | +//=============================================================================================================================================================== |
| 113 | +int start(){ |
| 114 | + int choice; |
| 115 | + system("clear"); |
| 116 | + |
| 117 | + printf("\n WELCOME TO CHESS \n\n"); |
| 118 | + printf(" To Start: Press 1 \n"); |
| 119 | + printf(" Instructions: Press 2 \n\n"); |
| 120 | + printf("> "); |
| 121 | + scanf("%d", &choice); |
| 122 | + |
| 123 | + return choice; |
| 124 | +} |
| 125 | + |
| 126 | + |
| 127 | +//=============================================================================================================================================================== |
| 128 | + |
| 129 | +//=============================================================================================================================================================== |
| 130 | + |
| 131 | + |
| 132 | +int ins(){ |
| 133 | + int choice; |
| 134 | + |
| 135 | + printf("\nThis is a chess game between 2 players, since making AI is too hard.\n"); |
| 136 | + printf("To Move a piece, enter its x coordinate, then its y coordinate.\n"); |
| 137 | + printf("Then, enter the square of a valid spot to move there.\n"); |
| 138 | + printf("Player 1: lower case\n"); |
| 139 | + printf("Player 2: lower case\n"); |
| 140 | + printf("W / w = KING\n"); |
| 141 | + printf("Q / q = QUEEN\n"); |
| 142 | + printf("R / r = Rook\n"); |
| 143 | + printf("K / k = KNIGHT\n"); |
| 144 | + printf("B / b = BISHOP\n"); |
| 145 | + printf("P / p = PAWN\n\n"); |
| 146 | + printf("Once you are done, enter 1 to begin playing.\n"); |
| 147 | + scanf("%d", &choice); |
| 148 | + |
| 149 | + system("clear"); |
| 150 | + return choice; |
| 151 | +} |
| 152 | +//=============================================================================================================================================================== |
| 153 | +void display(char* piece[8][8]){ |
| 154 | + |
| 155 | + printf("\n\n"); |
| 156 | + printf(" 0 1 2 3 4 5 6 7\n"); |
| 157 | + printf(" .................................................\n"); |
| 158 | + printf("0 | %s | %s | %s | %s | %s | %s | %s | %s | 0\n", piece[0][0], piece[0][1], piece[0][2], piece[0][3], piece[0][4], piece[0][5], piece[0][6], piece[0][7]); |
| 159 | + printf(" .................................................\n"); |
| 160 | + printf("1 | %s | %s | %s | %s | %s | %s | %s | %s | 1\n", piece[1][0], piece[1][1], piece[1][2], piece[1][3], piece[1][4], piece[1][5], piece[1][6], piece[1][7]); |
| 161 | + printf(" .................................................\n"); |
| 162 | + printf("2 | %s | %s | %s | %s | %s | %s | %s | %s | 2\n", piece[2][0], piece[2][1], piece[2][2], piece[2][3], piece[2][4], piece[2][5], piece[2][6], piece[2][7]); |
| 163 | + printf(" .................................................\n"); |
| 164 | + printf("3 | %s | %s | %s | %s | %s | %s | %s | %s | 3\n", piece[3][0], piece[3][1], piece[3][2], piece[3][3], piece[3][4], piece[3][5], piece[3][6], piece[3][7]); |
| 165 | + printf(" .................................................\n"); |
| 166 | + printf("4 | %s | %s | %s | %s | %s | %s | %s | %s | 4\n", piece[4][0], piece[4][1], piece[4][2], piece[4][3], piece[4][4], piece[4][5], piece[4][6], piece[4][7]); |
| 167 | + printf(" .................................................\n"); |
| 168 | + printf("5 | %s | %s | %s | %s | %s | %s | %s | %s | 5\n", piece[5][0], piece[5][1], piece[5][2], piece[5][3], piece[5][4], piece[5][5], piece[5][6], piece[5][7]); |
| 169 | + printf(" .................................................\n"); |
| 170 | + printf("6 | %s | %s | %s | %s | %s | %s | %s | %s | 6\n", piece[6][0], piece[6][1], piece[6][2], piece[6][3], piece[6][4], piece[6][5], piece[6][6], piece[6][7]); |
| 171 | + printf(" .................................................\n"); |
| 172 | + printf("7 | %s | %s | %s | %s | %s | %s | %s | %s | 7\n", piece[7][0], piece[7][1], piece[7][2], piece[7][3], piece[7][4], piece[7][5], piece[7][6], piece[7][7]); |
| 173 | + printf(" .................................................\n"); |
| 174 | + printf(" 0 1 2 3 4 5 6 7\n"); |
| 175 | +} |
0 commit comments