-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcBoardState.h
More file actions
106 lines (86 loc) · 3.09 KB
/
cBoardState.h
File metadata and controls
106 lines (86 loc) · 3.09 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* boardState.h
*
* Created on: Jul 25, 2018
* Author: mduarte
*/
#ifndef BOARDSTATE_H_
#define BOARDSTATE_H_
#include <iostream>
#include <string>
#include <vector>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <algorithm>
#include <pthread.h>
#include "mpi.h"
#include "cHash.h"
#include "types.h"
extern int rank, worldSize;
extern MPI_Datatype customType;
extern int pawnSquare[64], knightSquare[64], bishopSquare[64];
extern int rookSquare[64], queenSquare[64], kingSquare[64], kingEndGame[64];
class cBoardState
{
private:
int mTurn; //turn counter
int mState; //gameState value from above
int mWScore;
int mBScore; //total board score, see computeValidMoves()
int mBoard[8][8];
int mEnPassant[2]; //coordinates of piece that can be captured en passant
int mWLostCastle; //what turn did white lose castling ability?
int mBLostCastle;
int mEndGame;
int mNumCheckMoves; //number of moves the ai checked, for fun
bool mWCheck; //is white in check?
bool mBCheck;
static cHash *mHash;
std::vector<gameMove> mMoveList; //list of moves that have been played
std::vector<gameMove> mValidList; //list of legal moves that can be played this turn
void fAddPieceMoves(int i, int j); //add moves for the piece at the given coordinates
void fAddPawnMoves(int i, int j);
void fAddKnightMoves(int i, int j);
void fAddHorVertMoves(int i, int j); //add horizontal and vertical moves for piece
void fAddDiagMoves(int i, int j); //add diagonal moves
void fAddKingMoves(int i, int j);
void fAddMove(int i, int j, int i2, int j2, int list); //add move to the given list
void fPrintMoves(int list);
std::string fPrintPiece(int piece);
void fMove(gameMove *m); //perform the given move on the board
void fIsInCheck(); //update values if current player's king is in check
void fRemoveChecks(); //remove moves that result in check
bool fCanMove(int i, int j);
bool fMoveIsValid(gameMove *m);
bool fCheckMoves(gameMove *m); //check if the given move is in the validList
mpiBoardState* fToStruct();
void fMPIGetBoardState(); //for MPI compute threads to get board from root thread
//alpha beta pruning, used to find the "best" move the ai can make
int fAlphaBeta(gameMove* m, int maxPlayer, int alpha, int beta, int depth, int& checkMoves);
//driver function for alpha beta used by threads
static void *fAlphaBetaDriver(void *args);
public:
cBoardState();
cBoardState(const cBoardState &b2);
cBoardState(mpiBoardState *m);
void fComputeValidMoves();
void fPrintBoard();
void fProcessMove(gameMove *m);
void fUndoMove();
void fCleanup();
void fMPISendBoardState();
gameMove* fMPIGetBestMove();
void fAiCalculateMove();
int fGetState();
int fGetTurn();
int fGetCheckMoves();
int fGetListCount(int list);
};
typedef struct threadArgs
{
cBoardState* bs;
int start;
int stop;
} threadArgs;
#endif /* BOARDSTATE_H_ */