Refactor
This commit is contained in:
26
include/common.h
Normal file
26
include/common.h
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
#include <stdbool.h> /* true, false, bool */
|
||||
#include <stddef.h> /* ptrdiff_t */
|
||||
#include <stdint.h> /* int32_t */
|
||||
|
||||
/** Type representing piece/tile on a chessboard */
|
||||
typedef int32_t tile_t;
|
||||
|
||||
/** Type representing index of a chessboard tile */
|
||||
typedef ptrdiff_t index_t;
|
||||
|
||||
#define BOARD_SIZE ((index_t)(8 * 8))
|
||||
|
||||
#define WHITE 1
|
||||
#define BLACK -1
|
||||
|
||||
#define E ((tile_t)0) ///< empty tile
|
||||
#define K ((tile_t)1) ///< king
|
||||
#define Q ((tile_t)2) ///< queen
|
||||
#define R ((tile_t)3) ///< rook
|
||||
#define B ((tile_t)4) ///< bishop
|
||||
#define N ((tile_t)5) ///< knight
|
||||
#define P ((tile_t)6) ///< pawn
|
||||
|
||||
#define ROW ((index_t)8)
|
||||
#define COL ((index_t)1)
|
||||
8
include/graphics.h
Normal file
8
include/graphics.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef GRAPHICS_H
|
||||
#define GRAPHICS_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
void print_board(const tile_t board[BOARD_SIZE]);
|
||||
|
||||
#endif
|
||||
12
include/pieces.h
Normal file
12
include/pieces.h
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
#ifndef PIECES_H
|
||||
#define PIECES_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
bool move_ok(const tile_t board[BOARD_SIZE],
|
||||
index_t from,
|
||||
index_t to,
|
||||
int player);
|
||||
|
||||
#endif
|
||||
9
include/util.h
Normal file
9
include/util.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "common.h"
|
||||
|
||||
bool tile_empty(tile_t t);
|
||||
index_t abs_pos(index_t p);
|
||||
index_t column(index_t i);
|
||||
index_t row(index_t i);
|
||||
tile_t abs_tile(tile_t t);
|
||||
bool same_color(tile_t a, tile_t b);
|
||||
bool opposite_color(tile_t a, tile_t b);
|
||||
Reference in New Issue
Block a user