Console client: Show cards and result at end of hand. All-in still not working.
This commit is contained in:
@@ -110,9 +110,19 @@ namespace pokerth_console
|
||||
Log.CardToString(cards[4]));
|
||||
}
|
||||
|
||||
public void PlayerWinsHideCards(string name, uint moneyWon)
|
||||
public void EndOfHandShowCards(string name, int[] cards, int cardsValue, bool allIn)
|
||||
{
|
||||
Console.WriteLine("\n{0} wins ${1}.", name, moneyWon);
|
||||
Console.WriteLine("{0} {1} [{2}, {3}] - {4}",
|
||||
name,
|
||||
allIn ? "has" : "shows",
|
||||
Log.CardToString(cards[0]),
|
||||
Log.CardToString(cards[1]),
|
||||
Log.CardsValueToString(cardsValue));
|
||||
}
|
||||
|
||||
public void PlayerWins(string name, uint moneyWon)
|
||||
{
|
||||
Console.WriteLine("{0} wins ${1}.", name, moneyWon);
|
||||
}
|
||||
|
||||
public void Error(string message)
|
||||
|
||||
@@ -37,7 +37,8 @@ namespace pokerth_lib
|
||||
void ShowFlopCards(int[] cards);
|
||||
void ShowTurnCards(int[] cards);
|
||||
void ShowRiverCards(int[] cards);
|
||||
void PlayerWinsHideCards(string name, uint moneyWon);
|
||||
void EndOfHandShowCards(string name, int[] cards, int cardsValue, bool allIn);
|
||||
void PlayerWins(string name, uint moneyWon);
|
||||
void Error(string message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,5 +159,150 @@ namespace pokerth_lib
|
||||
|
||||
return actionString;
|
||||
}
|
||||
|
||||
protected static string CardCodeToString(int cardCode, bool plural)
|
||||
{
|
||||
string cardString;
|
||||
|
||||
switch (cardCode)
|
||||
{
|
||||
case 12 :
|
||||
cardString = "Ace";
|
||||
break;
|
||||
case 11 :
|
||||
cardString = "King";
|
||||
break;
|
||||
case 10 :
|
||||
cardString = "Queen";
|
||||
break;
|
||||
case 9 :
|
||||
cardString = "Jack";
|
||||
break;
|
||||
case 8 :
|
||||
cardString = "Ten";
|
||||
break;
|
||||
case 7 :
|
||||
cardString = "Nine";
|
||||
break;
|
||||
case 6 :
|
||||
cardString = "Eight";
|
||||
break;
|
||||
case 5 :
|
||||
cardString = "Seven";
|
||||
break;
|
||||
case 4 :
|
||||
cardString = "Six";
|
||||
break;
|
||||
case 3 :
|
||||
cardString = "Five";
|
||||
break;
|
||||
case 2 :
|
||||
cardString = "Four";
|
||||
break;
|
||||
case 1 :
|
||||
cardString = "Three";
|
||||
break;
|
||||
case 0 :
|
||||
cardString = "Deuce";
|
||||
break;
|
||||
default :
|
||||
cardString = "Invalid Card";
|
||||
break;
|
||||
}
|
||||
if (plural)
|
||||
{
|
||||
if (cardCode == 4) // sixes
|
||||
cardString += "e";
|
||||
cardString += "s";
|
||||
}
|
||||
return cardString;
|
||||
}
|
||||
|
||||
public static string CardsValueToString(int cardsValue)
|
||||
{
|
||||
string cardString;
|
||||
|
||||
int firstPart = cardsValue / 100000000;
|
||||
int secondPart = cardsValue / 1000000 - firstPart * 100;
|
||||
int thirdPart = cardsValue / 10000 - firstPart * 10000
|
||||
- secondPart * 100;
|
||||
int fourthPart = cardsValue / 100 - firstPart * 1000000
|
||||
- secondPart * 10000 - thirdPart * 100;
|
||||
int fifthPart = cardsValue - firstPart * 100000000
|
||||
- secondPart * 1000000 - thirdPart * 10000 - fourthPart * 100;
|
||||
int fifthPartA = cardsValue / 10 - firstPart * 10000000
|
||||
- secondPart * 100000 - thirdPart * 1000 - fourthPart * 10;
|
||||
int fifthPartB = cardsValue - firstPart * 100000000
|
||||
- secondPart * 1000000 - thirdPart * 10000 - fourthPart*100
|
||||
- fifthPartA*10;
|
||||
|
||||
switch (firstPart)
|
||||
{
|
||||
// Royal Flush
|
||||
case 9 :
|
||||
cardString = "Royal Flush";
|
||||
break;
|
||||
// Straight Flush
|
||||
case 8 :
|
||||
cardString = "Straight Flush, ";
|
||||
if (secondPart >= 3)
|
||||
cardString += CardCodeToString(secondPart, false) + " high";
|
||||
else
|
||||
cardString += "Invalid high";
|
||||
break;
|
||||
// Four of a Kind
|
||||
case 7 :
|
||||
cardString = "Four of a Kind, " + CardCodeToString(secondPart, true);
|
||||
break;
|
||||
// Full House
|
||||
case 6 :
|
||||
cardString = "Full House, "
|
||||
+ CardCodeToString(secondPart, true)
|
||||
+ " full of "
|
||||
+ CardCodeToString(thirdPart, true);
|
||||
break;
|
||||
// Flush
|
||||
case 5 :
|
||||
cardString = "Flush, ";
|
||||
if (secondPart >= 4)
|
||||
cardString += CardCodeToString(secondPart, false) + " high";
|
||||
else
|
||||
cardString += "Invalid high";
|
||||
break;
|
||||
// Straight
|
||||
case 4 :
|
||||
cardString = "Straight, ";
|
||||
if (secondPart >= 3)
|
||||
cardString += CardCodeToString(secondPart, false) + " high";
|
||||
else
|
||||
cardString += "Invalid high";
|
||||
break;
|
||||
// Three of a Kind
|
||||
case 3 :
|
||||
cardString = "Three of a Kind, " + CardCodeToString(secondPart, true);
|
||||
break;
|
||||
// Two Pairs
|
||||
case 2 :
|
||||
cardString = "Two Pairs, "
|
||||
+ CardCodeToString(secondPart, true)
|
||||
+ " and "
|
||||
+ CardCodeToString(secondPart, true);
|
||||
break;
|
||||
// One Pair
|
||||
case 1 :
|
||||
cardString = "One Pair, "
|
||||
+ CardCodeToString(secondPart, true);
|
||||
break;
|
||||
// Highest Card
|
||||
case 0 :
|
||||
cardString = "High Card, "
|
||||
+ CardCodeToString(secondPart, false);
|
||||
break;
|
||||
default:
|
||||
cardString = "Invalid Card Value";
|
||||
break;
|
||||
}
|
||||
return cardString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,25 @@ namespace pokerth_lib
|
||||
}
|
||||
}
|
||||
|
||||
public int[] BestHandPos
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (m_mutex)
|
||||
{
|
||||
// Return a copy of the array.
|
||||
return (int[])m_bestHandPos.Clone();
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
lock (m_mutex)
|
||||
{
|
||||
m_bestHandPos = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Hand.Action CurAction
|
||||
{
|
||||
get
|
||||
@@ -104,6 +123,24 @@ namespace pokerth_lib
|
||||
}
|
||||
}
|
||||
|
||||
public int CardsValue
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (m_mutex)
|
||||
{
|
||||
return m_cardsValue;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
lock (m_mutex)
|
||||
{
|
||||
m_cardsValue = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void NewHand()
|
||||
{
|
||||
lock (m_mutex)
|
||||
@@ -116,8 +153,10 @@ namespace pokerth_lib
|
||||
|
||||
private Object m_mutex;
|
||||
private int[] m_cards;
|
||||
private int[] m_bestHandPos;
|
||||
private Hand.Action m_curAction;
|
||||
private uint m_money;
|
||||
private uint m_totalBet;
|
||||
private int m_cardsValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ namespace pokerth_lib
|
||||
void VisitDealFlopCards(NetPacket p);
|
||||
void VisitDealTurnCard(NetPacket p);
|
||||
void VisitDealRiverCard(NetPacket p);
|
||||
void VisitEndOfHandShowCards(NetPacket p);
|
||||
void VisitEndOfHandHideCards(NetPacket p);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,6 +137,12 @@ namespace pokerth_lib
|
||||
TurnCard,
|
||||
RiverCard,
|
||||
MoneyWon,
|
||||
BestHandPos1,
|
||||
BestHandPos2,
|
||||
BestHandPos3,
|
||||
BestHandPos4,
|
||||
BestHandPos5,
|
||||
CardsValue,
|
||||
}
|
||||
|
||||
public enum ListPropType
|
||||
@@ -195,6 +201,9 @@ namespace pokerth_lib
|
||||
case NetTypeDealRiverCard :
|
||||
tmpPacket = new NetPacketDealRiverCard(size, reader);
|
||||
break;
|
||||
case NetTypeEndOfHandShowCards :
|
||||
tmpPacket = new NetPacketEndOfHandShowCards(size, reader);
|
||||
break;
|
||||
case NetTypeEndOfHandHideCards :
|
||||
tmpPacket = new NetPacketEndOfHandHideCards(size, reader);
|
||||
break;
|
||||
|
||||
@@ -60,6 +60,18 @@ namespace pokerth_lib.src
|
||||
|
||||
WriteGameInfoBlock(w);
|
||||
|
||||
w.Write(tmpPassword);
|
||||
// Add padding.
|
||||
int passwordPadding = passwordWithPadding - tmpPassword.Length;
|
||||
if (passwordPadding > 0)
|
||||
w.Write(new byte[passwordPadding]);
|
||||
|
||||
w.Write(tmpName);
|
||||
// Add padding.
|
||||
int namePadding = nameWithPadding - tmpName.Length;
|
||||
if (namePadding > 0)
|
||||
w.Write(new byte[namePadding]);
|
||||
|
||||
return memStream.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,13 +52,32 @@ namespace pokerth_lib
|
||||
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
|
||||
tmpList.Add(PropType.SecondCard,
|
||||
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
|
||||
tmpList.Add(PropType.BestHandPos1,
|
||||
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
|
||||
tmpList.Add(PropType.BestHandPos2,
|
||||
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
|
||||
tmpList.Add(PropType.BestHandPos3,
|
||||
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
|
||||
tmpList.Add(PropType.BestHandPos4,
|
||||
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
|
||||
tmpList.Add(PropType.BestHandPos5,
|
||||
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
|
||||
r.ReadUInt16(); // reserved
|
||||
tmpList.Add(PropType.CardsValue,
|
||||
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
|
||||
tmpList.Add(PropType.MoneyWon,
|
||||
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
|
||||
tmpList.Add(PropType.PlayerMoney,
|
||||
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
|
||||
|
||||
tmpRecordList.Add(tmpList);
|
||||
}
|
||||
RecordProperties.Add(RecordPropType.PlayerResult, tmpRecordList);
|
||||
}
|
||||
|
||||
public override void Accept(INetPacketVisitor visitor)
|
||||
{
|
||||
visitor.VisitEndOfHandHideCards(this);
|
||||
visitor.VisitEndOfHandShowCards(this);
|
||||
}
|
||||
|
||||
public override byte[] ToByteArray()
|
||||
|
||||
@@ -250,6 +250,43 @@ namespace pokerth_lib
|
||||
m_callback.ShowRiverCards(tmpCards);
|
||||
}
|
||||
|
||||
public void VisitEndOfHandShowCards(NetPacket p)
|
||||
{
|
||||
List<Dictionary<NetPacket.PropType, string>> tmpList
|
||||
= p.RecordProperties[NetPacket.RecordPropType.PlayerResult];
|
||||
foreach (Dictionary<NetPacket.PropType, string> i in tmpList)
|
||||
{
|
||||
uint playerId = Convert.ToUInt32(i[NetPacket.PropType.PlayerId]);
|
||||
string name = m_data.PlayerList.GetPlayerInfo(playerId).Name;
|
||||
Player curPlayer = m_data.CurHand.Players[playerId];
|
||||
int[] tmpCards = new int[2];
|
||||
tmpCards[0] = Convert.ToInt32(i[NetPacket.PropType.FirstCard]);
|
||||
tmpCards[1] = Convert.ToInt32(i[NetPacket.PropType.SecondCard]);
|
||||
curPlayer.Cards = tmpCards;
|
||||
int[] tmpBest = new int[5];
|
||||
tmpBest[0] = Convert.ToInt32(i[NetPacket.PropType.BestHandPos1]);
|
||||
tmpBest[1] = Convert.ToInt32(i[NetPacket.PropType.BestHandPos2]);
|
||||
tmpBest[2] = Convert.ToInt32(i[NetPacket.PropType.BestHandPos3]);
|
||||
tmpBest[3] = Convert.ToInt32(i[NetPacket.PropType.BestHandPos4]);
|
||||
tmpBest[4] = Convert.ToInt32(i[NetPacket.PropType.BestHandPos5]);
|
||||
curPlayer.BestHandPos = tmpBest;
|
||||
curPlayer.CardsValue = Convert.ToInt32(i[NetPacket.PropType.CardsValue]);
|
||||
curPlayer.Money = Convert.ToUInt32(i[NetPacket.PropType.PlayerMoney]);
|
||||
|
||||
m_callback.EndOfHandShowCards(name, tmpCards, curPlayer.CardsValue, false);
|
||||
}
|
||||
foreach (Dictionary<NetPacket.PropType, string> i in tmpList)
|
||||
{
|
||||
uint moneyWon = Convert.ToUInt32(i[NetPacket.PropType.MoneyWon]);
|
||||
if (moneyWon > 0)
|
||||
{
|
||||
uint playerId = Convert.ToUInt32(i[NetPacket.PropType.PlayerId]);
|
||||
string name = m_data.PlayerList.GetPlayerInfo(playerId).Name;
|
||||
m_callback.PlayerWins(name, moneyWon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void VisitEndOfHandHideCards(NetPacket p)
|
||||
{
|
||||
uint playerId = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerId]);
|
||||
@@ -257,7 +294,7 @@ namespace pokerth_lib
|
||||
Player curPlayer = m_data.CurHand.Players[playerId];
|
||||
curPlayer.Money = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerMoney]);
|
||||
|
||||
m_callback.PlayerWinsHideCards(
|
||||
m_callback.PlayerWins(
|
||||
name,
|
||||
Convert.ToUInt32(p.Properties[NetPacket.PropType.MoneyWon]));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user