2024-07-14 02:45:09 -07:00
|
|
|
#ifndef CONNECT4_H_
|
|
|
|
|
#define CONNECT4_H_
|
|
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
|
|
enum Tile {
|
2024-07-14 03:51:47 -07:00
|
|
|
BLACK = -1,
|
2024-07-14 02:45:09 -07:00
|
|
|
EMPTY = 0,
|
2024-07-14 03:51:47 -07:00
|
|
|
RED = 1,
|
2024-07-14 02:45:09 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Board {
|
|
|
|
|
size_t height;
|
|
|
|
|
size_t width;
|
|
|
|
|
size_t *tile_heights;
|
|
|
|
|
enum Tile *tilemap;
|
|
|
|
|
enum Tile next_player;
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-14 03:51:47 -07:00
|
|
|
#define IDX(i, j, board) (board->tilemap[j*(board->width) + i])
|
2024-07-14 02:45:09 -07:00
|
|
|
|
|
|
|
|
// Returns a board struct with height and width based on parameters
|
|
|
|
|
struct Board *make_board(size_t height, size_t width);
|
|
|
|
|
|
2024-07-15 18:57:53 -07:00
|
|
|
void free_board(struct Board *board);
|
|
|
|
|
|
2024-07-14 02:45:09 -07:00
|
|
|
// Drops a tile, returns 0 if successful, -1 if error, and 1 if the move won
|
|
|
|
|
int drop_tile(struct Board *board, size_t drop_pos);
|
|
|
|
|
|
|
|
|
|
// Prints the supplied board
|
|
|
|
|
void print_board(struct Board *board);
|
|
|
|
|
|
|
|
|
|
#endif // !CONNECT4_H_
|