include/algos.h
Classes
Name | |
---|---|
struct | play contains all info to make a play |
struct | tree node of the tree made by/for the min-max algorithm |
Types
Name | |
---|---|
typedef struct play | play_t contains all info to make a play |
typedef struct tree | tree_t node of the tree made by/for the min-max algorithm |
Functions
Name | |
---|---|
int | max_value(int a, int b)return the max value of a and b |
int | min_value(int a, int b)return the min value of a and b |
int | max(tree_t * tree, bool player)returns the max/min value of a tree node, depending on the player turn |
play_t * | max_play(tree_t * tree)return the max play of a tree node |
int | basic_heuristic(cell_t ** cell_tab)basic heuristic function maximizing the ratio between our cells and the adversary |
play_t * | choose_play(board_t * board, cell_t ** cell_tab, bool player)returns the best play depending on the player |
board_t * | apply_play(board_t * board, play_t * play)applies a play to the board |
board_t * | undo_play(board_t * board, play_t * play)reverts a play to the board |
int | eval(board_t * board, cell_t ** cell_tab, int depth, int max_depth, bool player, int alpha, int beta)applies the min-max algorithm |
Defines
Name | |
---|---|
algos_h |
Types Documentation
typedef play_t
typedef struct play play_t;
contains all info to make a play
typedef tree_t
typedef struct tree tree_t;
node of the tree made by/for the min-max algorithm
Functions Documentation
function max_value
int max_value(
int a,
int b
)
return the max value of a and b
function min_value
int min_value(
int a,
int b
)
return the min value of a and b
function max
int max(
tree_t * tree,
bool player
)
returns the max/min value of a tree node, depending on the player turn
function max_play
play_t * max_play(
tree_t * tree
)
return the max play of a tree node
function basic_heuristic
int basic_heuristic(
cell_t ** cell_tab
)
basic heuristic function maximizing the ratio between our cells and the adversary
function choose_play
play_t * choose_play(
board_t * board,
cell_t ** cell_tab,
bool player
)
returns the best play depending on the player
function apply_play
board_t * apply_play(
board_t * board,
play_t * play
)
applies a play to the board
function undo_play
board_t * undo_play(
board_t * board,
play_t * play
)
reverts a play to the board
function eval
int eval(
board_t * board,
cell_t ** cell_tab,
int depth,
int max_depth,
bool player,
int alpha,
int beta
)
applies the min-max algorithm
Macros Documentation
define algos_h
#define algos_h
Source code
/* name : algos.h
* authors : eloi petit, matheo thomas, domitille vale
* date : 18-06-24
*/
#include <stdbool.h>
#include "init.h"
#include "graphics.h"
#ifndef algos_h
#define algos_h
/* Struct definitions */
typedef struct play {
cell_t *cell_tab[5];
state_e buffer[5];
int cell_tab_length;
int movement_direction;
int cell_direction;
} play_t;
typedef struct tree {
struct tree *next_tree;
play_t *play;
int value;
int depth;
} tree_t;
/* Functions definitions */
int max_value(int a, int b);
int min_value(int a, int b);
int max(tree_t *tree, bool player);
play_t *max_play(tree_t *tree);
int basic_heuristic(cell_t **cell_tab);
play_t *choose_play(board_t *board, cell_t **cell_tab, bool player);
// play_t *choose_play(board_t *board, graphics_t *g, cell_t **cell_tab);
board_t *apply_play(board_t *board, play_t *play);
board_t *undo_play(board_t *board, play_t *play);
int eval(board_t *board, cell_t **cell_tab, int depth, int max_depth, bool player, int alpha, int beta);
#endif