/* This file is part of ct. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Takwrap. If not, see . */ #ifndef TAK_H #define TAK_H #include // =================================================================== // Types // =================================================================== enum ACT_RESULT { ACT_OK, ACT_ILLEGAL, ACT_OVERFLOW, ACT_INVALID_PTN, GAME_END }; enum PTN_RESULT { PTN_OK, PTN_INVALID }; enum TPS_RESULT { TPS_OK, TPS_INVALID }; enum COLOUR { C_WHITE, C_BLACK }; enum STONE_VARIANT { STONE_FLAT, STONE_STANDING, STONE_CAPSTONE }; enum MOVE_DIRECTION { M_UP, M_DOWN, M_LEFT, M_RIGHT }; enum WIN_TYPE { WIN_DRAW, WIN_FLAT_WHITE, WIN_FLAT_BLACK, WIN_ROAD_WHITE, WIN_ROAD_BLACK }; typedef uint8_t data_t; typedef uint16_t colour_stack_t; #define NUM_SHIFT 4 #define NUM_MASK (0xF<> NUM_SHIFT) #define THE_COORDS(col,row) ((col)+(row)*board_size) // =================================================================== // Variables // =================================================================== // NOTE: We only support one capstone per player and 5s or 6s games. extern enum WIN_TYPE won; extern uint8_t board_size; extern data_t celldat[36]; extern colour_stack_t colours[36]; extern enum COLOUR current_colour; extern uint8_t white_count, black_count, ply; // =================================================================== // Methods // =================================================================== // ------------------------------------------------------------------- // Game state void reset_state(const uint8_t new_board_size); void next_ply(void); enum ACT_RESULT try_place(const int8_t location, const enum COLOUR colour, const enum STONE_VARIANT stone); enum ACT_RESULT try_move(const int8_t location, const enum MOVE_DIRECTION direction, const uint8_t steps, const uint8_t drops[5]); enum WIN_TYPE check_win(void); // ------------------------------------------------------------------- // PTN related enum PTN_RESULT parse_place(char *in_ptn, uint8_t *out_location, enum STONE_VARIANT *out_stone); enum PTN_RESULT parse_move(char *in_ptn, uint8_t *out_location, enum MOVE_DIRECTION *out_direction, uint8_t *out_steps, uint8_t out_drops[5]); void generate_place(const uint8_t in_location, const enum STONE_VARIANT in_stone, char out_ptn[4]); void generate_move(const uint8_t in_location, const enum MOVE_DIRECTION in_direction, const uint8_t in_steps, const uint8_t in_drops[5], char out_ptn[10]); // ------------------------------------------------------------------- // Game driver enum ACT_RESULT do_ptn(char *ptn); #endif