-
Notifications
You must be signed in to change notification settings - Fork 0
/
MiniMax.h
69 lines (52 loc) · 1.75 KB
/
MiniMax.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* MiniMax.h
*
* Created on: 14 áàåâ× 2017
* Author: User
*/
#ifndef MINIMAX_H_
#define MINIMAX_H_
#include "GameBasicBuildingBlocks.h"
#include "GameBoard.h"
#define PAWN_VALUE 1
#define KNIGHT_VALUE 3
#define BISHOP_VALUE 3
#define ROOK_VALUE 5
#define QUEEN_VALUE 9
#define KING_VALUE 100
typedef enum {
MinNode,
MaxNode
} NodeType;
typedef struct Move {
int srow; // source row
int scol; // source col
int drow; // dest row
int dcol; // dest col
} Move;
typedef struct step_value {
Step *step;
int value; //value of the step
Piece_type promote_to; //in case of promotion: promote piece type
} StepValue;
/* sum-up all the pieces of the specified color */
int sumup_pieces(Gameboard *board, int color);
/* scoring function for the mini-max algorithm
* eval_pespective is the color of the root of the mini-max tree */
int eval(Gameboard *board, int eval_perspective);
/* return true if found a better option, and update alpha or beta if needed */
bool update_ab(int *alpha, int *beta, int step_value, NodeType node_type, bool first_move);
/* initial step value */
StepValue *init_step_value();
/* implementation of the MiniMax algorithm, using alpha-beta pruning
* assuming we can alter the board as we will, and that the game is not over
* node-types:
* 0 - min-node
* 1 - max-node */
StepValue *MiniMaxAlgo(Gameboard *board, int alpha, int beta, int search_depth, NodeType node_type, int eval_perspective, bool first_option);
/* we assume the game is not over
* a wrapper function for the mini-max algo */
StepValue *find_best_step(Gameboard *board, int search_depth);
/* destroys a StepValue */
void destroy_step_value(StepValue *best_move);
#endif /* MINIMAX_H_ */