src/game.c

changeset 28
0c1371488d87
parent 27
efeb98bc69c9
child 30
a285ee393860
equal deleted inserted replaced
27:efeb98bc69c9 28:0c1371488d87
104 } 104 }
105 } 105 }
106 } 106 }
107 if (!logelem->next) { 107 if (!logelem->next) {
108 if (gamestate->checkmate) { 108 if (gamestate->checkmate) {
109 addch('#'); 109 addstr("\b#");
110 } else if (gamestate->stalemate) { 110 } else if (gamestate->stalemate) {
111 addstr(" stalemate"); 111 addstr(" stalemate");
112 } 112 }
113 } 113 }
114 addch(' '); 114 addch(' ');
341 memcpy(gamestate->board, initboard, sizeof(Board)); 341 memcpy(gamestate->board, initboard, sizeof(Board));
342 } 342 }
343 343
344 void game_start_singlemachine(Settings *settings) { 344 void game_start_singlemachine(Settings *settings) {
345 GameState gamestate; 345 GameState gamestate;
346 memset(&gamestate, 0, sizeof(GameState));
346 init_board(&gamestate); 347 init_board(&gamestate);
347 gamestate.mycolor = WHITE; 348 gamestate.mycolor = WHITE;
348 gamestate.movelist = gamestate.lastmove = NULL;
349 // TODO: time limit 349 // TODO: time limit
350 _Bool running; 350 _Bool running;
351 do { 351 do {
352 clear(); 352 clear();
353 draw_board(&gamestate); 353 draw_board(&gamestate);
354 running = !domove_singlemachine(&gamestate); 354 running = !domove_singlemachine(&gamestate);
355 gamestate.mycolor = opponent_color(gamestate.mycolor); 355 gamestate.mycolor = opponent_color(gamestate.mycolor);
356 } while (running); 356 } while (running);
357 move(0,0);
358 draw_board(&gamestate);
357 359
358 gamestate_cleanup(&gamestate); 360 gamestate_cleanup(&gamestate);
359 361
360 mvaddstr(getmaxy(stdscr)-1, 0, 362 mvaddstr(getmaxy(stdscr)-1, 0,
361 "Game has ended. Press any key to leave..."); 363 "Game has ended. Press any key to leave...");
367 _Bool myturn = is_server(settings) == 369 _Bool myturn = is_server(settings) ==
368 (settings->gameinfo.servercolor == WHITE); 370 (settings->gameinfo.servercolor == WHITE);
369 371
370 // TODO: time limit 372 // TODO: time limit
371 GameState gamestate; 373 GameState gamestate;
374 memset(&gamestate, 0, sizeof(GameState));
372 init_board(&gamestate); 375 init_board(&gamestate);
373 gamestate.mycolor = myturn ? WHITE:BLACK; 376 gamestate.mycolor = myturn ? WHITE:BLACK;
374 gamestate.movelist = gamestate.lastmove = NULL;
375 377
376 _Bool running; 378 _Bool running;
377 do { 379 do {
378 clear(); 380 clear();
379 draw_board(&gamestate); 381 draw_board(&gamestate);
384 flushinp(); // flush any input the user hacked in while waiting 386 flushinp(); // flush any input the user hacked in while waiting
385 } 387 }
386 myturn ^= TRUE; 388 myturn ^= TRUE;
387 } while (running); 389 } while (running);
388 390
391 move(0,0);
392 draw_board(&gamestate);
393
389 gamestate_cleanup(&gamestate); 394 gamestate_cleanup(&gamestate);
390 395
391 mvaddstr(getmaxy(stdscr)-1, 0, 396 mvaddstr(getmaxy(stdscr)-1, 0,
392 "Game has ended. Press any key to leave..."); 397 "Game has ended. Press any key to leave...");
393 refresh(); 398 refresh();

mercurial