Skip to content

Commit 2eb4c2b

Browse files
committed
Sending data to rainman
1 parent 3e94b75 commit 2eb4c2b

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

‎src/PokerPlayer.cs‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Net;
66
using System.Text;
7+
using Newtonsoft.Json;
78
using Newtonsoft.Json.Linq;
89

910
namespace Nancy.Simple
@@ -111,18 +112,25 @@ private static bool GetPlay(out int betValue, List<Card> cards, JToken community
111112
return true;
112113
}
113114

115+
var commCount = communityCards.Count();
116+
var allCards = new List<Card>(cards);
117+
foreach (var card in communityCards)
118+
{
119+
var rank = card["rank"].Value<string>();
120+
var suit = card["suit"].Value<string>();
121+
allCards.Add(new Card(rank,suit));
122+
}
114123

115124
try
116125
{
117-
ContactRainman();
126+
ContactRainman(allCards);
118127
}
119128
catch (Exception ex)
120129
{
121130

122131
Console.Error.WriteLine(ex);
123132
}
124133

125-
var commCount = communityCards.Count();
126134
if (commCount == 3)
127135
{
128136

@@ -214,15 +222,24 @@ public static int SmallRaise(int currentBuyIn, int currentBet, int smallBlind)
214222
return currentBuyIn + currentBet + smallBlind*2;
215223
}
216224

217-
public static void ContactRainman()
225+
public static void ContactRainman(List<Card> allCards)
218226
{
219227
string address = "http://rainman.leanpoker.org/rank";
220228
var httpWebRequest = (HttpWebRequest)WebRequest.Create(address);
221229
httpWebRequest.ContentType = "text/plain";
222230
httpWebRequest.Method = "POST";
223231

224-
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
232+
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()
233+
))
225234
{
235+
var baseStr = "cards=";
236+
237+
var result = JsonConvert.SerializeObject(allCards);
238+
Console.Error.WriteLine("Json sent: " + result);
239+
240+
241+
242+
226243
string json = "cards=[{ \"rank\":\"5\",\"suit\":\"diamonds\"}]";
227244

228245
streamWriter.Write(json);

0 commit comments

Comments
 (0)