找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 1742|回复: 5

[求助]Video Poker Simulation编程问题

[复制链接]
发表于 2009-11-6 01:38:22 | 显示全部楼层 |阅读模式 IP:江苏扬州
QUOTE:
Video Poker Simulation



Acme Software, Inc, has been contracted to write a Video Poker Simulation game in basic C++ that follows the following rules:



Basic Setting:

The player places an initial bet between one (1) and fifty (50) coins. The player is then dealt five (5) cards and allowed to choose which cards, if any, they wish to keep. The cards that they do not wish to keep are discarded, and replacement cards are dealt so that they again have a total of five (5) cards. The computer then determines what amount they have won, if any.



Card Ranks and Suits:

Cards are ranked, from highest to lowest:

· Ace

· King

· Queen

· Jack

· Ten

· Nine

· Eight

· Seven

· Six

· Five

· Four

· Three

· Two

· Ace

(Ace can count as either low or high. See "Royal Flush"'s scoring, below.)

The card suits are: Hearts, Clubs, Diamonds, and Spades



Hand Ranks:

When you are dealt replacement cards for your discards, your new hand is evaluated. Based on what kind of hand you're holding, you'll receive a certain number of points.

Hands are listed below, from best (highest scoring), to worst (no score):

· Royal Flush - 2000 points

A straight flush, with the Ace high.

In other words, a Ten, Jack, Queen, King and Ace, all of the same suit.

· Straight Flush - 250 points

A straight flush.

In other words, all five cards are consecutive and are the same suit.

For example: Three of Clubs, Four of Clubs, Five of Clubs, Six of Clubs and Seven of Clubs.

· Four of a Kind - 125 points

Four cards of the same value. (Obviously, each of different suits.)

· Full House - 40 points

A three of a kind and a pair at the same time.

· Flush - 25 points

All cards in your hand are the same suit.

· Straight - 20 points

All five cards are consecutive.

For example: Three of Clubs, Four of Spades, Five of Clubs, Six of Diamonds, and Seven of Hearts.

· Three of a Kind - 15 points

Three cards of the same value.

· Two Pair - 10 points

Two pairs of cards.

In other words, two cards in your hand are the same value, and two other cards in your hand are also the same value.

· Pair - 5 points

Two cards in your hand are the same value. In this version, they must be Jacks or better!

· None of the Above - 0 points

Each turn "costs" 5 dollars, so if you get a pair, no money actually end up added to your total score. If you don't get anything, you actually lose five dollars! If you bet more than one 5 dollar coin, then the returns above are multiplied by the number of coins entered to give the actual yield. This is just how handheld and Vegas video poker games actually work!



Project Requirements:

Your project must meet the following specifications:

1. Text-based display of what is in the player’s hand.
2. Read all cards to be discarded at once
3. Read from the command line as a program parameter the name of a file that contains the state of a previous game so that a player can resume a game at any point. Thus, your program must read and write to a file as well as verify that a file exists.
4. Provided adequate “help” for the player on how to play the game.
5. Score all hands correctly.
6. Know the player’s name and be “friendly”
发表于 2009-11-6 01:38:24 | 显示全部楼层 IP:江苏扬州
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <time.h>
#include <string>
#include <fstream>

using namespace std;

void loadDeck(string suits[4], string faceValue[13])
{
ifstream in;
in.open("cards.dat");
if(in.fail())
{
in.close();
cout<<"Deck of cards not found, program ending"<<endl;
exit(1);
}
for(int i=0; i<4; i++)
in>>suits[i];
for(int i=0; i<13; i++)
in>>faceValue[i];
in.close();
}

void shuffle( bool cards[52], int hand[5])
{
for(int i=0;i<52; i++)
cards[i] = false;
for(int i=0; i<5; i++)
hand[i] = -1;
}

void deal(bool card[], int hand[], int pos)
{
int dealt;
while(card[dealt=rand()%52]);
hand[pos] = dealt;
card[dealt] = true;
}


void initialDeal(bool card[], int hand[])
{
for(int i=0; i<5; i++)
deal(card, hand, i);
}

void discard(bool card[], int hand[])
{
char str[80];
cout<<"Which cards would you like to discard: ";
cin.getline(str, '\n',80);
char * pch;
pch = strtok (str," ,.-");
while (pch != NULL)
{
deal(card, hand, atoi(pch));
pch = strtok (NULL, " ,.-");
}
}

void display(int hand[], string suit[], string faceValue[])
{
cout<<"The cards in your hand are: "<<endl;
for(int i=0; i<5; i++)
cout<<i<<". "<<faceValue[hand[i]%13]<<" of "<<suit[hand[i]%4]<<endl;
// cout<<hand[i]<<endl;
cout<<endl;
}

int computepoints(hand,suits,faceValue,points)
{
for( int i = 0; i < 5; i++ )
{
for( int j = i+1; j < 5; j++ )
{
if( faceValue[ hand[i]%13 ] == faceValue[ hand[j]%13 ] )
{
if(faceValue[



bool again()
{
string ans;
cout<<"Do you want to do this again? ";
cin>>ans;
return (toupper(ans[0]) == 'Y');
}

int main(int argc, char *argv[])
{
string suits[4], faceValue[13];
bool cards[52];
int hand[5],points;
srand(time(NULL));
loadDeck(suits, faceValue);
do
{
shuffle(cards, hand);
initialDeal(cards, hand);
display(hand, suits, faceValue);
discard(cards, hand);
display(hand, suits, faceValue);
computepoints(hand,suits,faceValue,points);
}while(again());
system("PAUSE");
return EXIT_SUCCESS;
}




这是我的部分代码,我想请问如何编算分数的环节,如:如何表示5张连续的牌,2或3张值一样的牌,等等。。。
可不可以编一些例子给我或者讲的详细些,谢了!!!!
回复

使用道具 举报

发表于 2009-11-6 01:38:25 | 显示全部楼层 IP:江苏扬州
我给大家大致翻译一下,就是编一个纸牌游戏,每轮下注1个5分硬币或更多个,那五张牌,可以任意换牌一次(就是五张PASS),然后看手牌评分。如:
五张是10,J,Q,K,A就是2000分;五张连续(同花色)250分;四张牌面值一样,就是125分;3张一样还有一个对子是40分;全牌同花色25分;五张连续(不同花色)20分;3张一样15分;一个对子,5分。
如果你下注超过1个5分硬币,就把奖励分数乘以硬币数。要求纪录玩家的每轮分数。
大家一定要帮忙啊!我好怕阿,超级新手,都说美国的简单,可谁知这老师的题这么难啊!
回复

使用道具 举报

发表于 2009-11-6 01:38:26 | 显示全部楼层 IP:江苏扬州
召唤斑竹‘s help!!!!!!!
回复

使用道具 举报

发表于 2009-11-6 01:38:28 | 显示全部楼层 IP:江苏扬州
没空啊,课多,有空帮你看看!
回复

使用道具 举报

发表于 2009-11-6 01:38:29 | 显示全部楼层 IP:江苏扬州
呜呜呜,斑竹不帮小弟的话,偶~~~~~偶就出家当和尚去,天天念经烦死你!!!!哈哈哈哈~~~~~~~~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-10-1 17:23 , Processed in 0.188575 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表