Skip to content

Commit

Permalink
Add comment field to tnode struct #27
Browse files Browse the repository at this point in the history
  • Loading branch information
SmekhMaksimgithub committed Jul 15, 2023
1 parent 77db84a commit cedf47d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/state_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
void init_tree(state_tree*, const game_state*);
void clear_tree(state_tree*);

tnode * addnode(game_state, tnode*, const char* last_move);
tnode * addnode(game_state, tnode*, const char*, const char*);
void destroy_tnode(tnode*);

int tnode_equals(const tnode*, const tnode*);
Expand Down
1 change: 1 addition & 0 deletions include/typedecl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ typedef struct
game_state state;
struct tnode* parent;
GList* children;
char* comment;
int hbox_status;// remove
int indent; // remove
GtkBox* hbox; // remove
Expand Down
2 changes: 1 addition & 1 deletion src/notation.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void show_state(tnode* node, int level)
for(int i = 3; i< 62;i++) {
text[i] = '-';
}
text[61] = '\0';
text[62] = '\0';
}
else
text = get_sign(1,' ');
Expand Down
3 changes: 1 addition & 2 deletions src/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ void next_move(__attribute_maybe_unused__ const game_state* state, char piece, i
clear_enpassant(&new_state);
char move_buffer[6] = "";
get_move_notation(&new_state, move_buffer, from_row, from_col, to_row, to_col, promotion);

//
tree.current = addnode(new_state, tree.current, move_buffer);
tree.current = addnode(new_state, tree.current, move_buffer, NULL);
show_notation(&tree);
//
}
Expand Down
21 changes: 18 additions & 3 deletions src/state_tree.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
#include "state_tree.h"
#include "state.h"
//#define DEBUG_STATE_TREE

// allocates
tnode* addnode(game_state _field, tnode *_parent, const char *last_move)
// allocates node, by default set _comment as NULL
tnode* addnode(game_state _field, tnode *_parent, const char *_last_move, const char* _comment)
{
tnode* new_node = malloc(sizeof(tnode));
new_node->state = _field;
new_node->children = NULL;
strcpy(new_node->last_move_notation, last_move);
strcpy(new_node->last_move_notation, _last_move);
if(_comment==NULL)
{
new_node->comment = NULL;
}
else
{
new_node->comment = malloc(strlen(_comment));
strcpy(new_node->comment, _comment);
}

new_node->hbox = NULL;
new_node->vbox = NULL;
(*new_node).hbox_status=0;
Expand Down Expand Up @@ -36,6 +47,7 @@ void init_tree(state_tree* tree, const game_state* state)
tree->root->parent = NULL;
tree->root->children = NULL;
strcpy(tree->root->last_move_notation, "begin");
tree->root->comment=NULL;
tree->root->hbox_status=0;
tree->root->indent=0;
tree->root->hbox = NULL;
Expand Down Expand Up @@ -64,6 +76,9 @@ void destroy_tnode(tnode* node)
}
g_list_free(element);
}
if(node->comment!=NULL)
free(node->comment);

free(node);
}

Expand Down

0 comments on commit cedf47d

Please sign in to comment.