/*
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 ct. 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;
typedef struct tak_state_s {
data_t celldat[36];
colour_stack_t colours[36];
enum WIN_TYPE won;
enum COLOUR current_colour;
uint8_t white_count, black_count, ply, board_size;
} *tak_state_p;
#define NUM_SHIFT 4
#define NUM_MASK (0xF << NUM_SHIFT) // 0b11110000
#define NUM_INC (0x1 << NUM_SHIFT) // 0b00010000
#define STONE_MASK 3 // 0b00000011
#define STONE_AT(state, l) (state->celldat[(l)] & STONE_MASK)
#define COUNT_AT(state, l) (state->celldat[(l)] >> NUM_SHIFT)
#define THE_COORDS(board_size, col, row) ((col) + (row)*board_size)
// ===================================================================
// Methods
// ===================================================================
tak_state_p new_tak_state(const uint8_t board_size);
void free_tak_state(tak_state_p state);
// -------------------------------------------------------------------
// Game state
void reset_state(tak_state_p state, const uint8_t new_board_size);
void next_ply(tak_state_p state);
enum ACT_RESULT try_place(tak_state_p state, const int8_t location,
const enum COLOUR colour,
const enum STONE_VARIANT stone);
enum ACT_RESULT try_move(tak_state_p state, const int8_t location,
const enum MOVE_DIRECTION direction,
const uint8_t steps, const uint8_t drops[5]);
enum WIN_TYPE check_win(tak_state_p state);
// -------------------------------------------------------------------
// PTN related
enum PTN_RESULT parse_place(const uint8_t board_size, char *in_ptn,
uint8_t *out_location,
enum STONE_VARIANT *out_stone);
enum PTN_RESULT parse_move(const uint8_t board_size, 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 board_size, const uint8_t in_location,
const enum STONE_VARIANT in_stone, char out_ptn[4]);
void generate_move(const uint8_t board_size, 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(tak_state_p state, char *ptn);
#endif