2.2 KiB
AnnaConnect
AnnaConnect is a silly little text-based connect 4 game c:
Supports vt100 escape codes and ncurses for drawing the UI. There is also an option to let the game (randomly) play itself for testing, which does not need a UI.
Header files
types.h
The types.h file defines the types used in all of the program.
Integer types
rowsint_t: row numbers.columnsint_t: columns numbers.winint_t: amount of wins.column_t: the bit field of the pieces in a column, LSB is the bottom of the board.
Structs
wincount_t
This struct has all counts for all the wins made my a players.
winint_t total: total amount of winswinint_t horizontal: amount of wins from a horizontal linewinint_t vertical: amount of wins from a vertical linewinint_t diagonalUp: amount of wins from a line going diagonally up (from left to right)winint_t diagonalDown: amount of wins from a line going diagonally down (from left to right)
board_t
This struct has an enire board.
bool player: The current playerrowsint_t *height: An array with the amount of pieces in each columncolumn_t *column: An array of all the columns in the boardrowsint_t rows: The amount of rows the baord hascolumnint_t columns: The amount of columns the board haswincount_t count0: A struct holding the counts of wins player 0 has gottenwincount_t count1: A struct holding the counts of wins player 1 has gotten
ui.h
The ui.h file describes the functions each ui_*.c user interface is expected to implement.
These should be ass cross-platform as possible for the used backend.
So for example the ui_vt100.c supports all platforms where vt100 escape codes are supported.
When implementing a new ui, you can start from ui_stub.c.
This "ui" is just the bare minimum to let the rest of the code work.
commandline.h
The commandline.h file has the function that handles command-line argument parsing.
logic.h
The logic.h file has the types used in logic.c and the functions it exposes.
macros.h
The macros.h file has macros for simple stuff.
config.h
The config.h defines default board size, and wether or not the displayed row and column numbers start at 0.