Exemplo n.º 1
0
void test_pile_onto() {
	/* Set up */
	world_t* world = world_create(7);
	pile_onto(world, 1, 2);
	pile_onto(world, 3, 4);
	pile_onto(world, 2, 4);

	/* Test case 1 - Middle of stack A to middle of stack B */
	assert(block_get_stack(block_get(world, 3)) == 3);
	assert(block_get_stack(block_get(world, 1)) == 4 &&
		block_get_stack(block_get(world, 2)) == 4);
	assert(world->position_blocks_top[4]->value == 1 &&
			world->position_blocks_bottom[4]->value == 4);

	/* Test case 2 - stack A already on top of block B*/
	pile_onto(world, 1, 4);
	assert(block_get_stack(block_get(world, 2)) == 4);

	/* Tear down */
	world_delete(&world);
}
Exemplo n.º 2
0
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;
}