Created
December 31, 2014 13:00
-
-
Save FilipChalupa/7b6e491aaca9d90791cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define BOARD_SIZE 8 | |
char **new_board(const int size) { | |
int i, k; | |
char **board; | |
board = (char**) malloc(sizeof(char*) * size); | |
for (i = 0; i < size; ++i) { | |
board[i] = (char*) malloc(sizeof(char) * size); | |
} | |
for (i = 0; i < size; ++i) { | |
for (k = 0; k < size; ++k) { | |
board[i][k] = (i + k) % 2; | |
} | |
} | |
return board; | |
} | |
void print_row(char *row, const int size) { | |
int i; | |
for (i = 0; i < size; ++i) { | |
if (row[i]) { | |
printf(" o"); | |
} else { | |
printf(" x"); | |
} | |
} | |
} | |
void print_board(char **board, const int size) { | |
int i; | |
for (i = 0; i < size; ++i) { | |
printf("%2d|", BOARD_SIZE - i); | |
print_row(board[i], size); | |
printf("\n"); | |
} | |
printf(" "); | |
for (i = 0; i < size; ++i) { | |
printf("__"); | |
} | |
printf("\n "); | |
for (i = 0; i < size; ++i) { | |
printf(" %c", 97+i); | |
} | |
printf("\n"); | |
} | |
void free_board(char **board, const int size) { | |
int i, k; | |
for (i = 0; i < size; ++i) { | |
free(board[i]); | |
} | |
free(board); | |
} | |
int main (int argc, char *argv[]) { | |
char **board = new_board(BOARD_SIZE); | |
printf("\n\n"); | |
printf(" SACHOVNICE 2015\n\n"); | |
print_board(board, BOARD_SIZE); | |
printf("\n"); | |
free_board(board, BOARD_SIZE); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment