Files
2026-08-30 23:42:26 +03:00

40 lines
1.6 KiB
C

#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "app_config.h"
typedef uint8_t cell_t;
enum { CELL_UNKNOWN, CELL_WATER, CELL_SHIP, CELL_MISS, CELL_HIT };
typedef uint8_t phase_t;
enum { PHASE_LOBBY, PHASE_PREPARING, PHASE_IN_PROGRESS, PHASE_FINISHED, PHASE_REMATCH_WAIT };
typedef uint8_t role_t;
enum { ROLE_PLAYER_1, ROLE_PLAYER_2, ROLE_SPECTATOR, ROLE_AUTO_PLAYER };
typedef uint8_t game_mode_t;
enum { MODE_HUMAN, MODE_BOT };
typedef struct { uint8_t x; uint8_t y; } coordinate_t;
typedef struct { uint8_t x; uint8_t y; uint8_t length; uint8_t hits; bool horizontal; } ship_t;
typedef struct { cell_t cells[kBoardCellCount]; ship_t ships[kFleetShipCount]; uint8_t ships_alive; } board_t;
typedef struct { uint16_t shots; uint16_t hits; uint16_t misses; uint8_t ships_sunk; } match_statistics_t;
typedef struct {
uint32_t game_id;
uint32_t version;
phase_t phase;
game_mode_t mode;
uint8_t current_player;
uint8_t winner;
board_t boards[kPlayerCapacity];
match_statistics_t statistics[kPlayerCapacity];
} game_state_t;
_Static_assert(kBoardCellCount == 100, "board contract changed");
_Static_assert(kFleetShipCount == 10, "fleet contract changed");
_Static_assert(kSessionCapacity == 10, "session contract changed");
_Static_assert(sizeof(coordinate_t) == 2, "coordinate must remain compact");
_Static_assert(sizeof(ship_t) <= 6, "ship grew beyond fixed budget");
_Static_assert(sizeof(board_t) <= 164, "board grew beyond fixed budget");
_Static_assert(sizeof(match_statistics_t) <= 8, "statistics grew beyond fixed budget");
_Static_assert(sizeof(game_state_t) <= 360, "game state grew beyond fixed budget");