Hosting your own poker tournament with LINQPad & Reactive Extensions

Playing poker next Saturday night & want to impress your friends with your programming skills?

The following solution requires LINQPad Beta release; It uses the new DumpLive feature allowing you to render reactive streams of WPF UI Elements!

Enjoy!

(from round in new[]
{
    new{Small = 5, Big = 10, Length = 16},
    new{Small = 10, Big = 20, Length = 20},
    new{Small = 20, Big = 40, Length = 20},
    new{Small = 100, Big = 200, Length = 20},
    new{Small = 300, Big = 600, Length = 20},
    new{Small = 600, Big = 1200, Length = 20},
    new{Small = 1000, Big = 2000, Length = 20},
    new{Small = 5000, Big = 10000, Length = 20},
    new{Small = 30000, Big = 60000, Length = 20},
    new{Small = 100000, Big = 200000, Length = 20},
}   
let ts = TimeSpan.FromMinutes(round.Length)
select from tick in Observable.Interval(TimeSpan.FromSeconds(1)).TakeUntil(Observable.Timer(ts))
let remaining = ts.Subtract(TimeSpan.FromSeconds(tick))
select new{
    text = string.Format("Small: {0}\r\nBig: {1}\r\nRemaining: {2}", round.Small, round.Big, remaining),
    colour = remaining < TimeSpan.FromMinutes(1) ? Brushes.Red : Brushes.Black
})
.Concat()
.ObserveOnDispatcher()
.Select(x => new TextBlock{Text = x.text, FontSize = 80, Foreground = x.colour})
.DumpLive();

OUTPUT

image

5 Responses to “Hosting your own poker tournament with LINQPad & Reactive Extensions”

  1. i97henka Says:

    I am having trouble to get this snippet to work. Which additional references and additional namespaces were used in Linqpad? (I am using LP 4.40.03 but still cannot see the DumpLive() method in the intellisense?)

    • James Miles Says:

      Could you provide some more details?

      Make sure you are using the latest beta release of LINQPad (http://www.linqpad.net/Beta.aspx)

      • i97henka Says:

        thanks for getting back James,

        I think I am using the latest beta version, LINQPad 4.40.03.

        I have the query working except the ObserveOnDispatcher line.
        with the original query I get this:

        (I think the reason may be that I have the latest beta of RX (2.0))

        if I comment out the observeondispatcher I get this:

        Any ideas how to circumvent this or get the observeondispatcher method to work?

  2. James Miles Says:

    Hi Henrik,

    It looks like you might be missing a reference to;

    System.Reactive.Windows.Threading.dll


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: