Example #1
0
void test_board_is_won_column() {
  Board* board = new_board(3);
  assert(!is_won(board));
  make_move(board, 0, 'X');
  make_move(board, 3, 'X');
  make_move(board, 6, 'X');
  assert(is_won(board));
  destroy_board(board);
}
Example #2
0
void test_board_is_won_diag2() {
  Board* board = new_board(3);
  assert(!is_won(board));
  make_move(board, 2, 'X');
  make_move(board, 4, 'X');
  make_move(board, 6, 'X');
  assert(is_won(board));
  destroy_board(board);
}
Example #3
0
void test_board_is_won_row() {
  Board* board = new_board(3);
  assert(!is_won(board));
  make_move(board, 0, 'X');
  make_move(board, 1, 'X');
  make_move(board, 2, 'X');
  assert(is_won(board));
  destroy_board(board);
}
Example #4
0
void ConnectFour::update_game_state() {
	//check if the last move won the game
	if(is_won()) {
		if(human == current)
			printf("You win!\n");
		else
			printf("You lose.\n");
		state = GAMEOVER;
	}
	
	else if(is_lost()) {
		printf("No more possible moves\n");
		state = GAMEOVER;
	}
	
	else { //next turn
		current = Tile::opposite(current);
	}
}
bool run(struct grid *grid)
{
  char entree[50];
  char **tmp;
  char *ent;
  int i;

  print_game(grid);
  my_memreset(entree, 50);
  ent = readLine();
  if (my_strcmp(my_strcpy(entree, ent), "") != 0) {
    free(ent);
    tmp = my_str_to_wordtab(entree);
    if (choise(grid, tmp) == true)
      return (true);
    for (i = 0; tmp[i][0] != '\0'; i++)
        free(tmp[i]);
    free(tmp);
  }
  else
    my_putstr("Wrong command \n");
  return (is_won(grid));
}