go-tui

Une TUI pour jouer au go - retour accueil

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

Log | Files | Refs | README |

commit e8e38dab4e258254b532a2b23971c551975e69a6
parent 2932c12cb9c360b522a1f75d12efe5a403dfc8aa
Auteurice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Fri, 18 Jul 2025 20:46:29 +0200

Revert "On peut remonter dans le temps !"

This reverts commit 2932c12cb9c360b522a1f75d12efe5a403dfc8aa.

En fait c'est n'importe quoi, on va opter pour autre chose

Diffstat:
Mgotui.c | 75++++++++++++---------------------------------------------------------------
1 file changed, 12 insertions(+), 63 deletions(-)

diff --git a/gotui.c b/gotui.c @@ -15,17 +15,6 @@ struct stone_list { int count; }; -struct game_state { - struct stone_list played_list; - struct stone_list captured_list; - int color_to_play; -}; - -/*Helper functions*/ - -int max(int a, int b) { return a > b ? a : b; } -int min(int a, int b) { return a < b ? a : b; } - /*List functions*/ struct stone_list new_stone_list() { @@ -60,20 +49,6 @@ int spot_is_taken(struct stone_list s_list, int x, int y) { return -1; } -struct game_state create_game_state(struct stone_list played_list, struct stone_list captured_list, int color) { - struct game_state g; - /*struct stone_list p=new_stone_list(); - struct stone_list c=new_stone_list(); - int co; - memcpy(&p,&played_list,played_list.count*sizeof(struct stone_list)); - memcpy(&c,&captured_list,captured_list.count*sizeof(struct stone_list)); - co=color;*/ - g.played_list=played_list; - g.captured_list=captured_list; - g.color_to_play=color; - return g; -} - /*Display functions*/ void print_line(int y, int size) { @@ -98,22 +73,21 @@ void print_line(int y, int size) { } } -void display(struct game_state g, int size, int turn) { +void display(struct stone_list s_list, struct stone_list c_list, int size) { for (int i=0;i<size;i++) print_line(i,size); - for(int i=0;i<g.played_list.count;i++) { - if(g.played_list.list[i].color==BLACK) tb_printf(g.played_list.list[i].x,g.played_list.list[i].y,0,0,"○"); - else tb_printf(g.played_list.list[i].x,g.played_list.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,"●"); } int bc=0; int ac=0; - for(int i=0;i<g.captured_list.count;i++) { - if(g.captured_list.list[i].color==BLACK) bc++; - else ac++; + for(int i=0;i<c_list.count;i++) { + if(c_list.list[i].color==BLACK) bc++; + else ac++; } tb_printf(0,size,0,0,"%d ○ capturées",bc); tb_printf(0,size+1,0,0,"%d ● capturées",ac); - tb_printf(0,size+2,0,0,"tour : %d",turn); - tb_print(0,size+4,0,0,"q pour quitter"); + tb_print(0,size+2,0,0,"\nq pour quitter"); } /* Main */ @@ -121,29 +95,18 @@ void display(struct game_state g, int size, int turn) { int main(int argc, char **argv) { int size=9; if (argc>1) { size=atoi(argv[1]); } - + int input=0; tb_init(); tb_hide_cursor(); tb_set_input_mode(TB_INPUT_ESC | TB_INPUT_MOUSE); struct tb_event ev; - int input=0; - - struct game_state history[1000]; - int turn=0; - int shown_turn=turn; - struct stone_list s_list=new_stone_list(); struct stone_list c_list=new_stone_list(); int color=BLACK; - struct game_state g=create_game_state(s_list,c_list,color); - history[turn]=g; - turn++; - shown_turn++; - while(1) { tb_clear(); - display(history[shown_turn-1],size,shown_turn); + display(s_list,c_list,size); tb_present(); tb_poll_event(&ev); @@ -154,27 +117,19 @@ int main(int argc, char **argv) { int spot=-1; switch(input) { case 65512: /*MouseLeft*/ - if(ev.x<0 || ev.x>size*2-2 || ev.x <0 || ev.y>size-1 || ev.x%2 || turn!=shown_turn) break; + if(ev.x<0 || ev.x>size*2-2 || ev.x <0 || ev.y>size-1 || ev.x%2) break; spot=spot_is_taken(s_list,ev.x,ev.y); if(spot!=-1) { remove_stone_from_list(&s_list,spot); if(color==BLACK) { color=WHITE; } else { color=BLACK; } - struct game_state g=create_game_state(s_list,c_list,color); - history[turn]=g; - turn++; - shown_turn++; break; } s=create_stone(ev.x,ev.y,color); add_stone_to_list(&s_list,s); if(color==BLACK) { color=WHITE; } else { color=BLACK; } - struct game_state g=create_game_state(s_list,c_list,color); - history[turn]=g; - turn++; - shown_turn++; break; case 65511: /*MouseRight*/ - if(ev.x<0 || ev.x>size*2-2 || ev.x <0 || ev.y>size-1 || ev.x%2 || turn!=shown_turn) break; + if(ev.x<0 || ev.x>size*2-2 || ev.x <0 || ev.y>size-1 || ev.x%2) break; spot=spot_is_taken(s_list,ev.x,ev.y); if(spot!=-1) { s=create_stone(ev.x,ev.y,s_list.list[spot].color); @@ -188,12 +143,6 @@ int main(int argc, char **argv) { tb_shutdown(); return 0; break; - case 65515: /*arrow left*/ - shown_turn=max(1,shown_turn-1); - break; - case 65514: /*arrow right*/ - shown_turn=min(turn,shown_turn+1); - break; } } return 0;