AnnaConnect/logic.h
2025-08-14 18:38:22 +02:00

54 lines
1 KiB
C

/* SPDX-License-Identifier: GPL-2.0-only */
#pragma once
#include <stddef.h>
#include "config.h"
#include "types.h"
// Types for using a bit more ram to avoid duplicated computations
typedef struct {
column_t *vertical2;
column_t *horizontal2;
column_t *diagonalUp2;
column_t *diagonalDown2;
column_t *vertical4;
column_t *horizontal4;
column_t *diagonalUp4;
column_t *diagonalDown4;
} directions_t;
typedef struct {
column_t *win0;
column_t *win1;
directions_t same;
} wins_t;
extern winint_t countcmp(
const board_t a,
const board_t b
);
// Get a random column in the board
extern columnsint_t randomColumn(
const board_t board
);
// Put a piece in the board
extern void playMove(
board_t *boardptr,
const columnsint_t column
);
// Calculate wins
extern void calcWins(
// Null pointer on systems where the extra ram is not available
wins_t *wins,
board_t *boardptr,
const columnsint_t column
);
// Reference implementation for calculating wins,
// slow AF especially on big boards
extern void calcWins_slow(
board_t *boardptr
);