/BGA

Bridge Gameplay Analysis

Primary LanguageC#MIT LicenseMIT

Forked project

This is forked from BGA, and compiled into a DLL used from BEN, the open source bridge engine.

BGA

Bridge Gameplay Analysis (BSc Thesis project)

Subject: Desktop application for the analysis of gameplay in card game of Bridge

University: Politechnika Bydgoska im. Jana i Jędrzeja Śniadeckich

alt text

Introduction

The aim of this project is to create a desktop application enabling the analysis of Bridge gameplay. The following doc discusses the practical result of the application development process, provides insight into the architecture of components and the adopted solutions using the Bridge Calculator library (http://bcalc.w8.pl/), as well as statistical analysis. The main program requirements include a user-friendly graphical interface allowing users to define their own gameplay problems, navigate through the game by placing cards on the table, perform gameplay analysis from the perspective of the declarer, and update analysis results for each possible play in terms of approximate win probability and predicted number of tricks to be taken. Based on the analyzed game positions, the program statistically selects moves promising the highest number of winning playouts.

In the recent past, similar programs have been developed, which to this day can be divided into two categories - commercial software and freeware. Their significant drawback is the closed source code - apart from the code curtain itself, these applications operate solely based on the selection of the best move, without presenting any calculations or the reasons behind choosing such a move. The discussed solution in the project is fully available for free, along with open-source code under the MIT license. This license allows for unlimited use, modification, and distribution. The advantage of open-sourcing is primarily flexibility, as unrestricted access gives developers the opportunity to customize the program to their needs, and thanks to the community, one can be assured that any gaps and suggestions will be easily addressed by the creator.

Apart from its open distribution, the application can serve as a "teacher" - it instructs new Bridge enthusiasts on how to play a contract for maximum chances, allows them to shape popular Bridge techniques such as finesses or squeezes, and also reinforces the acquired knowledge that can be applied in practice. The application supports all possible card distributions intended for analysis with any contract agreed upon by the players. Thus, users can analyze previously current_trick hands and assess to what extent the gameplay progressed in terms of strategy and tactics. A precise knowledge of the deals is not necessarily required, as the analysis can take place concurrently with the ongoing contract.

Solution

The solution relies on the use of statistical analysis to calculate the probability of winning a contract by the declarer pair. The analysis is based on the popular Perfect Information Monte Carlo method, originally used for decision-making in games with imperfect information. Position evaluation operates by utilizing the Bridge Calculator library, which solves the game with an assumption that all cards are not hidden. The entire process of analysis, problem definition, and game simulation takes place in a desktop application created in the .NET Framework 4.6.1 environment.

An essential element of the analysis is generating combinations of opponents' card distributions and drawing conclusions based on the calculations performed, as well as implementing multithreading to expedite this process. Users have the ability to navigate through the game by placing cards on the table. It should be noted that only the card distributions of the declarer pair playing the contract are defined at the input. This is because the algorithm analyzing the game must examine many different opponents' card distributions. The more cards we add to the table, the more the program learns about the entire distribution. For example, if a particular opponent does not play a card in the led suit, it indicates that they no longer have cards of that suit. The game under consideration should proceed according to the actual distribution of cards, where the user takes responsibility for their correct placement - since the distributions of the declarer pair are well known, the program also prevents illegal plays from their side. Additional information for the algorithm includes knowledge of the contract, the side currently leading the trick, and the cards already current_trick to the table.

Perfect Information Monte Carlo

According to the theory of games with incomplete information, individual game states form an information set, which dictates how the game under consideration unfolds. For example, in card games, some participants do not reveal their cards, so the set of positions includes states that define all possible combinations of card distributions. A player aims to maximize their chances by analyzing each possible scenario. When choosing a position from the set (also known as determinization), we receive a game with perfect information. The Perfect Information Monte Carlo (PIMC) method is a technique designed for decision-making in games with incomplete information. Random determinizations are assigned as samples, for which the algorithm statistically determines the move that yields the highest winning coefficient. The algorithm uses a function returning values of game position evaluations for an analytical compilation of results. Although the method has received positive feedback across a wide range of games with imperfect information, it is not without flaws.

The PIMC method, when applied to Bridge games, cannot play based on bluffing or retain information about the participants' leads, which could be very useful for a defensive play. Problems also arise from the fact that the move statistically determined by PIMC to be winning is based on the analysis of games with perfect information - however, there are many situations where this assumption is incorrect. This problem was described in the paper of Frank and Basin and termed the "strategy fusion" (https://core.ac.uk/download/pdf/82412244.pdf). It arises from the properties of games with incomplete information, where each move determines how the game will unfold further. In the deterministic variant, only one game state is possible - in games with incomplete information, however, there are many possible states. When analyzing different determinizations, the algorithm gains insight into all participants' cards and determines the optimal line of play for each state. In other words, the method assumes that it knows the solution for all considered cases, which is impossible to achieve because players do not know which cards the other players hold, except for the declarer's partner. With such an approach, the evaluation of the position changes drastically after playing the card for which the highest winning coefficient was determined, and the consequences can be negative.

This problem could be solved in many different ways. The simple one works by conducting a game simulation for each possible play by the declarer, in which the opponent plays any card to the led suit. Subsequently, the algorithm calculates tricks for the declarer's partner's hand and determines whether any of the cards yield one trick less for the pair than originally assumed. The simulation should consist of two variations - one composed of randomly drawn opponent cards and the other based on the same distributions but reversed. The modification was included into the statistical analysis when calculating tricks using the Bridge Calculator engine.