コード例 #1
0
ファイル: game_test.c プロジェクト: HalosGhost/tty-solitaire
void test_move_card_should_not_change_stack_empty_stack_coordinates() {
  struct stack *origin, *destination;
  struct card *card[2];

  card_malloc(&card[0]);
  card_malloc(&card[1]);
  card_init(card[0]);
  card_init(card[1]);
  card_set(card[0], ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_0_BEGIN_X);
  card_set(card[1], KING, HEARTS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_1_BEGIN_X);

  stack_malloc(&origin);
  stack_malloc(&destination);
  stack_init(origin);
  stack_init(destination);
  stack_push(&origin, card[0]);
  stack_push(&destination, card[1]);
  move_card(&origin, &destination);

  assert(origin->card->frame->begin_y == MANEUVRE_BEGIN_Y);
  assert(origin->card->frame->begin_x == MANEUVRE_0_BEGIN_X);

  stack_free(origin);
  stack_free(destination);
}
コード例 #2
0
ファイル: game_test.c プロジェクト: HalosGhost/tty-solitaire
void test_move_card_from_non_stack_empty_stack_to_non_stack_empty_stack() {
  struct stack *origin, *destination;
  struct card *card[6];

  for (int i = 0; i < 6; i++) {
    card_malloc(&card[i]);
    card_init(card[i]);
    card_set(card[i], TWO + i, i % 5, i % 2, 99, 99);
  }

  stack_malloc(&origin);
  stack_malloc(&destination);
  stack_init(origin);
  stack_init(destination);
  for (int i = 0; i < 3; i++) {
    stack_push(&origin, card[i]);
  }
  for (int i = 3; i < 6; i++) {
    stack_push(&destination, card[i]);
  }
  move_card(&origin, &destination);

  assert(stack_length(origin) == 2);
  assert(stack_length(destination) == 4);
  assert(cards_equal(destination->card, card[2]));
  assert(cards_equal(destination->next->card, card[5]));

  stack_free(origin);
  stack_free(destination);
}
コード例 #3
0
ファイル: game_test.c プロジェクト: HalosGhost/tty-solitaire
void test_move_card_from_stack_empty_stack_to_non_stack_empty_stack() {
  struct stack *origin, *destination,
               *new_origin, *new_destination,
               *origin_duplicate, *destination_duplicate;
  struct card *card;

  card_malloc(&card);
  card_init(card);
  card_set(card, ACE, SPADES, EXPOSED, 0, 0);

  stack_malloc(&origin);
  stack_malloc(&destination);
  stack_init(origin);
  stack_init(destination);
  new_origin = origin;
  new_destination = destination;
  stack_push(&new_destination, card);
  origin_duplicate = stack_dup(origin);
  destination_duplicate = stack_dup(destination);
  move_card(&new_origin, &new_destination);

  assert(origin == new_origin);
  assert(stacks_equal(origin, origin_duplicate));
  assert(destination == new_destination);
  assert(stacks_equal(destination, destination_duplicate));

  stack_free(origin);
  stack_free(destination);
}
コード例 #4
0
ファイル: ai_client.c プロジェクト: rpcraig/rftg
/*
 * Handle a status update about a card.
 */
static void handle_status_card(char *ptr)
{
    card *c_ptr;
    int x;
    int owner, where, start_owner, start_where;

    /* Read card index */
    x = get_integer(&ptr);

    /* Get card pointer */
    c_ptr = &real_game.deck[x];

    /* Read card owner */
    owner = get_integer(&ptr);
    start_owner = get_integer(&ptr);

    /* Read card location */
    where = get_integer(&ptr);
    start_where = get_integer(&ptr);

    /* Move card to current location */
    move_card(&real_game, x, owner, where);

    /* Move "start of phase" location */
    move_start(&real_game, x, start_owner, start_where);

    /* Read unpaid good flag */
    c_ptr->unpaid = get_integer(&ptr);

    /* Read order played */
    c_ptr->order = get_integer(&ptr);

    /* Read covered by good flag */
    c_ptr->covered = get_integer(&ptr);

    /* Set known flags for active cards */
    if (c_ptr->where == WHERE_ACTIVE)
    {
        /* Card's location is known to everyone */
        c_ptr->known = ~0;
    }

    /* Set known flags for our cards in hand */
    if (c_ptr->where == WHERE_HAND && c_ptr->owner == player_us)
    {
        /* Set known flag */
        c_ptr->known = (1 << c_ptr->owner);
    }
}
コード例 #5
0
ファイル: game_test.c プロジェクト: HalosGhost/tty-solitaire
void test_move_card_from_stack_empty_stack_to_stack_empty_stack() {
  struct stack *origin, *destination,
               *new_origin, *new_destination,
               *origin_duplicate, *destination_duplicate;

  stack_malloc(&origin);
  stack_malloc(&destination);
  stack_init(origin);
  stack_init(destination);
  new_origin = origin;
  new_destination = destination;
  origin_duplicate = stack_dup(origin);
  destination_duplicate = stack_dup(destination);
  move_card(&new_origin, &new_destination);

  assert(origin == new_origin);
  assert(stacks_equal(origin, origin_duplicate));
  assert(destination == new_destination);
  assert(stacks_equal(destination, destination_duplicate));

  stack_free(origin);
  stack_free(destination);
}
コード例 #6
0
ファイル: init.c プロジェクト: MichaelSitter/keldon-rftg-ai
/*
 * Initialize a campaign status.
 */
static void init_campaign(game *g)
{
	int i, j, k;

	/* Check for pre-existing campaign status */
	if (!g->camp_status)
	{
		/* Make a status structure */
		g->camp_status = (campaign_status *)
		                               malloc(sizeof(campaign_status));
	}

	/* Clear campaign status */
	memset(g->camp_status, 0, sizeof(campaign_status));

	/* Loop over players */
	for (i = 0; i < MAX_PLAYER; i++)
	{
		/* Loop over set aside cards for this player */
		for (j = 0; j < g->camp->size[i]; j++)
		{
			/* Loop over cards in deck */
			for (k = 0; k < g->deck_size; k++)
			{
				/* Skip cards not in deck */
				if (g->deck[k].where != WHERE_DECK) continue;

				/* Skip cards that do not match */
				if (g->deck[k].d_ptr != g->camp->order[i][j])
					continue;

				/* Move card to campaign location */
				move_card(g, k, i, WHERE_CAMPAIGN);

				/* Save index */
				g->camp_status->index[i][j] = k;

				/* Done looking */
				break;
			}

			/* Check for random card */
			if (!g->camp->order[i][j])
			{
				/* Add random card */
				g->camp_status->index[i][j] = -1;
				continue;
			}

			/* Check for failure to find card */
			if (k == g->deck_size)
			{
				/* Error */
				fprintf(stderr, "Could not find enough %s.\n",
				        g->camp->order[i][j]->name);
				exit(1);
			}
		}

		/* Set size */
		g->camp_status->size[i] = g->camp->size[i];
	}
}
コード例 #7
0
ファイル: System.cpp プロジェクト: aidint/EmailService
string solve(string command,user*& cur_user)
{
  vector <string> commands;
  string x;

  string sol;
  commands=parse(command);
  x=commands[0];
  if(x=="exit" || x=="disconnect")
    return x;
  if(x=="signup")
    sol=signup(cur_user,commands);
  if(x=="signin")
    sol=signin(cur_user,commands);
  if(x=="signout" && commands.size()==1)
    {
      cur_user=NULL;
      return "signing out completed.\n";
    }
  if(x=="show_boards")
    sol=show_boards(cur_user);
  if(x=="enter_board")
    sol=enter_board(cur_user,commands);
  if(x=="add_user")
    sol=add_user(cur_user,commands);
  if(x=="remove_user_from_board")
    sol=remove_user_from_board(cur_user,commands);
  if(x=="show_lists" && commands.size()==1)
    sol=show_lists(cur_user);
  if(x=="show_cards")
    sol=show_cards(cur_user,commands);
  if(x=="show_card")
    sol=show_card(cur_user,commands);
  if(x=="create_board")
    sol=create_board(cur_user,commands);
  if(x=="remove_board")
    sol=remove_board(cur_user,commands);
  if(x=="add_list")
    sol=add_list(cur_user,commands);
  if(x=="remove_list")
    sol=remove_list(cur_user,commands);
  if(x=="add_card")
    sol=add_card(cur_user,commands);
  if(x=="remove_card")
    sol=remove_card(cur_user,commands);
  if(x=="move_card")
    sol=move_card(cur_user,commands);
  if(x=="rename_card")
    sol=rename_card(cur_user,commands);
  if(x=="edit_card_description")
    sol=edit_card_des(cur_user,commands);
  if(x=="edit_card_due_date")
    sol=edit_card_date(cur_user,commands);
  if(x=="assign_user")
    sol=assign(cur_user,commands);
  if(x=="remove_user")
    sol=remove_user_from_card(cur_user,commands);
  if(x=="comment")
    sol=commenting(cur_user,commands);
  if(x=="filter")
    sol=filter(cur_user,commands);
  if(sol.size()==0)
    sol="Invalid command.\n";
  return sol;
     
}