コード例 #1
0
ファイル: tests.c プロジェクト: joaofnfernandes/uva
void test_move_onto() {
	/* Set up */
	world_t* world = world_create(5);

	/* Test case 1 - A is top of stack */
	move_onto(world, 1, 2);
	assert(world->position_blocks_top[1] == NULL && 
			world->position_blocks_bottom[1] == NULL);
	assert(world->position_blocks_top[2]->value == 1 &&
			world->position_blocks_bottom[2]->value == 2);

	/* Test case 2 - A and B in middle of their stacks */
	move_onto(world, 3, 4);
	move_onto(world, 2, 4);
	assert(block_get_stack(block_get(world, 1)) == 1 &&
			block_get_stack(block_get(world, 3)) == 3);
	assert(block_get_stack(block_get(world, 2)) == 4 &&
			block_get_stack(block_get(world, 4)) == 4);

	assert(world->position_blocks_top[4]->value == 2 &&
			world->position_blocks_bottom[4]->value == 4);

	/* Test case 3 - A and B on same stack */
	move_onto(world, 3, 2);
	move_onto(world, 3, 4);
	assert(block_get_stack(block_get(world, 2)) == 4);

	/* Tear down */
	world_delete(&world);
}
コード例 #2
0
ファイル: solitaire_s.c プロジェクト: gchronis/groupitaire
int moveCardOntoAnother(card_t *card, card_t *onto) {
  cardstack_t *dest = onto->stack;
  if ((dest->type == LAIN) && isUp(card) && isOnTop(onto) && isOkOn(card,onto)) {
    move_onto(card,dest);
    return SUCCESS;
  } else {
    return FAILURE;
  }
}
コード例 #3
0
ファイル: solitaire_s.c プロジェクト: gchronis/groupitaire
int moveKingOntoFree(card_t *king, deal_t *deal) {
  cardstack_t *dest = findEmptyLainStack(deal);
  if (isUp(king) && dest != NULL) {
    move_onto(king,dest);
    return SUCCESS;
  } else {
    return FAILURE;
  }
}
コード例 #4
0
ファイル: main.c プロジェクト: benipet/algorithms
int main(void){
	pos* table = init_table();
	build_positions(table, 10);
	move_onto(table, 9,1);
	move_over(table, 8,1);
	move_over(table, 7,1);
	move_over(table, 6,1);
	pile_over(table, 8,6);
	pile_over(table, 8,5);
	move_over(table, 2,1);
	move_over(table, 4,9);
	display_all(table);
	return 0;
}
コード例 #5
0
ファイル: solitaire.c プロジェクト: gchronis/groupitaire
int moveCardOntoAnother(card_t *card, card_t *onto) {
  cardstack_t *dest = onto->stack;
  printf("onto LAIN %d %d\n", dest->type == LAIN, dest->type);
  printf("card LAIN %d %d\n", card->stack->type == LAIN, card->stack->type);
  printf("isUp %d\n",isUp(card));
  printf("isOnTop %d\n",isOnTop(onto));
  printf("isOkOn %d\n",isOkOn(card,onto));
  if ((dest->type == LAIN) && isUp(card) && isOnTop(onto) && isOkOn(card,onto)) {
    move_onto(card,dest);
    return SUCCESS;
  } else {
    return FAILURE;
  }
}
コード例 #6
0
ファイル: 101v2.c プロジェクト: minixalpha/Online-Judge
void run_cmd(Stack stacks[N], int locations[N], char cmd[M]) {
  char action[M], type[M];
  int a, b;

  sscanf (cmd, "%s %d %s %d\n", action, &a, type, &b);

  if (a == b || locations[a] == locations[b])
    return;

  if (!strcmp (action, "move") && !strcmp (type, "onto"))
    move_onto (stacks, locations, a, b);
  else if (!strcmp (action, "move") && !strcmp (type, "over"))
    move_over (stacks, locations, a, b);
  else if (!strcmp (action, "pile") && !strcmp (type, "onto"))
    pile_onto (stacks, locations, a, b);
  else if (!strcmp (action, "pile") && !strcmp (type, "over"))
    pile_over (stacks, locations, a, b); 
  else
    return;
}