go-tui

Une TUI pour jouer au go - retour accueil

git clone git://bebou.netlib.re/go-tui

Log | Files | Refs |

commit ed4732fef380d4383c0db356ebb7e9413137ab73
parent a1917e47b76484f1cd00021ed9c20da60add682b
Auteurice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Wed, 16 Jul 2025 16:40:59 +0200

Ajout d'une structure de liste de pierres

Pour préparer les listes des pierres capturées

Diffstat:
Mgotui.c | 45++++++++++++++++++++++++++++-----------------
1 file changed, 28 insertions(+), 17 deletions(-)

diff --git a/gotui.c b/gotui.c @@ -10,6 +10,18 @@ struct stone { int color; }; +struct stone_list { + struct stone* list; + int count; +}; + +struct stone_list new_stone_list() { + struct stone_list s; + s.count=0; + s.list=malloc(sizeof(struct stone)*100); + return s; +} + /*Game function*/ struct stone create_stone(int x, int y, int color) { @@ -18,11 +30,10 @@ struct stone create_stone(int x, int y, int color) { return s; } -int spot_is_taken(struct stone* stone_list, int stone_count, int x, int y) { - for (int i=0;i<stone_count;i++) { - if (stone_list[i].x==x && stone_list[i].y==y) +int spot_is_taken(struct stone_list s_list, int x, int y) { + for (int i=0;i<s_list.count;i++) + if (s_list.list[i].x==x && s_list.list[i].y==y) return i; - } return -1; } @@ -50,12 +61,12 @@ void print_line(int y, int size) { } } -void display(struct stone* stone_list, int count, int size) { +void display(struct stone_list s_list, int size) { for (int i=0;i<size;i++) print_line(i,size); - for(int i=0;i<count;i++) { - if(stone_list[i].color==BLACK) tb_printf(stone_list[i].x,stone_list[i].y,0,0,"○"); - else tb_printf(stone_list[i].x,stone_list[i].y,0,0,"●"); + for(int i=0;i<s_list.count;i++) { + if(s_list.list[i].color==BLACK) tb_printf(s_list.list[i].x,s_list.list[i].y,0,0,"○"); + else tb_printf(s_list.list[i].x,s_list.list[i].y,0,0,"●"); } } @@ -69,13 +80,13 @@ int main(int argc, char **argv) { tb_hide_cursor(); tb_set_input_mode(TB_INPUT_ESC | TB_INPUT_MOUSE); struct tb_event ev; - struct stone stone_list[100]; - int stone_count=0; - int color;color=BLACK; + struct stone_list s_list=new_stone_list(); + struct stone_list c_list=new_stone_list(); + int color=BLACK; while(1) { tb_clear(); - display(stone_list,stone_count,size); + display(s_list,size); tb_present(); tb_poll_event(&ev); @@ -87,16 +98,16 @@ int main(int argc, char **argv) { switch(input) { case 65512: /*MouseLeft*/ if(ev.x<0 || ev.x>size*2+2 || ev.x <0 || ev.y>size-1 || ev.x%2) break; - spot=spot_is_taken(stone_list,stone_count,ev.x,ev.y); + spot=spot_is_taken(s_list,ev.x,ev.y); if(spot!=-1) { - for (int j=spot;j<stone_count;j++) stone_list[j]=stone_list[j+1]; - stone_count--; + for (int j=spot;j<s_list.count;j++) s_list.list[j]=s_list.list[j+1]; + s_list.count--; if(color==BLACK) { color=WHITE; } else { color=BLACK; } break; } s=create_stone(ev.x,ev.y,color); - stone_list[stone_count]=s; - stone_count++; + s_list.list[s_list.count]=s; + s_list.count++; if(color==BLACK) { color=WHITE; } else { color=BLACK; } break; case 113: