feat: complete human-vs-ESP32 gameplay and cumulative statistics
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
typedef struct { command_queue_t command_queue; game_lifecycle_t lifecycle; } application_t;
|
||||
|
||||
void application_init(application_t *application, random_source_t random);
|
||||
void application_set_bot_scheduler(application_t *application, scheduler_t scheduler);
|
||||
bool application_enqueue(application_t *application, const app_command_t *command);
|
||||
bool application_take_next_command(application_t *application, app_command_t *command);
|
||||
lifecycle_result_t application_join(application_t *application, role_t requested_role, const char *name,
|
||||
@@ -18,3 +19,4 @@ lifecycle_result_t application_resume(application_t *application,
|
||||
bool application_session_for_token(const application_t *application,
|
||||
const uint8_t token[kSessionTokenBytes], uint8_t *session_index);
|
||||
lifecycle_result_t application_submit(application_t *application, const app_command_t *command);
|
||||
bool application_bot_take_turn(application_t *application);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "fleet_generator.h"
|
||||
#include "bot_player.h"
|
||||
#include "game_engine.h"
|
||||
#include "session_manager.h"
|
||||
#include "statistics.h"
|
||||
@@ -28,12 +29,15 @@ typedef struct {
|
||||
session_manager_t sessions;
|
||||
cumulative_statistics_t cumulative[kPlayerCapacity];
|
||||
random_source_t random;
|
||||
bot_player_t bot;
|
||||
scheduler_t bot_scheduler;
|
||||
bool bot_reserved;
|
||||
bool rematch_confirmed[kPlayerCapacity];
|
||||
uint32_t next_game_id;
|
||||
} game_lifecycle_t;
|
||||
|
||||
void game_lifecycle_init(game_lifecycle_t *lifecycle, random_source_t random);
|
||||
void game_lifecycle_set_bot_scheduler(game_lifecycle_t *lifecycle, scheduler_t scheduler);
|
||||
lifecycle_result_t game_lifecycle_join(game_lifecycle_t *lifecycle, role_t requested_role, const char *name,
|
||||
uint8_t *session_index);
|
||||
lifecycle_result_t game_lifecycle_resume(game_lifecycle_t *lifecycle,
|
||||
@@ -47,5 +51,6 @@ lifecycle_result_t game_lifecycle_shot(game_lifecycle_t *lifecycle, uint8_t sess
|
||||
coordinate_t coordinate, shot_result_t *result);
|
||||
lifecycle_result_t game_lifecycle_rematch(game_lifecycle_t *lifecycle, uint8_t session_index, uint32_t game_id);
|
||||
lifecycle_result_t game_lifecycle_abort(game_lifecycle_t *lifecycle, uint8_t session_index, uint32_t game_id);
|
||||
bool game_lifecycle_bot_take_turn(game_lifecycle_t *lifecycle);
|
||||
|
||||
_Static_assert(sizeof(game_lifecycle_t) <= 1600, "lifecycle state grew beyond fixed budget");
|
||||
|
||||
@@ -19,6 +19,7 @@ typedef enum {
|
||||
HTTP_API_ROUTE_REMATCH,
|
||||
HTTP_API_ROUTE_ABORT,
|
||||
HTTP_API_ROUTE_STATE,
|
||||
HTTP_API_ROUTE_STATISTICS,
|
||||
} http_api_route_t;
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -4,4 +4,12 @@
|
||||
|
||||
#include "game_types.h"
|
||||
|
||||
typedef struct { uint16_t games; uint16_t wins; uint16_t losses; uint32_t shots; uint32_t hits; } cumulative_statistics_t;
|
||||
typedef struct {
|
||||
uint16_t games;
|
||||
uint16_t wins;
|
||||
uint16_t losses;
|
||||
uint16_t ships_sunk;
|
||||
uint32_t shots;
|
||||
uint32_t hits;
|
||||
uint32_t misses;
|
||||
} cumulative_statistics_t;
|
||||
|
||||
Reference in New Issue
Block a user