← Back to all articles

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

Comments