拖拉机牌的算法(C++实现)来者有分!

tomcat_jb 2002-04-30 10:26:52
请各位谈谈拖拉机升级的算法实现?讲讲思路也有分。
...全文
307 35 打赏 收藏 转发到动态 举报
写回复
用AI写文章
35 条回复
切换为时间正序
请发表友善的回复…
发表回复
heiseloveyou 2002-06-26
  • 打赏
  • 举报
回复
up!
思考中…………
lyneville 2002-06-26
  • 打赏
  • 举报
回复
呵呵,我也考虑这些问题
tomcat_jb 2002-06-26
  • 打赏
  • 举报
回复
就是两副牌的升级.
wtzyb4446 2002-06-25
  • 打赏
  • 举报
回复
不知你们讨论几副牌的升级,如果是一两副牌还简单,三副牌以上就麻烦了
tomcat_jb 2002-06-25
  • 打赏
  • 举报
回复
我说的不是人工智能,而是建立客户端和服务器端的数据通信,如何来进行数据结构定义。
penu 2002-06-24
  • 打赏
  • 举报
回复
按照人出牌的思路建立规则!其它都是旁支末节!
tomcat_jb 2002-06-24
  • 打赏
  • 举报
回复
继续关注。。。
flyinfree 2002-05-14
  • 打赏
  • 举报
回复
如何跟当前牌局的形势做出决策这个太难了,该怎么实现?
不用回答,俺学得太少,讲了也不一定能明白:)
popular21cn 2002-05-14
  • 打赏
  • 举报
回复
老千!向各位学习!
WUKAI001 2002-05-13
  • 打赏
  • 举报
回复
谢谢大家,受益匪浅!
tomcat_jb 2002-05-13
  • 打赏
  • 举报
回复
to sdp(闲着的眼)
谢谢,我研究研究。这是那里DOWN的?能告诉我地址吗?
l_xiaofeng 2002-05-11
  • 打赏
  • 举报
回复
up
jluhs 2002-05-11
  • 打赏
  • 举报
回复
老兄,看来我是帮不上什么忙了,抱歉!
tomcat_jb 2002-05-10
  • 打赏
  • 举报
回复
gz
Kaye 2002-05-10
  • 打赏
  • 举报
回复
g & z
挺拔的劲松 2002-05-10
  • 打赏
  • 举报
回复
这是以上纸牌游戏的规则:
Two players, playing poker game, five cards in each hand, comparing the five cards, decide who is going to win.

1. If nothing, highest card win. If tie, compare second card, highest win, If tie again, compare the third card, and so on, if five cards all tie, then it's a tie.

2. If there's a pair, pair wins, if both have pair, higher pair win, if pairs are the same, compare the third card, higher one win, if tie, compare the fourth card, higher one win. if tie again, compare the fifth card. if tie, then it's a tie.

3. If there's two pairs in one hand, two pairs wins. If both have two pairs, higher one pair wins. If the first pair is the same, then compare the second pair, higher one wins, if the same, then compare the fifth card, higher one wins, if still the same, then it's a tie.

4. If there's Three of a kind ( Three Queen, for example ), three of a kind wins. If both have three of a kind, higher one wins.

5. If there's straight ( eg. cards in consecutive number, like 2,3,4,5,6, doesn't mater if they are the same suit), staight wins. If both have staight, higher one wins, if the first high card ties, then compare the second one, and so on, just like in number 1.

6. If there's flush ( all same suit, eg. five cards are all hearts, doesn't have to be the consecutive number ), flush wins. If both have flush, higher card wins, and so on just like in number 1.

7. If there's full house ( three of a kind, one pair ), full house wins, if both have full house, higher one wins.

8. If there's four of a kind ( eg. 4,4,4,4, 7 ), four of a kind wins, if both have four of a kind, higher one wins.

9. If there's straight flush ( same suit, consecutive number, eg. 2,3,4,5,6, and they are all hearts ), straight flush wins. If both have straight flush, higher one wins. ( eg. 10, Jack, Queen, King, Ace , this flush is always the highest ). If same, tie.

From 1 to 9, it's from low to high, so number 2 always wins over number 1, number 3 always win over number 1 and 2, number 4 always win over 3, 2, 1, and so on.

the cout statement should be able to show the two players playing like this:

player 1 player 2
__________ _________

card 1 card 1
card 2 card 2
card 3 card 3
card 4 card 4
card 5 card 5
(should show what card they are, like, seven of heart )
挺拔的劲松 2002-05-10
  • 打赏
  • 举报
回复
下面是一个纸牌游戏的代码,你可以作为参考!
#include <iostream>
using std::cout;

#include <iomanip>
using std::ios;

using std::setw;
using std::setiosflags;

#include <cstdlib>
#include <ctime>

struct CARD {
char *FACE;
char *SUIT;
}_CARD;

struct PLAYER {
char *NAME;
CARD cards[5];
}_PLAYER;


void shuffle( int [][13] );
void deal( const int [][13], const char *[], const char *[] );

void StringToInt( char *sFACE, unsigned int iFACE );
int JudgeFormFace(unsigned int iFACE[]);
int JudgeSuit( CARD cards[] );
int JudgeKind(PLAYER *player);
int CompareCard( PLAYER *player0, PLAYER *player1 );


PLAYER players[2];
unsigned int bFACE[5]; //经过排序后的5张牌的面值(FACE)顺序 因为题目没有要求花色的顺序,所以只有面值即可判定大小.

int main()
{
const char *suit[4] = {"Hearts", "Dismonds", "Clubs", "Spades"};
const char *face[13] = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
int deck[4][13] = {0};

int ret;

srand( time(0) );

shuffle( deck );
deal( deck, face, suit );

ret = CompareCard(&players[0], &players[1]);

if ( ret = 1 )
cout << "\n" << players[0].NAME << "Is Wins!\n";

if ( ret = -1 )
cout << "\n" << players[1].NAME << "Is Wins!\n";

if ( ret = 0 )
cout << "\n" << players[0].NAME << "And" << players[1].NAME <<"Are Tie!\n";

return 0;
}


//洗牌
void shuffle( int wDeck[][13] )
{
int row, column;
int card;

for( card =1; card <= 10; card++ ){

do {
row = rand() % 4;
column = rand() % 13;
} while ( wDeck[row][column] != 0);

wDeck[row][column] = card;
}
}

//发牌并显示
void deal(const int wDeck[][13],const char *wFace[],const char *wSuit[])
{

memset(players, 0, sizeof(PLAYER));

cout << setw(2) << setiosflags (ios::right)
<< players[0].NAME << "\t" << players[1].NAME << "\n";

cout << "---------------------------------" << "\n";

for (int card = 1; card <= 10; card++)

for (int row = 0; row < 4; row++)

for ( int column = 0; column <= 12; column++)

if( wDeck[row][column] == card )
{
if ( card % 2 == 0 ) {
memcpy ( players[1].cards[(card-2) / 2].FACE, wFace[column], sizeof(wFace[column]) );
memcpy ( players[1].cards[(card-2) / 2].SUIT, wSuit[row], sizeof(wSuit[row]) );

cout << setw(2) << setiosflags (ios::right)
<< players[1].cards[(card-2) / 2].FACE << " of "
<< setw(8) << setiosflags (ios::left)
<< players[1].cards[(card-2) / 2].SUIT
<< "\n";
}

else {
memcpy ( players[0].cards[(card-1) / 2].FACE, wFace[column], sizeof(wFace[column]) );
memcpy ( players[0].cards[(card-1) / 2].SUIT, wSuit[row], sizeof(wSuit[row]) );

cout << setw(2) << setiosflags (ios::right)
<< players[0].cards[(card-1) / 2].FACE << " of "
<< setw(8) << setiosflags (ios::left)
<< players[0].cards[(card-1) / 2].SUIT
<< "\t";
}

}

}

/* 函数功能: 比较牌的大小
1. PLAYER[0] 大于 PLAYER[1]
-1. PLAYER[0] 小于 PLAYER[1]
0. PLAYER[0] 等于 PLAYER[1]

*/
int CompareCard( PLAYER *player0, PLAYER *player1 )
{
unsigned int i, r;

i = JudgeKind(player0);
r = JudgeKind(player1);

if ( i > r ) return 1;
if ( i < r ) return -1;

//这里是 i=r 时, 即有相同类型时的判断 {未完成}


return 0;
}


/* 函数功能: 判断玩家手中的牌属于哪种类型
1. Nothing, Highest Card Win
2. Pair
3. Two Pair
4. Three Of Kind
5. Straight
6. Flush
7. Full House (Three Of Kind And Pair)
8. Four Of Kind
9. Straight Flush

返回 -1 表示错误!
*/

int JudgeKind(PLAYER *player)
{
CARD cards[5];
unsigned int iFACE[5], bFACE[5];

memset (cards, 0, sizeof(cards));
memset (iFACE, 0, sizeof(iFACE));
memset (bFACE, 0, sizeof(bFACE));

StringToInt( player->cards[0].FACE, iFACE[0] );
StringToInt( player->cards[1].FACE, iFACE[1] );
StringToInt( player->cards[2].FACE, iFACE[2] );
StringToInt( player->cards[3].FACE, iFACE[3] );
StringToInt( player->cards[4].FACE, iFACE[4] );

strcpy( cards[0].SUIT, player->cards[0].SUIT );
strcpy( cards[1].SUIT, player->cards[1].SUIT );
strcpy( cards[2].SUIT, player->cards[2].SUIT );
strcpy( cards[3].SUIT, player->cards[3].SUIT );
strcpy( cards[4].SUIT, player->cards[4].SUIT );

if(JudgeSuit(&cards[0]) && JudgeFormFace(&iFACE[0]) == 50 )
return 9;
if(JudgeSuit(&cards[0]) )
return 6;
if( JudgeFormFace(&iFACE[0]) == 80 )
return 8;
if( JudgeFormFace(&iFACE[0]) == 70 )
return 7;
if( JudgeFormFace(&iFACE[0]) == 50 )
return 5;
if( JudgeFormFace(&iFACE[0]) == 40 )
return 4;
if( JudgeFormFace(&iFACE[0]) == 30 )
return 3;
if( JudgeFormFace(&iFACE[0]) == 20 )
return 2;
if( JudgeFormFace(&iFACE[0]) == 10 )
return 1;

return -1;

}


// 函数功能: 转换FACE字符串为 1-13的 INT型整数,
void StringToInt( char *sFACE, unsigned int iFACE )
{
if( strcmp("A", sFACE) ) iFACE = 1;
if( strcmp("2", sFACE) ) iFACE = 2;
if( strcmp("3", sFACE) ) iFACE = 3;
if( strcmp("4", sFACE) ) iFACE = 4;
if( strcmp("5", sFACE) ) iFACE = 5;
if( strcmp("6", sFACE) ) iFACE = 6;
if( strcmp("7", sFACE) ) iFACE = 7;
if( strcmp("8", sFACE) ) iFACE = 8;
if( strcmp("9", sFACE) ) iFACE = 9;
if( strcmp("10", sFACE) ) iFACE = 10;
if( strcmp("J", sFACE) ) iFACE = 11;
if( strcmp("Q", sFACE) ) iFACE = 12;
if( strcmp("K", sFACE) ) iFACE = 13;
}

/* 函数功能: 判断5张牌Face的大小,是否两张同,三张同,四张同,是否顺等等,并排序

例: A, K, Q, J, 10; straight return 50
8, 8, 8, 8, K; Four kind return 80;
7, 7, 7, 6, 6; Full House return 70;
7, 7, 7, Q, 3; Three kind return 40;
4, 4, 2, 2, 9; two pair return 30;
J, J, 7, 6, 5; a pair return 20;
K, Q, 9, 5, 2; Nothing return 10;
*/

int JudgeFormFace(unsigned int iFACE[] )
{

//{未完成}
return -1;
}



/* 函数功能: 判断5张牌是否同花色
是同花: return 1;
不是同花: return -1;
*/
int JudgeSuit( CARD cards[] )
{
if( strcmp(cards[0].SUIT, cards[1].SUIT) &&
strcmp(cards[0].SUIT, cards[2].SUIT) &&
strcmp(cards[0].SUIT, cards[3].SUIT) &&
strcmp(cards[0].SUIT, cards[4].SUIT) )
return 1;
return -1;
}
better2best 2002-05-10
  • 打赏
  • 举报
回复
不需要做专家系统吧

不可想象 有那么复杂么
tomcat_jb 2002-05-09
  • 打赏
  • 举报
回复
作弊软件也需要了解其中的算法啊,不然就是直接在底层进行数据包分析,在把分析好的包发送出去,但是如果服务器端或者客户端的规则算法精确的话,可以屏蔽任何的伪造的数据包,而且可以维护游戏规则。

不知道是否是每次出牌的时候都进行规则判断,但是如何从最容易的规则来开始判断,这样可以提高出牌速度。
lbl20020123 2002-05-08
  • 打赏
  • 举报
回复
gz
加载更多回复(15)
1 课程目标 学会使用腾讯提供的云开发功能快速开发后台 数据接口,用于存储小程序中用到的数据 学会使用小程序中常见的一些API,比如:分享小程序,拨打手机电话,地图位置等 掌握快速上架一款小程序需要的步骤 前端相关的css以及html,vue等基础不作为本课程的重点,本课程将提供一个基于图鸟UI修改的企业产品展示前端代码,我们在此基础上使用云开发实现页面数据动态化。由于本人是后端开发,对于前端样式等不擅长,所以基本都是直接复制现成的样式做简单的修改,想要学习前端html,css,js,vue等基础知识的小伙伴可以不必考虑本课程,B站以及其他平台有大量的免费课程。 2 课程内容 本课程将实现一个完整功能的企业产品展示小程序,之前有人找我开发一个农用拖拉机企业展示的小程序,说是要用云开发来做,正好我之前没用过云开发,都是自己搭建后端API以及管理后台来开发,因此想着一边开发一边录一个云开发的课程,帮助一些同学快速入门云开发,将包括一下内容: 首页 主要产品推荐 顶部铲平轮播图展示 中间产品分类 轮播消息通知 产品价格咨询 用户留下联系方式 全部产品列表展示 产品详细信息展示 用户估价咨询表单,用户向企业出售产品,类似厂家回收 个人中心 注册登录 询价记录 拨打企业电话 查看企业地址 查看企业工作时间 3 使用技术 vue2 uniapp 图鸟UI javascript 腾讯云开发 4 需要的开发工具 图鸟原始模板:https://ext.dcloud.net.cn/plugin?id=14378 hbuilder开发工具: https://www.dcloud.io/hbuilderx.html 微信开发者工具:https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html

33,010

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧