C++ :: Cards Game - Seeding A Vector With 52 Unique Values
Dec 29, 2013
I am trying to seed a vector with 52 values ranging from 1 to 52. I already have the code written to seed the vector bu how to keep from repeating the same values from being seeded. This is for a five card stud game.
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
#include<ctime>
using namespace std;
[Code] ....
View 3 Replies
Mar 2, 2014
I am trying to write a sub-program that takes a deck of 52 cards and will shuffle it up using this algorithm:
Start with n=51
Repeatedly:
Generate a random integer between 0 and n. Call it i.
Swap card i and card n in the deck.
Decrease n by 1
However the code that I've written,
vector<int> shuffleDeck(vector<int> deckVector)//deckVector is the original deck in order
{
int temp, n, i, s;
n = 51;
[Code].....
when I output the new vector, only produces this output(note- it is a random number every time, but it just repeats over and over):
8 8 8 8 8 8 8 8 0 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8 8 8 8 8
or:
22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 0 22 22 22 22
22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22
View 1 Replies
View Related
Oct 14, 2014
I'm looking for a way to generate a program-wide unique value to use as a template parameter. Generating a unique value within a translation unit is pretty easy with __LINE__, but that doesn't ensure uniqueness across translation units. I thought maybe I could use __FILE__, but that can't be used as a template parameter.
I stumbled across this page: [uRL] ....
which is exactly what I want, except that the anonymous namespace trick doesn't work on all the compilers I've tried it on. (This may be due to C++11 changing anonymous namespaces to internal linkage rather than external as they did before....that page is five years old.)
View 8 Replies
View Related
Mar 25, 2013
I need to assign unique integer values to words in a dictionary that have the same alphabets, for example 'act' and 'cat' should have the same integer value. Would just adding the ascii values of the letters be sufficient?
View 1 Replies
View Related
Aug 19, 2012
I am grabbing data from three entities and want to grab a field value in each of the entites and place it in an arraylist. What I would like to do is loop through the arraylist for all the values and do something for each value only once. If the value in the array list is repeated, I want to not do anything for it and continue till the end. Basically, I loop through all the values do something for each value and skip over the repeated value if I already did something.
View 1 Replies
View Related
Mar 24, 2013
I'm trying to write a recursive function that takes in a vector of strings that contains
"1 forward", "2 forward", "rotate left", "2 backwards" ... etc
how can I write recursive function that creates a vector of every unique combination of commands?
View 8 Replies
View Related
Nov 24, 2014
I got this program to create an array of playing cards and assign the values and suits and shuffle the array. I'm at the point where I need to output the cards but I need to burn the first card by making it output "**" instead of the card. my cards[] is a constant so I can's assign the first card as such.
void showCards(const int cards[], int numCards, bool hideFirstCard) {
if (cards[0]) {
hideFirstCard=true;
cards[0] = '**';
} for(int a = 0; a <= numCards; a++) {
cout >> showCard(cards[a]);
} }
View 1 Replies
View Related
Dec 4, 2013
This is my code: [tag]
Code:
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
[Code] .....
View 4 Replies
View Related
Apr 19, 2013
Here is the code I have written so far. My problem is that when the second user enters its position the last user's position is wiped of the board. I want to know how I can hold that position and keep doing so until the game is finished. I thought that calling the previous function would do that (and you can see where I have put that into a comment) but it doesn't.
Code:
#include <iostream> //includes header file
using namespace std;
//function prototypes
void printLeftUpper(int i, int j);
void printMiddleUpper(int i, int j);
[Code] ....
View 1 Replies
View Related
Apr 24, 2014
When things at work get overwhelming, it's not unusual for me to briefly "escape" by writing small programs simply for fun. A few days ago, I had an idea for a "binary game". I completed the first draft of it yesterday.
The idea is simple. The game uses 8-bit values. At the start of the game, a random "target" value is generated. The player is dealt a "hand" of seven values. The object is to use the values in your hand, along with some basic logical operations, to create the "target" value. While the idea is simple, the game itself can be quite difficult.
Here is an example of the output:
Code: --------------------
T: 1111 1100 (0xFC)
--------------------
0: 0000 0000 (0x00)
--------------------
1: 1100 1110 (0xCE)
2: 1010 0011 (0xA3)
3: 1100 0101 (0xC5)
4: 1011 1111 (0xBF)
5: 1010 1011 (0xAB)
6: 0001 1011 (0x1B)
7: 0001 1011 (0x1B)
--------------------
: Looking at the first column:
- 'T' is the "target" value
- '0' can be thought of as the "game board" - this is the value that needs to match the target value for a win
- '1' - '7' are the values in your "hand"
You can apply logic AND ('A'), OR ('O'), or XOR ('X') to a value in your hand with the value on the "game board". You are also allowed to apply logic to two values in your hand to create a new value for your hand. When a value from your hand is used, it is removed.
Some examples of the commands:
A30 --- apply logic AND to value #3 in your hand, and the "game board" value
O23 --- apply logic OR to value #2 in your hand and value #3 in your hand
X70 --- apply logic XOR to value #7 in your hand, and the "game board" value
You can also be dealt new values (as long as there's room in your hand) with the '+' command. 'H' or 'h' prints the help, and 'Q' or 'q' exits the game.
I haven't thoroughly tested it yet, since I just finished it a yesterday, but so far it looks good. The program itself uses only standard C.
I was dickering with the idea of supporting more logical operators (NOT, NAND, NOR, XNOR, shift), but I like the simplicity and resulting difficulty of the current implementation.
During initial testing, I realized it's possible to have doubles in your hand. Also, it's quite possible to be dealt the target value directly, which means that you could potentially win with one move, chance permitting. At first I thought about defending against these conditions, but came to the conclusion that it is fine as is - chances of an instant win are small, and if it does occur, would still be an enjoyable experience. Besides, if you're dealt the target value after the "game board" value has been modified.
Also, I did not allow a value of "zero" in the players hand. This was originally because I thought it would be of little use (though I've been reconsidering this). This also means that if two values in the hand are combined and result in zero, both values are removed and no new value is added. This was originally a bug, but I think I'll just reclassify it as a feature
So far, I found that the best strategy is to avoid modifying the "game board" value, and just play with the values in your hand. If you can get the target value in your hand, you just OR it with the "game board" and you're done.
View 2 Replies
View Related
Nov 7, 2013
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <conio.h>
using namespace std;
class Dice {
[Code] ....
Every time the roll_dice function get call twice for the same object, i receive the same dice values.
View 4 Replies
View Related
Nov 11, 2014
My assignment is writing Madd Libs game. I still do not understand how to store inputted strings or values to arrays. I need explanation of collecting inputted data to arrays.
#include "stdafx.h"
#include<stdio.h>
//#include<string.h>
int main(void) {
char string[37] = {'