Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8936609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:14:59+00:00 2026-06-15T10:14:59+00:00

So i am making the card game called War, the rules are the following:

  • 0

So i am making the card game called War, the rules are the following:

  1. Player 1 and player 2 each queues of cards called q1 and q2. Both
    queues are not empty. The players also have empty battle stacks s1
    and s2.
  2. Each player removes a card from the front of their queue and puts it
    on the top of their stack
  3. If the cards have equal face values, a war happens.
  4. Each player moves 3 additional cards from their queue to their stack
    and check the face value of their top cards again. This may happen
    several times. Go to 3 again.
  5. If the cards do not have equal values, the battle has ended and a
    can be determined.

the function i have to write is called start_battle.c and the logic i have came up with is the following, the queue_front, queue_empty and stack_top functions are already written. So my pseudocode is the following:

function start_battle(q1, q2, s1, s2, logfile)

warc=0
move front card of q1 to the top of s1
move front card of q2 to the top of s2
while (top cards of s1 and s2 have equal value
       and both q1 and q2 are not empty)           
  for i=1 to 3
    if q1 is not empty
      move front card of q1 to the top of s1
    endif
  done
  for i=1 to 3
    if q2 is not empty
      move front card of q2 to the top of s2
    endif
  done
done
return warc

My code is the following:

#include "libcardlist.h"
int start_battle(queue *q1, queue *q2, stack *s1, stack *s2, FILE *logfile){    
    int warc =0;
    int i;
    stack_push(s1, queue_front(q1));
    stack_push(s2, queue_front(q2));
    card c1 = stack_top(s1);
    card c2 = stack_top(s2);
    while (c1.face==c2.face&&  queue_empty(q1)==0 && queue_empty(q2)==0) {        
        warc++;        
        for (i=0; i<3; i++) {
            if(queue_empty(q1)==0){
                stack_push(s1, queue_front(q1));
            }
        }
        for (i=0; i<3; i++) {
            if (queue_empty(q2)==0){
              stack_push(s2, queue_front(q2));
            }    
        }       
   }
   return warc;
}

oh and

typedef struct {
  int face;         /* 2-14 */
  char suit;            /* C H S D */
} card;

When i test it, my code is stuck in the while loop, can someone help me fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:15:01+00:00Added an answer on June 15, 2026 at 10:15 am

    I added the queue_pop() where appropriate in your algorithm. Once you copy the card from a queue to a stack (via push) you need to remove it from your pile. In reality this should be part of the main-play of the game, not the intro (its the same, but you’ll figure that out eventually), and you’ll need to move both stacks of cards to the appropriate queue once a winner of a specific round is declared.

    Anyway, get your pops in there.

    int start_battle(queue *q1, queue *q2, stack *s1, stack *s2, FILE *logfile){    
        int warc =0;
        int i;
        stack_push(s1, queue_front(q1));
        queue_pop(q1); // no longer in this queue.
        stack_push(s2, queue_front(q2));
        queue_pop(q2); // no longer in this queue.
        card c1 = stack_top(s1);
        card c2 = stack_top(s2);
        while (c1.face==c2.face && queue_empty(q1)==0 && queue_empty(q2)==0) {        
            warc++;        
            for (i=0; i<3; i++) {
                if(queue_empty(q1)==0){
                    stack_push(s1, queue_front(q1));
                    queue_pop(q1);
                }
            }
            for (i=0; i<3; i++) {
                if (queue_empty(q2)==0){
                    stack_push(s2, queue_front(q2));
                    queue_pop(q2);
                }    
            }       
       }
    
       return warc;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a card game where the player can touch and drag around
Possible Duplicate: 3 player card game turn system I'm making a GUI 3 player
I am making a card game where the cards are represented as JLabels, having
I am making a card game and I have an activity for discarding cards
I'm making a card game and I need to previously create the cards and
I'm making an iPhone cards game where each use has a deck of cards,
I am making a card game in ruby. I have the Game class, which
Scenario : I am making a clone of a popular card game. There needs
I am making card game in C# WPF. For now I have singleplayer mode,
I am making a blackjack game in cocos2d-x here is the following code of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.