include/utilities.h

Classes

Name
struct play Linked dtructure used to represent placing a tile on the board. It contains the coefficients for MCTS.
struct tree Tree used for MCTS.
struct linked_plays Wrapper for play_t that adds the size of the linked list.

Types

Name
typedef struct play play_t Linked dtructure used to represent placing a tile on the board. It contains the coefficients for MCTS.
typedef struct tree tree_t Tree used for MCTS.
typedef struct linked_plays linked_plays_t Wrapper for play_t that adds the size of the linked list.

Functions

Name
bool validity_tile(tile_t * tile_to_add)Check if a tile with the correct pointers in cell_tab is valid.
type_linked_t * add_level(tile_t * tile, type_linked_t * level, cell_type_e cell_type)declares a type_linked_t
void remove_level(cell_t * cell)Remove a level from a cell.
void add_tile(tile_t * tile)Update altitude and add level to all cells in the tile.
void undo_tile(tile_t * tile)Inverse of add_tile and put pointers of cells in the tile to NULL.
void undo_without_null_tile(tile_t * tile)Same as undo_tile bus does not puts the pointers to NULL.
bool cell_in_periphery(cell_t * cell)Test if cell is on the edge.
bool cell_isolated(cell_t * cell, cell_type_e cell_type)Test if cell has no neighbors of the same cell_type.
bool cell_circled(cell_t * cell)Test if cell is not on the edge.
int get_connex_size(bool * visited, cell_t * cell, cell_type_e cell_type)Returns the size of the linked space corresponding to cell_type given.
int get_connex_size_with_altitude(bool * visited, cell_t * cell, cell_type_e cell_type)Same as get_connex_size but multiply result by the altitude of the cell.
int maximum_connex_size_with_altitude(board_t * board, cell_type_e cell_type)Return the maximum connex size coefficented with altitude.
void calculate_score_from_table(board_t * board)Like the title says.
void update_scoring_table(board_t * board)Update the value of the score table. Operation describes addition (1) and soustraction (-1)
void print_table(scoring_table_t * table)print the score table
void update_scoring_table_rec(board_t * board, cell_t * cell, bool * visited)table is updated recursively
void update_scoring_table_rec_false_start(board_t * board)
void remove_tile_from_board(board_t * board, tile_t * tile)Remove table from the board and puts pointers to NULL.
void remove_tile_from_board_without_null_without_score(board_t * board, tile_t * tile)Remove tile from board without updating the score.
void remove_tile_from_board_without_null(board_t * board, tile_t * tile)Remove table from the board.
void add_tile_to_board(board_t * board, tile_t * tile)Same.
void add_tile_to_board_without_score(board_t * board, tile_t * tile)Flemme.
linked_plays_t * gen_tiles(cell_t ** cell_tab, tile_t * tile)Generate all plays associated to the current state of the board and the tile given.
linked_plays_t * fusion_linked_plays(linked_plays_t * linked_plays_1, linked_plays_t * linked_plays_2)Fusion two linked_plays_t lists.
linked_plays_t * gen_tiles_from_game(game_t * game, bool is_bot)Generates all possible plays from two tiles.
void update_deck(game_t * game, tile_t * tile, bool is_bot)Updates the deck.
void undo_deck(game_t * game, tile_t * tile, bool is_bot)Undo the deck.

Types Documentation

typedef play_t

typedef struct play play_t;

Linked dtructure used to represent placing a tile on the board. It contains the coefficients for MCTS.

typedef tree_t

typedef struct tree tree_t;

Tree used for MCTS.

typedef linked_plays_t

typedef struct linked_plays linked_plays_t;

Wrapper for play_t that adds the size of the linked list.

Functions Documentation

function validity_tile

bool validity_tile(
    tile_t * tile_to_add
)

Check if a tile with the correct pointers in cell_tab is valid.

function add_level

type_linked_t * add_level(
    tile_t * tile,
    type_linked_t * level,
    cell_type_e cell_type
)

declares a type_linked_t

function remove_level

void remove_level(
    cell_t * cell
)

Remove a level from a cell.

function add_tile

void add_tile(
    tile_t * tile
)

Update altitude and add level to all cells in the tile.

function undo_tile

void undo_tile(
    tile_t * tile
)

Inverse of add_tile and put pointers of cells in the tile to NULL.

function undo_without_null_tile

void undo_without_null_tile(
    tile_t * tile
)

Same as undo_tile bus does not puts the pointers to NULL.

function cell_in_periphery

bool cell_in_periphery(
    cell_t * cell
)

Test if cell is on the edge.

function cell_isolated

bool cell_isolated(
    cell_t * cell,
    cell_type_e cell_type
)

Test if cell has no neighbors of the same cell_type.

function cell_circled

bool cell_circled(
    cell_t * cell
)

Test if cell is not on the edge.

function get_connex_size

int get_connex_size(
    bool * visited,
    cell_t * cell,
    cell_type_e cell_type
)

Returns the size of the linked space corresponding to cell_type given.

function get_connex_size_with_altitude

int get_connex_size_with_altitude(
    bool * visited,
    cell_t * cell,
    cell_type_e cell_type
)

Same as get_connex_size but multiply result by the altitude of the cell.

function maximum_connex_size_with_altitude

int maximum_connex_size_with_altitude(
    board_t * board,
    cell_type_e cell_type
)

Return the maximum connex size coefficented with altitude.

function calculate_score_from_table

void calculate_score_from_table(
    board_t * board
)

Like the title says.

function update_scoring_table

void update_scoring_table(
    board_t * board
)

Update the value of the score table. Operation describes addition (1) and soustraction (-1)

function print_table

void print_table(
    scoring_table_t * table
)

print the score table

function update_scoring_table_rec

void update_scoring_table_rec(
    board_t * board,
    cell_t * cell,
    bool * visited
)

table is updated recursively

function update_scoring_table_rec_false_start

void update_scoring_table_rec_false_start(
    board_t * board
)

function remove_tile_from_board

void remove_tile_from_board(
    board_t * board,
    tile_t * tile
)

Remove table from the board and puts pointers to NULL.

function remove_tile_from_board_without_null_without_score

void remove_tile_from_board_without_null_without_score(
    board_t * board,
    tile_t * tile
)

Remove tile from board without updating the score.

function remove_tile_from_board_without_null

void remove_tile_from_board_without_null(
    board_t * board,
    tile_t * tile
)

Remove table from the board.

function add_tile_to_board

void add_tile_to_board(
    board_t * board,
    tile_t * tile
)

Same.

function add_tile_to_board_without_score

void add_tile_to_board_without_score(
    board_t * board,
    tile_t * tile
)

Flemme.

function gen_tiles

linked_plays_t * gen_tiles(
    cell_t ** cell_tab,
    tile_t * tile
)

Generate all plays associated to the current state of the board and the tile given.

function fusion_linked_plays

linked_plays_t * fusion_linked_plays(
    linked_plays_t * linked_plays_1,
    linked_plays_t * linked_plays_2
)

Fusion two linked_plays_t lists.

function gen_tiles_from_game

linked_plays_t * gen_tiles_from_game(
    game_t * game,
    bool is_bot
)

Generates all possible plays from two tiles.

function update_deck

void update_deck(
    game_t * game,
    tile_t * tile,
    bool is_bot
)

Updates the deck.

function undo_deck

void undo_deck(
    game_t * game,
    tile_t * tile,
    bool is_bot
)

Undo the deck.

Source code

/* name : utilities.h
 * authors : eloi petit, matheo thomas, domitille vale
 * date : 23-06-24
 */

#ifndef utilities_h 
#define utilities_h

#include <stdbool.h>
#include <stdint.h>
#include "init.h"
/* Struct definitions */

typedef struct play {
    tile_t * tile;
    int n_coup;
    float gain_coup;
    struct play * next;
} play_t;

typedef struct tree {
    play_t *play;
    struct tree *next;
} tree_t;

typedef struct linked_plays {
    int size;
    play_t * play;
} linked_plays_t;




/* Functions definitions */

bool validity_tile(tile_t * tile_to_add);

type_linked_t * add_level(tile_t * tile, type_linked_t * level, cell_type_e cell_type);

void remove_level(cell_t * cell);

void add_tile(tile_t * tile);

void undo_tile(tile_t * tile);

void undo_without_null_tile(tile_t * tile);

bool cell_in_periphery(cell_t * cell);

bool cell_isolated(cell_t * cell, cell_type_e cell_type);

bool cell_circled(cell_t * cell);

int get_connex_size(bool * visited, cell_t * cell, cell_type_e cell_type);

int get_connex_size_with_altitude(bool * visited, cell_t * cell, cell_type_e cell_type);

int maximum_connex_size_with_altitude(board_t * board, cell_type_e cell_type);

void calculate_score_from_table(board_t * board);

void update_scoring_table(board_t * board);

void print_table(scoring_table_t * table);

void update_scoring_table_rec(board_t * board, cell_t * cell, bool * visited);

void update_scoring_table_rec_false_start(board_t * board);

void remove_tile_from_board(board_t * board, tile_t * tile);

void remove_tile_from_board_without_null_without_score(board_t * board, tile_t * tile);

void remove_tile_from_board_without_null(board_t * board, tile_t * tile);

void add_tile_to_board(board_t * board, tile_t * tile);

void add_tile_to_board_without_score(board_t * board, tile_t * tile);

linked_plays_t * gen_tiles(cell_t ** cell_tab, tile_t * tile);

linked_plays_t * fusion_linked_plays(linked_plays_t * linked_plays_1, linked_plays_t * linked_plays_2);

linked_plays_t * gen_tiles_from_game(game_t * game, bool is_bot);

/*
 * Deck functions
 */

void update_deck(game_t *game, tile_t *tile, bool is_bot);

void undo_deck(game_t *game, tile_t *tile, bool is_bot);


#endif

Updated on 2024-06-28 at 08:11:56 +0200