-
Notifications
You must be signed in to change notification settings - Fork 0
/
PieceTree.h
63 lines (53 loc) · 1.41 KB
/
PieceTree.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
//
// PieceTree.h
// Chess
//
// Created by Albaraa on 3/21/14.
// Copyright (c) 2014 Albaraa. All rights reserved.
//
#ifndef __Chess__PieceTree__
#define __Chess__PieceTree__
#include "Piece.h"
#include <iostream>
struct PieceNode{
PieceMove currentMove;
Piece* chessBoard[9][9];
std::vector<PieceNode*> children;
PieceNode* parent;
int nodeDepth;
int currentOwner;
int totalPoints;
PieceNode(){};
PieceNode(Piece* (&chessBoard)[9][9], PieceNode* parent, PieceMove currentMove, int totalPoints){
for (size_t rank=8; rank>0; rank--){
for (size_t file=1; file<=8; file++){
if(chessBoard[rank][file] != NULL){
this->chessBoard[rank][file] = chessBoard[rank][file]->clone();
} else {
this->chessBoard[rank][file] = NULL;
}
}
}
this->parent = parent;
this->currentMove = currentMove;
this->children = std::vector<PieceNode*>();
this->totalPoints = totalPoints;
if(parent != NULL){
this->nodeDepth = parent->nodeDepth + 1;
} else {
this->nodeDepth = 0;
}
}
~PieceNode(){};
};
class PieceTree{
private:
PieceNode root;
public:
PieceTree();
PieceTree(Piece* (&chessBoard)[9][9], PieceMove lastMove);
PieceNode* getRoot();
PieceNode* insert(Piece* (&chessBoard)[9][9], PieceNode* parent, PieceMove currentMove, int totalPoints);
~PieceTree();
};
#endif /* defined(__Chess__PieceTree__) */