Tag Archives: bridge

Developing software for playing bridge

I am a duplicate bridge player in my spare time and enjoyed playing in my local club once or twice a week. That was before COVID-19 and then, in March this year, lockdown. Bridge clubs were no longer able to meet. There are more important things in the world; but bridge is both a lot of fun and a welcome distraction from weightier matters, and my thoughts soon turned to what we could do to continue playing in these new circumstances.

The answer was to play online; but while there are plenty of ways to play bridge online, the existing systems were not designed with the idea of being a way for bridge clubs to meet in a new context. If anything, the reverse is true: online bridge site were designed for people who could not easily get to a club or wanted to play at any time with whoever else happened to be available. Clubs like my own, by contrast, wanted to replicate their face-to-face meetings with an online equivalent. A further complication back in March was that the biggest online bridge site, called Bridgebase, was immediately overloaded and declared that it was unwilling to allow new people to qualify as directors, people allowed to run online bridge sessions.

My immediate instinct was to build a new site for playing bridge. I was not quite starting from scratch. Back in the early days of Windows 8, I started work on a bridge game for Microsoft’s new and as it turned out ill-fated platform. I had got some way with it; I had created a bridge engine that understood about cards and hands and tricks and shuffling and scoring and all the various elements that go into playing bridge. It was written in C# and what is now UWP XAML. It is designed of course for a solo player. Here is the bidding screen:

image

and the play screen:

image

This is how it looks on Windows 10; it looked a bit better on Windows 8 though it would not win any prizes for design. My software could play bridge though; the reason I never finished it was that I never cracked getting the AI working. But for human to human play that did not matter. A weekend or two coding, I thought, and I could have a website up and running so our club could play bridge online. I made an immediate start, registering the domain name YourBridgeClubOnline.co.uk.

Well, three months later and here we are.

image

image

It is, I have to say, still under development. But it works and we have been able to play bridge again, as a club.

What took you so long? Ha! Much of my old bridge engine code remains untouched and has proved useful; it all runs fine on .NET Core. Even the (useless) AI has been handy, as I can test the mechanics of play without involving others. But I had, of course, wildly underestimated the problem of converting a game for solo play on Windows, to a multi-player web application. There is much to think about:

The UI. I am not a designer (I am sure you can tell) but spent ages puzzling over how to get a workable user interface in the browser for everything from tablets to desktops. Not smartphones yet but it is coming. I decided early on to take a view on compatibility. No Internet Explorer. JavaScript fetch API is required. When time is against you, it is easier to say, just use another browser, than to waste too much time supporting old browsers.

Messaging – both the API kind, and the chat kind. I am using C#, ASP.NET Core and SignalR. In general it works well. SignalR uses WebSockets as first preference, but falls back to Server Sent Events or long polling where necessary. In my first experiments I did my own polling and switching to SignalR was a great relief.

Registration and login. I am using the stuff that comes in the box, ASP.NET Core Identity. It has saved me a ton of work. It’s a bit annoying and not too well documented. I don’t really like using GUIDs for the primary key, for example, and I believe there is way to avoid it, but it isn’t top priority when you are going for Minimum Viable Product.

JavaScript. I’ve written tons of it and I don’t even like the language. I have a new respect for it though. The thing is, it is very fast and there is nothing you cannot do. The worst thing is the friction of doing some debugging in the browser, and some in Visual Studio. I am thinking of switching to VS Code for development since it works nicely with ASP.NET Core and is better for JavaScript than Visual Studio.

Scoring. My Windows software could score a hand of bridge. But duplicate is different; you have to compare the scores with others who played the same hands and work out the percentages, then export the results to standard formats for display on club websites and submission to the English Bridge Union. It was more work than I had expected and I am not done yet; the system only understands Pairs at the moment, not Teams (a different way of scoring).

Directing. Someone has to manage an online bridge session, settle any arguments, and fix errors like cards played by accident. It all needs coding and there was nothing like it in the Windows version.

Movements. Imagine you have 28 people playing bridge (or 14 pairs). They need to all play the same hands, but never play the same hand twice, and it has to be so arranged that each pair plays against other pairs in a defined sequence so it is balanced and fair. We call this the movement. Online, you have a bit more flexibility because you don’t need to share physical cards: everyone can play the same hand at the same time if you like. It is still quite fiddly though, and I did not do any of this in the old Windows version. I saved some time by writing an import function to enable re-use of movements made for EBUScore, a widely used scoring and bridge session management application. There is more to do though.

Claims. This is where, half way through the hand, a player says, “There’s no point in playing on, I’m obviously going to win all the remaining tricks.” A trick is a sequence of four cards played one from each hand, which is won by one of the pairs. This statement is called a claim, and has to be agreed by the other players. Getting this working was more difficult than I had expected – because built into my bridge engine was the idea that you could score by counting the tricks each side had won. But claimed tricks are never played. With hindsight, I should have allowed for this from the beginning.

Database. Every detail of play has to be stored on the server. I am using Dapper and SQL Server currently, though it is possible that PostgreSQL would work just as well. I started with Entity Framework Core, still there as it is used by ASP.NET Core Identity, but I am happier with Dapper.

Things that worked well

Three months is longer than I had thought it would take to get to a playable system, but I suppose as a spare time project it is not too bad. It would not be possible without the likes of ASP.NET Core and Dapper and SignalR doing so much for you. C# is a delight for coding. I am also using an Azure App Service for all this test and development and that has worked well. I am deploying to a Linux container of course; but the nice thing about App Service is that it will scale to a considerable extent without the hassle of Kubernetes. If the project succeeds and needs to scale up, there is an Azure SignalR service ready and waiting. I was nevertheless interested to see that AWS now offers .NET Core on Elastic Beanstalk, complete with some nice Visual Studio integration. Trying it there would be an interesting experiment, though I’m not sure AWS is so savvy about SignalR.

Open Source?

Could this have been done quicker by making it open source and seeking collaborators early on? Will it become open source? I need help for sure, though I also feel the code needs some cleaning up before it is fit to share more widely. You will recall though that I had started out thinking that it would be a small matter to convert my solo bridge game to an online multiplayer web application. I figured it would be better to get something working and then ask for help. But I am open to offers! Note: this is not a commercial project.

Rewarding

Most of the software projects I have been involved in have been business applications. Bridge is a lot more fun. I do see software development as a creative act. I recall starting work on the bridge game back in 2011 (I think); starting a new blank project in Visual Studio and thinking, hmm, I had better write a class to represent a pack of cards. From that beginning I ended up with an application that could play bridge, after a fashion, and now one that multiple people can play concurrently. It is rewarding and I will not regret the time spent on it, irrespective of how much actual use it gets.

Contract Bridge on a tablet: Funbridge vs Bridgebase vs Bridge Baron

Bridge is an ideal game for a tablet, well suited to touch control and the kind of game you can play for a few minutes or a few hours at a time, which is excellent for travellers.

So what are the choices? Here is a quick look at some favourites.

Funbridge is available for iPhone, iPad and Android. There are also versions for Windows and Mac. The Android edition is the newest but works fine, though of all of them it is the iOS release that is the nicest to use.

image

The way Funbridge works is that you always play against a computer, though this is on the internet rather than running locally, but your scores are compared with other humans playing the same hands. I have not tried the “Two players game” so I am not sure how that works, except that the other player has to be a “friend” in the Funbridge community system. It looks like you play with your friend against two bots.

Funbridge has a lot to like. The user interface is excellent, much the best of all the tablet bridge software I have used and better than most desktop bridge software too. There is a good variety of game options, including one-off games, tournaments of 5 games each, and a series ladder you can climb from 1 club to 7 no trumps. You can select one of 6 conventions, including ACOL, SAYC (American Standard), and 5 card major at three levels from beginner to expert. I think this is a hint that to get the best from Funbridge you should use the 5 card major system.

Another nice feature of Funbridge is that you can go back and replay a hand to try a different line of play. You can also see all the other scores on any hand, and how they were bid and played.

Funbridge is not perfect though. The bidding is eccentric at times, and it can be hard to persuade your partner bot to play in no trumps rather than a suit. There is definitely an art to winning at Funbridge that is a different from what it takes to win at a real bridge table.

Since you are playing against a cloud-based server, you can only play if you have an internet connection. Not so good for most flights.

Funbridge is a pay per game service. Currently 50 deals costs £1.49 (about 3p each) or if you pay more the per-deal cost falls to under 2p. Unlimited deals for a year costs £69.99.

That said, you can get 10 games a week for free, though you only get the 10 free games if you have no paid games in your account; slightly unfair to the paying customers.

Bridgebase is available for iPad, iPhone, Android and Amazon Kindle. Bridgebase also offers a browser-based game based on Adobe Flash. Like Funbridge, you can only play with an internet connection. You can either play with human opponents, or solo with three bots.

image

Of course human opponents are more fun, though there are advantages to playing with bots. No pressure, you can think for as long as you like, and none of the issues which afflict online bridge, such as players simply disappearing when in a bad contract, or being bad tempered if you make a mistake.

The Bridgebase user interface is OK though feels clunky compared to the smoothness of Funbridge. As in Funbridge, you can compare your score with other human players even if you play against bots. You cannot replay games, but you can undo your play which means you can easily cheat against the bots if you feel so inclined. Against humans your opponents have to approve an undo, which they will be reluctant to do other then in cases of genuine mis-taps.

The biggest problem with Bridgebase is the standard of the bots, which is much weaker than Funbridge. The play can be quite bizarre at times, sometimes excellent, sometimes daft.

A weak feature is that if your computer partner wins the auction, it also plays the contract, sometimes badly. I do not see the point of this. You may find yourself playing “hideous hog” style (Victor Mollo’s character who always tried to play the contract) as it is painful reaching a good contract but watching the bot throw it away.

Bridgebase is free to play, though there are subscription options online to get some extra features.

Bridge Baron is available for Android, iPad, iPhone, Amazon Kindle and Barnes and Noble Nook. It is inexpensive (£13.99 currently on the App Store) but you have to pay separately for each platform. Unlike the other two games, Bridge Baron runs entirely on your device, which is good if you are offline, but means you do not compare your score against other humans. You can set the standard from novice to advanced.

Bridge Baron plays well enough to be fun, though well short of the best computer players. You can replay games at will. You can compare your score against the Baron’s score, review the bidding and play, and undo your play at will. You can also ask for a hint from the Baron.

The Bridge Baron user interface is basic, a little worse than Bridgebase (though faster) and much worse than Funbridge. I do not know why the card icons are so small; it is like playing on a huge table.

image

Still, good fun and good value.

Conclusion

All three of these games have something to commend them. Funbridge for the best user interface and a standard good enough to be enjoyable despite a few eccentricities. Bridgebase for the option to play with real people, and for free play with bots. Bridge Baron for playing offline.

On the other hand, Bridgebase is spoilt by the poor play of its bots. Bridge Baron is dull because you cannot compare your score with other humans. Funbridge is the one I choose if I have some deals available, but can get expensive if you play a lot, and you will get annoyed with your computer partner from time to time.

There is nothing on a tablet that comes close to Jack Bridge for standard of play.

Finally, note there is no bridge app for Windows RT. So if you are a bridge addict with a Surface RT, you are out of luck.

Bridge for Apple iPad and iPhone: FunBridge upgraded, no longer free

GOTO Games has updated Funbridge for iOS to version 3.0, adding many features and introducing a per-game fee.

image

FunBridge is a Contract Bridge app in which the play is always online. You play against the computer but compare your score to that of others. In this new version the game engine seems little changed, but interaction with others is much greater, making it more like the web version.

image

In the earlier release, you could see your ranking and which users were in the top 10 for a tournament of 10 games, but you could not discover anything about another user beyond the username. Now there are user profiles and you can see another user’s overall ranking and, if they choose to provide it, name, age, location and About me notes.

Tournaments no longer stand alone, but are grouped into series which match you with players of similar standard. Rankings are decided after each period of a week, based on the results from short 3-game tournaments, provided you play at least 5 during the period. There are 35 series, and after each period the top 25% are promoted and the bottom 25% demoted from each.

You can also play in old-style Daily Tournaments, which are now more frequent than before with a new one every two hours, but these are not grouped into series. You can also play practice hands. The Daily Tournaments and practice hands are scored with IMPs (International Match Points), whereas the Series Tournaments are scored with pairs-style percentages; if you score just slightly more then others, you get 100%, and even a good score can get you 0% if everyone else made an overtrick.

The other big change to mention is that play is no longer free, though you get an introductory 100 games.

image

Games cost from 3p each falling to 1.75p if you purchase 1000 at a time. FunBridge will give you 5 games free if you reveal your birthday and another 5 for your city. Is your birthday worth more than 15p?

This makes FunBridge expensive compared to most iOS games. It is a different model to the web version, where you pay €9.90 per month (a bit less if you subscribe for a year) for unlimited games. That would buy around 400 games on the iOS version so you win or lose depending how often you play.

The game itself truly is a lot of fun, though I have found a few frustrations. The play is generally good, though eccentric occasionally. The bidding can be perplexing, especially as the bidding conventions are not described in detail, so you have to guess exactly which variant the computer is supposed to be playing. There is help for the meaning of simple bids, but this does not always match the selected convention and cannot be trusted.

Still, everyone is in the same situation so it is fair!

Hands seem to be tilted towards interesting deals; I have never seen a 10-card suit in one hand in regular bridge but I have in FunBridge.

Gameplay can be annoyingly slow even on a good connection; though perhaps when everyone has played all their free games this will improve!

A fun game; but with the new subscription model I wonder if we will see some alternatives at lower cost. It would also be good to see a version for Android and other mobile operating systems.

Funbridge: bridge for iPhone and iPad

There are several bridge app for Apple’s iPhone and iPad, but the one I’ve had most fun with is called, appropriately, Funbridge. This is already well-established as a Windows application, where you play against a computer but can compare your performance to other players, making the results much more interesting.

The iOS version is currently a free app, and has just been updated to include Tournaments as well as one-off games, now called Training.

image

In the latest version, you have to log in to play more than a couple of games, though the account is free.

image

Bidding and play is straightforward, with a few caveats. There is no fine-grained control over bidding conventions; you can choose between Beginner, Advanced, Expert, American Standard, Acol, or Polish system. Unless you choose Acol, these are all strong no trump, 5 card major systems. It is worth reading up on the systems used in detail, as otherwise you will get unpleasant surprises.

Note that during both bidding and play, Funbridge will call back to the server before every decision. This means you cannot play offline, and if you are playing where the internet connection is weak, such as on a train, you can expect frustrating delays; games can take so long that you forget what has been played!

image

During play just tap a suit to display all the cards you hold in that suit, then tap a card to play. Take care – there is no undo, and it is all too easy to tap the wrong card and then watch with horror as you see your safe contract sailing down to a penalty.

You can choose to withdraw on a hand, in which case it is not scored, but if you then play it again, you are given a kind of informational score that does not count towards your ranking. It can still be interesting to see how a different line works out.

Once play has completed, you get to compare your score with others and see how many IMPS (International Match Points) you achieved.

image

A really nice feature is that you can click the magnifying glass and get details of each contract, including card-by-card analysis. So if you are amazed at how well or badly someone managed to do, you can see how it happens. Sometimes, I have to say, it happens only because of a baffling misplay. I imagine this happens when the computer is playing on the other side, unless there are serious bugs in the engine.

A Tournament is a sequence of 10 games, at the end of which you can see how you rank among the other players, currently ranging from 150 to 750 or so in number. Scoring in tournaments seems to alternate between IMPs and Pairs scoring – the difference being that Pairs scoring rewards small differences in the score and makes big differences less costly, whereas with IMPs the reverse is true.

Overall it is enjoyable, though as in real bridge there are moments of frustration. The hands seem tilted towards more interesting or better than average holdings, though it is hard to be sure.

One complaint: the server seems to get too busy at times and the software does not cope particularly well; you click Connect and there is no error message, nothing happens.

Enjoy it for nothing while you can – it is “currently free” but I suspect will eventually attract a subscription cost – maybe a similar subscription rate to the desktop version, €74.00 for a year, or maybe something different.