[C#]帮助 - 新的随机播放方法 [英] [C#] Help - New Shuffle Method
问题描述
Hello Code Project!
过去一周,我开始了一个新项目,需要创建一个包含许多不同纸牌游戏的库。在编写shuffle方法时,我借用了M $的二十一点样本项目。毋庸置疑,我不喜欢那个洗牌的方式。所以我开始创建一个新的shuffle方法。所以我拿起了一副纸牌,真的看着我是如何改组尝试使用代码重新创建的。我也会写我的伪代码。
现在我的问题以及我需要帮助的原因...
伪代码:
private void Shuffle()
{
RightHand.Add(HalfDeck);
LeftHand.Add(HalfDeck);
while (他们' re still cards in一手)
{
//使用抵消添加(分层)1-4张牌(每手牌)
//到新洗牌牌
NewDeck.Add(NumberOfCards) ;
}
}
当前代码:
public void Shuffle()
{
Random r = new Random();
列表<卡> tempDeck = new List< Card>();
列表<卡> bridgeHand = new List< Card>();
列表<卡> LeftHand = new List< Card>();
列表<卡> RightHand = new List< Card>();
int nMinOffset = 1 ,nMaxOffset = 9 跨度>;
int cardHand = 0 ;
for ( int h = 0 ; h < 7 ; h ++) // 随机播放7次
{
// 构建左手 - 拆分甲板
( int i = 0 ; i < 25 ; i ++)
{LeftHand.Add( this .Draw()); }
// Build Right Hand - Splits Deck
< span class =code-keyword> for ( int i = 0 ; i < span class =code-keyword>< 25 ; i ++)
{RightHand.Add(此跨度> .Draw()); }
// 创建桥梁
while ( true )
{
cardHand = r.Next(nMinOffset,nMaxOffset);
// 这就是我被困在......
// 需要检查以确保双手都有卡
// 如果一只手没有足够的卡来匹配随机偏移,那么添加剩余的卡
// 双手空时打破循环...
}
}
}
任何和所有帮助都非常适合。这个问题一直困扰着我的大脑几个小时。不确定我需要做什么。
尽我所能尝试自学/学习这门语言(我的第一个)。
的二十一点示例项目。毋庸置疑,我不喜欢那个洗牌的方式。所以我开始创建一个新的shuffle方法。所以我拿起了一副纸牌,真的看着我是如何改组尝试使用代码重新创建的。我也会写我的伪代码。
现在我的问题以及我需要帮助的原因...
伪代码:
private void Shuffle()
{
RightHand.Add(HalfDeck);
LeftHand.Add(HalfDeck);
while (他们' re still cards in一手)
{
//使用抵消添加(分层)1-4张牌(每手牌)
//到新洗牌牌
NewDeck.Add(NumberOfCards) ;
}
}
当前代码:
public void Shuffle()
{
Random r = new Random();
列表<卡> tempDeck = new List< Card>();
列表<卡> bridgeHand = new List< Card>();
列表<卡> LeftHand = new List< Card>();
列表<卡> RightHand = new List< Card>();
int nMinOffset = 1 ,nMaxOffset = 9 跨度>;
int cardHand = 0 ;
for ( int h = 0 ; h < 7 ; h ++) // 随机播放7次
{
// 构建左手 - 拆分甲板
( int i = 0 ; i < 25 ; i ++)
{LeftHand.Add( this .Draw()); }
// Build Right Hand - Splits Deck
< span class =code-keyword> for ( int i = 0 ; i < span class =code-keyword>< 25 ; i ++)
{RightHand.Add(此跨度> .Draw()); }
// 创建桥梁
while ( true )
{
cardHand = r.Next(nMinOffset,nMaxOffset);
// 这就是我被困在......
// 需要检查以确保双手都有卡
// 如果一只手没有足够的卡来匹配随机偏移,那么添加剩余的卡
// 双手空时打破循环...
}
}
}
任何和所有帮助都非常适合。这个问题一直困扰着我的大脑几个小时。不确定我需要做什么。
尽我所能尝试自学/学习这门语言(My First)。
< blockquote> //调整随机数以确保它在我们正在处理的手的范围内
if(cardhand> = leftHand.Count)
{
cardHand = leftHand.Count-1;
}
//移动下一个''cardHand ''左手牌到桥牌手牌>
//重复右手
Hello Code Project!
Well for the past week I started a new project which entails creating a library full of many different card games. Well while writing the shuffle method I had borrowed from M$''s blackjack sample project. Needless to say I didn''t like the way that one shuffled. So I set out to create a new shuffle method. So I picked up a deck of cards and really looked at how I shuffled to try and recreate that using code. I''ll write my pseudo code as well.
Now for my problem and the reason I need some help...
Pseudo Code:
private void Shuffle()
{
RightHand.Add(HalfDeck);
LeftHand.Add(HalfDeck);
while(They're still cards in a hand)
{
// using offsets add(layer) 1-4 cards(from each hand)
// to the new shuffled deck
NewDeck.Add(NumberOfCards);
}
}
Current Code:
public void Shuffle()
{
Random r = new Random();
List<Card> tempDeck = new List<Card>();
List<Card> bridgeHand = new List<Card>();
List<Card> LeftHand = new List<Card>();
List<Card> RightHand = new List<Card>();
int nMinOffset = 1, nMaxOffset = 9;
int cardHand = 0;
for (int h = 0; h < 7; h++) // Shuffle 7 times
{
// Build Left Hand - Splits Deck
for (int i = 0; i < 25; i++)
{ LeftHand.Add(this.Draw()); }
// Build Right Hand - Splits Deck
for (int i = 0; i < 25; i++)
{ RightHand.Add(this.Draw()); }
// Create Bridge
while (true)
{
cardHand = r.Next(nMinOffset, nMaxOffset);
// This is where I get stuck at...
// Need to do checks to make sure both hands have cards
// If a hand doesn't have enough cards to match the random offset then add remaining cards
// When both hands are empty break the loop...
}
}
}
Any and all help is greatly appriciated. This problem has been rattling my brain for a few hours now. Not sure what I need to do.
Doing my best to try and self teach/learn this language(My First).
''s blackjack sample project. Needless to say I didn''t like the way that one shuffled. So I set out to create a new shuffle method. So I picked up a deck of cards and really looked at how I shuffled to try and recreate that using code. I''ll write my pseudo code as well.
Now for my problem and the reason I need some help...
Pseudo Code:
private void Shuffle() { RightHand.Add(HalfDeck); LeftHand.Add(HalfDeck); while(They're still cards in a hand) { // using offsets add(layer) 1-4 cards(from each hand) // to the new shuffled deck NewDeck.Add(NumberOfCards); } }
Current Code:
public void Shuffle() { Random r = new Random(); List<Card> tempDeck = new List<Card>(); List<Card> bridgeHand = new List<Card>(); List<Card> LeftHand = new List<Card>(); List<Card> RightHand = new List<Card>(); int nMinOffset = 1, nMaxOffset = 9; int cardHand = 0; for (int h = 0; h < 7; h++) // Shuffle 7 times { // Build Left Hand - Splits Deck for (int i = 0; i < 25; i++) { LeftHand.Add(this.Draw()); } // Build Right Hand - Splits Deck for (int i = 0; i < 25; i++) { RightHand.Add(this.Draw()); } // Create Bridge while (true) { cardHand = r.Next(nMinOffset, nMaxOffset); // This is where I get stuck at... // Need to do checks to make sure both hands have cards // If a hand doesn't have enough cards to match the random offset then add remaining cards // When both hands are empty break the loop... } } }
Any and all help is greatly appriciated. This problem has been rattling my brain for a few hours now. Not sure what I need to do.
Doing my best to try and self teach/learn this language(My First).
// Adjust the random number to ensure it is within the bounds of the hand we''re dealing with
if (cardhand >= leftHand.Count)
{
cardHand = leftHand.Count-1;
}
// move the next ''cardHand'' cards from leftHand to bridgeHand
// repeat for right hand
这篇关于[C#]帮助 - 新的随机播放方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!