amunn / tikz-backgammon

Display backgammon games with TikZ
12 stars 2 forks source link

Backgammon LaTeX Package: Board Customisation and New Game Features #2

Open bungogood opened 8 months ago

bungogood commented 8 months ago

Dear Alan Munn,

I'm a student currently working on a dissertation on reinforcement learning in backgammon and came across your LaTeX package. It's been incredibly useful, especially as I'm still learning the intricacies of LaTeX. I've made some modifications on my fork and also noticed Javier Doal's fork had some other enhancements, particularly the adjustable board orientation and number flipping, which are more aligned with what I'm accustomed to.

Starting-Position

Enable setup from a standard format, like the gnubg position ID, though this might be challenging.

  1. For a new game, clear the entire board instead of just resetting positions with pieces.
  2. Implement adjustable board orientations, such as having the home board on the left or right.
  3. Simplify the process of changing color palettes for points, bars, and checkers.
  4. Add commands for toggling doubles, similar to dice toggling.
  5. Create an environment for initializing a blank game, possibly using pgfkeys for customization options like color, dice, doubles, and orientation.
  6. Setting up from a standard format like gnubg position id (this may be quite challenging)
\begin{backgammon}[dice=false, doubles=true, home-side=right]
    \newgame
    \boardcaption{Starting Position}
    \blackboard
\end{backgammon}

I've changed commands to clear the board and set up the starting positions:

% command to setup new blank board
\newcommand*\blankBoard{
    \foreach \x in {1,...,24} {
        \bk@setstate{\x}{white}
        \bk@setcount{\x}{0}
    }
    \double{neutral}{64}
    \bk@displaydicefalse
}

% command to setup new starting board
\newcommand*\startingBoard{
    \blankBoard
    \foreach \x in {1,12,17,19}
        {\bk@setstate{\x}{white}}
    \foreach \x in {6,8,13,24}
        {\bk@setstate{\x}{black}}
    \foreach \x in {1,24}
        {\bk@setcount{\x}{2}}
    \foreach \x in {12,19,13,6}
        {\bk@setcount{\x}{5}}
    \foreach \x in {17,8}
    {\bk@setcount{\x}{3}}
}

% command to set a new game (no longer displays it)  
\let\newgame=\startingBoard

I'm enthusiastic about this project and would love to contribute further. Although I'm not a LaTeX expert, I'm eager to learn and help out where I can.

Many Thanks, Jonathan Good

amunn commented 7 months ago

Hi Jonathan, thanks for your comments. This package is really quite old now, and was written when I was very new to TeX programming. It's never been much of a priority for me, and I'm glad you're finding it helpful. I've been contemplating rewriting it in Expl3 which I suspect would make many things easier. But that's unlikely to happen before the summer. I'm happy to incorporate these changes into the package though. Make a new branch in your fork and then create a pull request. Adding position ID code wouldn't actually be that hard; is that notation fairly widely used? I'm a very casual backgammon player, so I don't know too much about what people use. Are there other ways of notating positions? (Edit: looking a bit more into that encoding, it might not be so simple, and it's not a very user-oriented.)

amunn commented 7 months ago

I've released a new version that adds a \clearboard command to clear the state of the board. I've also added two new move rules \blkmove/whtmove which use the standard nm:from/to,from/to notation. It's equivalent to \blackroll{nm}\blackmove{from}{to}{from}{to}. Given the increased interest in the package, I plan make a proper release of the package in the summer, but I suspect most of the internals will likely be rewritten. Until that time, I'm happy to see feature requests, but I probably won't entertain any pull requests.