summaryrefslogtreecommitdiff
path: root/src/engine/moves.h
blob: 86c4844e6cb2942b511bec8564ab19c2a9a91759 (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef MOVES_H
#define MOVES_H

#include "../ints.h"
#include "../bitboard.h"

typedef u8 square_t;

// think about the chess move notation
// e4, Nf6, Qh3+, Qe1#, a8=Q, i need to store the information needed to
// recreate this in move_t
enum {
  MOVE_CAPTURE       =  1,                                          
  MOVE_SHORT_CASTLE  =  1 << 1,                                  
  MOVE_LONG_CASTLE   =  1 << 2,                                  

  // technically these promotation flags can be compressed to only use 2 bits..
  MOVE_PROMOTE_Q     =  1 << 3, // 1 <<  5
  MOVE_PROMOTE_R     =  1 << 4, // 2 <<  5
  MOVE_PROMOTE_B     =  1 << 5, // 3 <<  5
  MOVE_PROMOTE_N     =  1 << 6, // 4 <<  5 ? nvm it uses 3
  MOVE_EN_PASSANT    =  1 << 7,
  MOVE_CHECK         =  1 << 8,
};

typedef struct {
  square_t from;
  square_t to;
  u16 flags;
} move_t;
void position_make_move(position_t* position, move_t* move);

typedef struct {
  move_t* moves;
  u32 length;
  u32 capacity;
} moves_t;

moves_t moves_init();
moves_t moves_init_wcapacity(u32 capacity);
moves_t moves_empty();

struct add_move_params {
  u16 flags;
};
#define add_move(moves, from, to, ...) _add_move(\
  moves, \
  from, \
  to, \
  (struct add_move_params) { .flags = 0, __VA_ARGS__ }\
)
void _add_move(
  moves_t* moves,
  square_t from,
  square_t to,
  struct add_move_params params
);

void get_pawn_moves(moves_t* moves, position_t position);
void get_knight_moves(moves_t* moves, position_t position);
void get_king_moves(moves_t* moves, position_t position);
void get_rook_moves(moves_t* moves, position_t position);
void get_bishop_moves(moves_t* moves, position_t position);
void get_queen_moves(moves_t* moves, position_t position);

void get_moves(moves_t* moves, position_t position);

void __forloop_rook_moves_gen(
  moves_t* moves,
  bitboard_t friendly_type,
  bitboard_t friendly_pieces,
  bitboard_t enemy_pieces
);
void __forloop_bishop_moves_gen(
  moves_t* moves,
  bitboard_t friendly_type,
  bitboard_t friendly_pieces,
  bitboard_t enemy_pieces
);

#endif // !MOVES_H