Console client: Output similar to PokerTH log.

This commit is contained in:
lotodore
2008-12-24 23:22:23 +00:00
parent 60fd3e2010
commit 6797fa3f54
11 changed files with 404 additions and 112 deletions
+68 -2
View File
@@ -52,6 +52,7 @@ namespace pokerth_lib
m_state = State.Preflop;
m_players = players;
m_myPlayerId = myPlayerId;
m_smallBlind = smallBlind;
}
public State CurState
@@ -85,12 +86,73 @@ namespace pokerth_lib
}
public uint MyPlayerId
{
get
{
// no need to lock a mutex, this is read only.
return m_myPlayerId;
}
}
public uint SmallBlind
{
get
{
// no need to lock a mutex, this is read only.
return m_smallBlind;
}
}
public uint HighestSet
{
get
{
lock (m_mutex)
{
return m_myPlayerId;
return m_highestSet;
}
}
set
{
lock (m_mutex)
{
m_highestSet = value;
}
}
}
public uint MinimumRaise
{
get
{
lock (m_mutex)
{
return m_minimumRaise;
}
}
set
{
lock (m_mutex)
{
m_minimumRaise = value;
}
}
}
public int[] TableCards
{
get
{
lock (m_mutex)
{
return (int[])m_tableCards.Clone();
}
}
set
{
lock (m_mutex)
{
m_tableCards = value;
}
}
}
@@ -98,6 +160,10 @@ namespace pokerth_lib
private Object m_mutex;
private State m_state;
private Dictionary<uint, Player> m_players;
uint m_myPlayerId;
private int[] m_tableCards;
private uint m_myPlayerId;
private uint m_smallBlind;
private uint m_highestSet;
private uint m_minimumRaise;
}
}
+9 -6
View File
@@ -28,13 +28,16 @@ namespace pokerth_lib
void InitDone();
void JoinedGame(string name);
void GameStarted(List<string> players);
void HandStarted(Hand h);
void MyTurn(Hand.State state);
void HandStarted(int[] cards);
void SmallBlind(string name, uint blind);
void BigBlind(string name, uint blind);
void MyTurn(Hand.State state, uint highestSet, uint minimumRaise, uint money);
void PlayersTurn(Hand.State state, string player);
void ActionDone(string name, Hand.Action action, uint totalBet, uint money, uint highestSet, uint minimumRaise);
void ShowFlopCards(int firstFlopCard, int secondFlopCard, int thirdFlopCard);
void ShowTurnCard(int turnCard);
void ShowRiverCard(int riverCard);
void ActionDone(string name, Hand.Action action, uint curBet);
void ShowFlopCards(int[] cards);
void ShowTurnCards(int[] cards);
void ShowRiverCards(int[] cards);
void PlayerWinsHideCards(string name, uint moneyWon);
void Error(string message);
}
}
+14 -11
View File
@@ -1,5 +1,7 @@
/***************************************************************************
* Copyright (C) 2008 by Lothar May *
* Inspired by log.cpp of the PokerTH client which is *
* Copyright (C) 2006 by FThauer FHammer *
* *
* This file is part of pokerth_console. *
* pokerth_console is free software: you can redistribute it and/or *
@@ -123,37 +125,38 @@ namespace pokerth_lib
return stateString;
}
public static string ActionToString(Hand.Action action)
public static string ActionToString(Hand.Action action, uint curSet)
{
string actionString;
switch (action)
{
case Hand.Action.None:
actionString = "None";
break;
case Hand.Action.Fold:
actionString = "Fold";
actionString = "folds";
break;
case Hand.Action.Check:
actionString = "Check";
actionString = "checks";
break;
case Hand.Action.Call:
actionString = "Call";
actionString = "calls";
break;
case Hand.Action.Bet:
actionString = "Bet";
actionString = "bets";
break;
case Hand.Action.Raise:
actionString = "Raise";
actionString = "bets";
break;
case Hand.Action.AllIn:
actionString = "All in";
actionString = "is all in with";
break;
default :
actionString = "Unknown action";
actionString = "(invalid action)";
break;
}
if ((int)action >= 3)
actionString += " $" + Convert.ToString(curSet);
return actionString;
}
}
+10
View File
@@ -104,6 +104,16 @@ namespace pokerth_lib
}
}
public void NewHand()
{
lock (m_mutex)
{
m_cards = null;
m_curAction = Hand.Action.None;
m_totalBet = 0;
}
}
private Object m_mutex;
private int[] m_cards;
private Hand.Action m_curAction;
+1
View File
@@ -45,5 +45,6 @@ namespace pokerth_lib
void VisitDealFlopCards(NetPacket p);
void VisitDealTurnCard(NetPacket p);
void VisitDealRiverCard(NetPacket p);
void VisitEndOfHandHideCards(NetPacket p);
}
}
+71 -48
View File
@@ -136,6 +136,7 @@ namespace pokerth_lib
FlopThirdCard,
TurnCard,
RiverCard,
MoneyWon,
}
public enum ListPropType
@@ -144,6 +145,11 @@ namespace pokerth_lib
ManualBlindSlots,
}
public enum RecordPropType
{
PlayerResult,
}
public static NetPacket Create(int type, int size, BinaryReader reader)
{
NetPacket tmpPacket = null;
@@ -189,12 +195,76 @@ namespace pokerth_lib
case NetTypeDealRiverCard :
tmpPacket = new NetPacketDealRiverCard(size, reader);
break;
case NetTypeEndOfHandHideCards :
tmpPacket = new NetPacketEndOfHandHideCards(size, reader);
break;
default:
break;
}
return tmpPacket;
}
public NetPacket(int type)
{
m_type = type;
m_properties = new Dictionary<PropType, string>();
m_listProperties = new Dictionary<ListPropType, List<string>>();
m_recordProperties = new Dictionary<RecordPropType, List<Dictionary<PropType, string>>>();
}
public Dictionary<PropType, string> Properties
{
set
{
m_properties = value;
}
get
{
return m_properties;
}
}
public Dictionary<ListPropType, List<string>> ListProperties
{
set
{
m_listProperties = value;
}
get
{
return m_listProperties;
}
}
public Dictionary<RecordPropType, List<Dictionary<PropType, string>>> RecordProperties
{
set
{
m_recordProperties = value;
}
get
{
return m_recordProperties;
}
}
public int Type
{
get
{
return m_type;
}
}
public abstract void Accept(INetPacketVisitor visitor);
public abstract byte[] ToByteArray();
static protected int AddPadding(int size)
{
return ((((size) + 3) / 4) * 4);
}
protected void ScanGameInfoBlock(BinaryReader r)
{
Properties.Add(PropType.MaxNumPlayers,
@@ -258,56 +328,9 @@ namespace pokerth_lib
}
}
public NetPacket(int type)
{
m_type = type;
m_properties = new Dictionary<PropType, string>();
m_listProperties = new Dictionary<ListPropType, List<string>>();
}
public Dictionary<PropType, string> Properties
{
set
{
m_properties = value;
}
get
{
return m_properties;
}
}
public Dictionary<ListPropType, List<string>> ListProperties
{
set
{
m_listProperties = value;
}
get
{
return m_listProperties;
}
}
public int Type
{
get
{
return m_type;
}
}
public abstract void Accept(INetPacketVisitor visitor);
public abstract byte[] ToByteArray();
static protected int AddPadding(int size)
{
return ((((size) + 3) / 4) * 4);
}
private int m_type;
private Dictionary<PropType, string> m_properties;
private Dictionary<ListPropType, List<string>> m_listProperties;
private Dictionary<RecordPropType, List<Dictionary<PropType, string>>> m_recordProperties;
}
}
@@ -0,0 +1,59 @@
/***************************************************************************
* Copyright (C) 2008 by Lothar May *
* *
* This file is part of pokerth_console. *
* pokerth_console is free software: you can redistribute it and/or *
* modify it under the terms of the GNU Affero General Public License *
* as published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version. *
* *
* pokerth_console is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the *
* GNU Affero General Public License along with pokerth_console. *
* If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace pokerth_lib
{
class NetPacketEndOfHandHideCards : NetPacket
{
public NetPacketEndOfHandHideCards()
: base(NetPacket.NetTypeEndOfHandHideCards)
{
}
public NetPacketEndOfHandHideCards(int size, BinaryReader r)
: base(NetPacket.NetTypeEndOfHandHideCards)
{
if (size != 16)
throw new NetPacketException("NetPacketEndOfHandHideCards invalid size.");
Properties.Add(PropType.PlayerId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropType.MoneyWon,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropType.PlayerMoney,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitEndOfHandHideCards(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,69 @@
/***************************************************************************
* Copyright (C) 2008 by Lothar May *
* *
* This file is part of pokerth_console. *
* pokerth_console is free software: you can redistribute it and/or *
* modify it under the terms of the GNU Affero General Public License *
* as published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version. *
* *
* pokerth_console is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the *
* GNU Affero General Public License along with pokerth_console. *
* If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace pokerth_lib
{
class NetPacketEndOfHandShowCards : NetPacket
{
public NetPacketEndOfHandShowCards()
: base(NetPacket.NetTypeEndOfHandShowCards)
{
}
public NetPacketEndOfHandShowCards(int size, BinaryReader r)
: base(NetPacket.NetTypeEndOfHandShowCards)
{
if (size < 40)
throw new NetPacketException("NetPacketEndOfHandShowCards invalid size.");
int numPlayerResults = IPAddress.NetworkToHostOrder((short)r.ReadUInt16());
r.ReadUInt16(); //reserved
List<Dictionary<PropType, string>> tmpRecordList = new List<Dictionary<PropType, string>>();
for (int i = 0; i < numPlayerResults; i++)
{
Dictionary<PropType, string> tmpList = new Dictionary<PropType, string>();
tmpList.Add(PropType.PlayerId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
tmpList.Add(PropType.FirstCard,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
tmpList.Add(PropType.SecondCard,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
}
RecordProperties.Add(RecordPropType.PlayerResult, tmpRecordList);
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitEndOfHandHideCards(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
+1 -1
View File
@@ -43,7 +43,7 @@ namespace pokerth_lib
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
int curNumPlayers = IPAddress.NetworkToHostOrder((short)r.ReadUInt16());
Properties.Add(PropType.CurNumPlayers, Convert.ToString(curNumPlayers));
r.ReadBytes(2); // reserved
r.ReadUInt16(); // reserved
// Read player ids.
List<string> playerSlots = new List<string>();
+59 -19
View File
@@ -150,17 +150,23 @@ namespace pokerth_lib
public void VisitHandStart(NetPacket p)
{
// Reset players.
foreach (KeyValuePair<uint, Player> player in m_players)
player.Value.NewHand();
// Assign own cards.
int[] tmpCards = new int[2];
tmpCards[0] =
Convert.ToInt32(p.Properties[NetPacket.PropType.FirstCard]);
tmpCards[1] =
Convert.ToInt32(p.Properties[NetPacket.PropType.SecondCard]);
m_players[m_data.MyPlayerId].Cards = tmpCards;
m_data.CurHand = new Hand(
m_players,
m_data.MyPlayerId,
Convert.ToUInt32(p.Properties[NetPacket.PropType.SmallBlind]));
m_callback.HandStarted(m_data.CurHand);
m_callback.HandStarted(tmpCards);
}
public void VisitPlayersTurn(NetPacket p)
@@ -168,7 +174,8 @@ namespace pokerth_lib
uint curPlayer = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerId]);
Hand.State state = (Hand.State)Convert.ToUInt16(p.Properties[NetPacket.PropType.GameState]);
if (curPlayer == m_data.MyPlayerId)
m_callback.MyTurn(state);
m_callback.MyTurn(state, m_data.CurHand.HighestSet,
m_data.CurHand.MinimumRaise, m_players[curPlayer].Money);
else
m_callback.PlayersTurn(state, m_data.PlayerList.GetPlayerInfo(curPlayer).Name);
}
@@ -182,19 +189,32 @@ namespace pokerth_lib
{
uint playerId = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerId]);
Player curPlayer = m_data.CurHand.Players[playerId];
string name = m_data.PlayerList.GetPlayerInfo(playerId).Name;
curPlayer.CurAction =
(Hand.Action)Convert.ToUInt16(p.Properties[NetPacket.PropType.PlayerAction]);
curPlayer.Money =
Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerMoney]);
curPlayer.TotalBet =
Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerBetTotal]);
m_callback.ActionDone(
m_data.PlayerList.GetPlayerInfo(playerId).Name,
curPlayer.CurAction,
curPlayer.TotalBet,
curPlayer.Money,
Convert.ToUInt32(p.Properties[NetPacket.PropType.HighestSet]),
Convert.ToUInt32(p.Properties[NetPacket.PropType.MinimumRaise]));
uint curBet = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerBetTotal])
- curPlayer.TotalBet;
curPlayer.TotalBet += curBet;
m_data.CurHand.HighestSet = Convert.ToUInt32(p.Properties[NetPacket.PropType.HighestSet]);
m_data.CurHand.MinimumRaise = Convert.ToUInt32(p.Properties[NetPacket.PropType.MinimumRaise]);
if (curPlayer.CurAction == Hand.Action.None)
{
if (curBet == m_data.CurHand.SmallBlind)
m_callback.SmallBlind(name, curBet);
else
m_callback.BigBlind(name, curBet);
}
else
{
m_callback.ActionDone(
name,
curPlayer.CurAction,
curBet);
}
}
public void VisitPlayersActionRejected(NetPacket p)
@@ -204,22 +224,42 @@ namespace pokerth_lib
public void VisitDealFlopCards(NetPacket p)
{
m_callback.ShowFlopCards(
Convert.ToInt32(p.Properties[NetPacket.PropType.FlopFirstCard]),
Convert.ToInt32(p.Properties[NetPacket.PropType.FlopSecondCard]),
Convert.ToInt32(p.Properties[NetPacket.PropType.FlopThirdCard]));
int[] tmpCards = new int[3];
tmpCards[0] = Convert.ToInt32(p.Properties[NetPacket.PropType.FlopFirstCard]);
tmpCards[1] = Convert.ToInt32(p.Properties[NetPacket.PropType.FlopSecondCard]);
tmpCards[2] = Convert.ToInt32(p.Properties[NetPacket.PropType.FlopThirdCard]);
m_data.CurHand.TableCards = tmpCards;
m_callback.ShowFlopCards(tmpCards);
}
public void VisitDealTurnCard(NetPacket p)
{
m_callback.ShowTurnCard(
Convert.ToInt32(p.Properties[NetPacket.PropType.TurnCard]));
int[] tmpCards = new int[4];
m_data.CurHand.TableCards.CopyTo(tmpCards, 0);
tmpCards[3] = Convert.ToInt32(p.Properties[NetPacket.PropType.TurnCard]);
m_data.CurHand.TableCards = tmpCards;
m_callback.ShowTurnCards(tmpCards);
}
public void VisitDealRiverCard(NetPacket p)
{
m_callback.ShowRiverCard(
Convert.ToInt32(p.Properties[NetPacket.PropType.RiverCard]));
int[] tmpCards = new int[5];
m_data.CurHand.TableCards.CopyTo(tmpCards, 0);
tmpCards[4] = Convert.ToInt32(p.Properties[NetPacket.PropType.RiverCard]);
m_data.CurHand.TableCards = tmpCards;
m_callback.ShowRiverCards(tmpCards);
}
public void VisitEndOfHandHideCards(NetPacket p)
{
uint playerId = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerId]);
string name = m_data.PlayerList.GetPlayerInfo(playerId).Name;
Player curPlayer = m_data.CurHand.Players[playerId];
curPlayer.Money = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerMoney]);
m_callback.PlayerWinsHideCards(
name,
Convert.ToUInt32(p.Properties[NetPacket.PropType.MoneyWon]));
}
private PokerTHData m_data;