Hello, i've been reading a little about linked lists and trees and such and i'm trying to make a (simple <- keyword, ha) decision tree. As of now i'm just trying to setup the tree.
I need some help, maybe everyone can see what i'm trying to do from the code here, thanks!
I realize this is probably completely wrong, ha, but i'm trying, as you can also see i'm getting into the meat of the tree and pseudocoding the rest, i actually have a program working now but without the AI which is the fundamental part.Code:#include <iostream> using namespace std; enum{COMPUTER = 1, PLAYER = 2, EMPTY = 0}; //For the purposes of the Tree the boxes will be referred to by the tree as such: /* [1][2][3] [4][5][6] [7][8][9] */ //Tree Structure struct node { int nBoard[3][3]; int depth; int value; node *parent; node *link[9]; }; //Coordinate Structure struct coordinate { int c; int r; }_coordinate; //Global Variables int board[3][3] = {{EMPTY, EMPTY, EMPTY}, {EMPTY, EMPTY, EMPTY}, {EMPTY, EMPTY, EMPTY}}; node *start; node *current; //Function Prototypes void displayBoard(int board[3][3]); void computerMove(int board[3][3]); void chooseMove(int board[3][3]); bool createTree(); void addNodes(node *parent); void copyParentBoard(node *parent); //Main int main() { displayBoard(board); cin.ignore(); return 0; } //Display The Board Function void displayBoard(int board[3][3]) { //Display The Board Function cout<<"\n\n"; cout<<"\t 1 2 3\n"; cout<<"\t _ _ _\n"; for(int c=0; c<3; c++) { cout<<"\t"; cout<<(c+1)<<" "; for(int r=0; r<3; r++) { if(board[c][r] == COMPUTER) { cout<<"|O|"; } else if(board[c][r] == PLAYER) { cout<<"|X|"; }else{ cout<<"|_|"; } } cout<<"\n"; } } //Move the Computer Function void computerMove(int board[3][3]) { //Moves the Computer } //Choose the Move Function void chooseMove(int board[3][3]) { //choose the best move } //Function which sets up the Tree bool createTree() { //Setup the Tree, once //Setup Start node start->parent = NULL; start->depth = 0; start->nBoard[3][3] = NULL; start->value = 0; return true; } void addNodes(node *parent, int cDepth) { //Add the 9 Nodes to the parent node *nNode1, *nNode2, *nNode3, *nNode4, *nNode5, *nNode6, *nNode7, *nNode8, *nNode9; nNode1 = new node; nNode2 = new node; nNode3 = new node; nNode4 = new node; nNode5 = new node; nNode6 = new node; nNode7 = new node; nNode8 = new node; nNode9 = new node; //Setup Variables nNode1->depth = nNode2->depth = nNode3->depth = nNode4->depth = nNode5->depth = nNode6->depth = nNode7->depth = nNode8->depth = nNode9->depth = cDepth; nNode1->parent = nNode2->parent = nNode3->parent = nNode4->parent = nNode5->parent = nNode6->parent = nNode7->parent = nNode8->parent = nNode9->parent = parent; //Adjust Parent Node - Link to Children parent->link[0] = nNode1; parent->link[1] = nNode2; parent->link[2] = nNode3; parent->link[3] = nNode4; parent->link[4] = nNode5; parent->link[5] = nNode6; parent->link[6] = nNode7; parent->link[7] = nNode8; parent->link[8] = nNode9; } void copyParentBoard(node *parent) { for(int n=0; n<9; n++) { for(int col=0; col<3; col++) { for(int row=0; row<3; row++) { &parent->link[n]->nBoard[col][row] = parent->nBoard[col][row]; } } } }
Thanks!



LinkBack URL
About LinkBacks




