Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 War card game help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rayman0055




PostPosted: Sat Apr 19, 2014 12:15 am   Post subject: War card game help

What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>


What is the problem you are having?
Im making a war card game and ive figured out how to add a card to the bottom of the winners deck but not how to remove the card from the top of the losers deck or put the winners top card to the bottom of their deck and move all of the other cards up
and i realize that its just random numbers from 1-52 right now i will fix the card values after this problem is dealt with
and THANKS FOR ANY HELP!!


Describe what you have tried to solve this problem
<Answer Here>


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


var deckSize : int := 52
var deck : array 1 .. deckSize of int %array to store int values randomized
var player1Deck : flexible array 1 .. 26 of int
var player2Deck : flexible array 1 .. 26 of int
var warDeck : flexible array 0 .. 0 of int
var temp, num : int %gives a value in order from 1 to deckSize to the deck
var counter : int := 27
var count : int := 0

%shuffles the cards and deals evenly to each player
proc shuffle
    for i : 1 .. deckSize
        deck (i) := i
    end for

    %shuffle cards
    for decreasing i : deckSize .. 1
        randint (num, 1, i)
        temp := deck (num)
        deck (num) := deck (i)
        deck (i) := temp
    end for

    %deal player 1
    for i : 1 .. 10
        player1Deck (i) := deck (i)
    end for

    %deal player 2
    for i : 1 .. 10
        player2Deck (i) := deck (counter)
        counter += 1
    end for
end shuffle

%Game
proc game
    shuffle
   loop
        put "Player 1: ", player1Deck (1)
        put "Player 2: ", player2Deck (1)
        put skip

        if player1Deck (1) > player2Deck (1) then
            new player1Deck, upper (player1Deck) + 1
            player1Deck (upper (player1Deck)) := player1Deck (1)
            player1Deck (upper (player1Deck) - 1) := player2Deck (1)
            player2Deck (upper (player2Deck)) := player2Deck (1)
            new player2Deck, upper (player2Deck) - 1
        elsif player2Deck (1) > player1Deck (1) then
            new player2Deck, upper (player2Deck) + 1
            player2Deck (upper (player2Deck)) := player2Deck (1)
            player2Deck (upper (player2Deck) - 1) := player1Deck (1)
            player1Deck (upper (player1Deck)) := player1Deck (1)
            new player1Deck, upper (player1Deck) - 1
        else
            for y : 1 .. 1000000 %Will change when i learn how to fix it
                new warDeck, upper (warDeck) + 2
                warDeck (upper (warDeck)) := player1Deck (1)
                warDeck (upper (warDeck) - 1) := player2Deck (1)
                if player1Deck (1) > player2Deck (1) then
                    new player1Deck, upper (player1Deck) + count
                    player1Deck (upper (player1Deck)) := player1Deck (1)
                    player1Deck (upper (player2Deck) - 1) := player2Deck (1)
                    player2Deck (upper (player2Deck)) := player2Deck (1)
                    player1Deck (upper (player1Deck) - count) := warDeck (upper (warDeck) - count)
                    for x : (count - 1) .. 1
                        player1Deck (upper (player1Deck) - x) := warDeck (upper (warDeck) - x)
                    end for
                    new player2Deck, upper (player2Deck) - 1
                    exit
                elsif player2Deck (1) > player1Deck (1) then
                    new player2Deck, upper (player2Deck) + 1
                    player2Deck (upper (player2Deck)) := player2Deck (1)
                    player2Deck (upper (player1Deck) - 1) := player1Deck (1)
                    player1Deck (upper (player1Deck)) := player1Deck (1)
                    for x : (count - 1) .. 1
                        player2Deck (upper (player2Deck) - x) := warDeck (upper (warDeck) - x)
                    end for
                    new player1Deck, upper (player1Deck) - 1
                    exit
                end if
                count += 2
            end for
            count := 0
        end if

        exit when upper (player1Deck) = 0 or upper (player2Deck) = 0
        Input.Pause
    end loop

    if upper (player2Deck) = 0 then
        put "PLAYER 1 WINS!"
    elsif upper (player1Deck) = 0 then
        put "PLAYER 2 WINS!"
    end if

end game

game




Please specify what version of Turing you are using
<Answer Here>
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Sat Apr 19, 2014 11:28 pm   Post subject: Re: War card game help

rayman0055 wrote:
how to remove the card from the top of the losers deck or put the winners top card to the bottom of their deck and move all of the other cards up


Well, when the top card is removed from the deck, the second card becomes the first card, the third card becomes the second and so on. If the first card is put on the bottom it becomes the new 26th card (assuming your deck has 26 cards).
To do this you just need to shift all the values up one index in your array (then either change your array size or put a card in the last position).
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: