cleanup
This commit is contained in:
parent
4a12db6cfd
commit
99a039898a
3 changed files with 18 additions and 11 deletions
|
@ -1,8 +1,6 @@
|
||||||
#ifndef MYSOK_H
|
#ifndef MYSOK_H
|
||||||
#define MYSOK_H
|
#define MYSOK_H
|
||||||
#include <cstdio>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <string.h>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#define NBL 20
|
#define NBL 20
|
||||||
|
@ -29,7 +27,7 @@ enum board_str {
|
||||||
END_OF_LINE = 'a'
|
END_OF_LINE = 'a'
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::string move_str[] = {"Up", "Down", "Left", "Right", "Wait"};
|
// const std::string move_str[] = {"Up", "Down", "Left", "Right", "Wait"};
|
||||||
|
|
||||||
struct sok_board_t {
|
struct sok_board_t {
|
||||||
int board[NBL][NBC];
|
int board[NBL][NBC];
|
||||||
|
|
|
@ -1,29 +1,38 @@
|
||||||
#include "../includes/mysok.h"
|
#include "../includes/mysok.h"
|
||||||
|
|
||||||
sok_board_t::sok_board_t() {
|
sok_board_t::sok_board_t() {
|
||||||
for (int i = 0; i < NBL; i++)
|
for (int i = 0; i < NBL; i++) {
|
||||||
for (int j = 0; j < NBC; j++)
|
for (int j = 0; j < NBC; j++) {
|
||||||
board[i][j] = FREE;
|
board[i][j] = FREE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void sok_board_t::print_board() {
|
void sok_board_t::print_board() {
|
||||||
for (int i = 0; i < board_nbl; i++) {
|
for (int i = 0; i < board_nbl; i++) {
|
||||||
for (int j = 0; j < NBC; j++) {
|
for (int j = 0; j < NBC; j++) {
|
||||||
if (board[i][j] == END_OF_LINE)
|
if (board[i][j] == END_OF_LINE) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
printf("%c", board[i][j]);
|
printf("%c", board[i][j]);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sok_board_t::load(char *_file) {
|
void sok_board_t::load(char *_file) {
|
||||||
FILE *fp = fopen(_file, "r");
|
FILE *fp = fopen(_file, "r");
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
ssize_t nread;
|
ssize_t nread;
|
||||||
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
perror("fopen");
|
perror("fopen");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
board_nbl = 0;
|
board_nbl = 0;
|
||||||
while ((nread = getline(&line, &len, fp)) != -1) {
|
while ((nread = getline(&line, &len, fp)) != -1) {
|
||||||
if ((static_cast<int>(nread)) > 0) {
|
if ((static_cast<int>(nread)) > 0) {
|
||||||
|
@ -83,6 +92,7 @@ void sok_board_t::load(char *_file) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(line);
|
free(line);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
#include "../includes/mysok.h"
|
#include "../includes/mysok.h"
|
||||||
#include <cstdio>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <string.h>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
int main(int _ac, char **_av) {
|
int main(int _ac, char **_av) {
|
||||||
if (_ac != 2) {
|
if (_ac != 2) {
|
||||||
printf("usage: %s SOK_FILE\n", _av[0]);
|
printf("usage: %s SOK_FILE\n", _av[0]);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sok_board_t S;
|
sok_board_t S;
|
||||||
S.load(_av[1]);
|
S.load(_av[1]);
|
||||||
S.print_board();
|
S.print_board();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue