Laurens Van Keer

Laurens.VanKeer.eu

PokerRanker – A poker hand evaluator in C++/CLI

August 11th, 2009 by Laurens
PokerRanker

PokerRanker is a Windows application I wrote several months ago. Today I finally took the time to share it on my blog. :-)

This program demonstrates a collection of essential C++/CLI classes for poker (Texas Hold ‘em) applications: Card, Deck, Hand and HandEvaluator. The latter, HandEvaluator, is based on the 7 card hand evaluator written in Java by the University of Alberta.

It’s not the fastest evaluator available, but it’s a pretty simple one and does the trick for most poker applications. If you really need a lightning fast hand evaluator, check out this blog post by Coding The Wheel for a hand evaluator roundup. You’ll need to do the conversion to C++/CLI by yourself though.

PokerRanker is licensed under the terms of the GNU Lesser General Public License.

Click here to download the ZIP file containing all the project source files.

Posted in Poker, Programming | having no comments »

Back from Scotland

August 8th, 2009 by Laurens
Cycling at Scotland!

Last week I went cycling in Scotland with four friends. We took the ferry from Zeebrugge to Rosyth and cycled around Scotland. We visited Edinburgh, Elgin, Dufftown, Keith, Inverness, Loch Ness, Glasgow and many small villages in between. It was fun, but tiring. :-)

In other news… I’ve been working on a few new (poker related) software projects lately. Well, actually most of them are already finished for months, but I didn’t bother publishing them because I had other things on my mind (exams e.g.). So I’ll probably post more updates on these projects soon.

Posted in General | having no comments »

SimpleCap – A TCP packet sniffer written in C++/CLI

May 14th, 2009 by Laurens
SimpleCap

For one of my latest projects, I needed to capture certain TCP packets coming from a certain IP address and port. This is called a packet sniffer.

Luckily, a complete Windows packet capture library already exists: WinPcap (based on the libpcap Unix API). This is a popular library used by many well known packet capture applications, such as Wireshark. The documentation for WinPcap is decent, but IMHO there aren’t that many C++ examples of simple Windows packet sniffers (let alone examples in C++/CLI…). So I wrote a TCP packet sniffer in C++/CLI myself, using the UDP sniffer tutorial as a reference. The result is a small Windows application I called SimpleCap.

SimpleCap v0.1 can currently capture TCP packets from either all sources, or from a specific IP address and port. Not quite the next Wireshark, but the goal was only to show how I implemented a TCP packet sniffer in Visual C++. I hope I succeeded. If there are any problems, please let me know (either in the comment section or via the contact page).

Click here to download the SimpleCap v0.1 source files.

When starting your own packet capture project in Visual C++, don’t forget to:

  • Include all WinPcap header files
  • Add the following dependencies to your project: Ws2_32.lib (Winsock library) and wpcap.lib (WinPcap library).
    Do this by opening project properties -> Linker -> Input -> Additional Dependencies: Ws2_32.lib wpcap.lib
  • Set the /clr option (Common Language Runtime Support) on via project properties -> General -> CLR support

Posted in Programming | having no comments »

WinRegEx – A primitive regex tester in C++/CLI

April 2nd, 2009 by Laurens

While working on a project in Visual C++ (more info coming soon), I encountered some difficulties with System::Text::RegularExpressions. So I started a little side-project specifically aimed at testing this regex library. The result is this little, trivial (but useful) regular expression tester.

Download links:
the executable (for Windows platforms only obviously)
VC++ project files

Posted in Programming | having no comments »

Coding Tip: selecting a row from a matrix in managed C++

March 29th, 2009 by Laurens

I decided to update my blog now and then with coding tips for various languages I work in. These will usually be my own solutions for problems on which I can’t immediately find a clear answer on.

This first tip is specifically for writing managed C++ (in Microsoft’s Visual C++).

Suppose you have a function that accepts a managed integer array as a parameter.

void foo(array<int>^ row);

And suppose you have a managed integer matrix.

array<int, 2>^ matrix = {{1,2,3},{3,4,5},{6,7,8},{9,10,11}};

How do you pass a row (e.g. row 2) from this matrix to that function?

One way to do this, is by using native pointers. You could pin the matrix in the memory using the pin_ptr keyword (see MSDN library) and then pass a pointer to the function as an int*.
(with thanks to “Alex F” from the CodeGuru forums)

Another way is to use the following function I wrote:

array<int>^ getRowFromMatrix(array<int, 2>^ matrix, int row)
{
	array<int>^ rowArray = gcnew array<int>(matrix->GetLength(1));
	for (int i=0; i<matrix->GetLength(1); i++)
		rowArray[i] = matrix[row, i];
	return rowArray;
}

Easy, right? :-)

Posted in Programming | having no comments »