mchung94 / solitaire-player

Automatically play Pyramid and TriPeaks Solitaire in Microsoft Solitaire Collection for Windows 10
MIT License
41 stars 14 forks source link
solitaire

solitaire-player

Solve and automatically play Pyramid or TriPeaks Solitaire. Watch the demonstration video for getting started and solving TriPeaks Solitaire, or the demonstration video for Pyramid Solitaire. The latest release for Windows 10 for download is version 2.6.10. This requires that you install a 64 bit JRE 11 first.

2023-08-12

This program has been in "maintenance mode" for several years now, with updates as new versions of Microsoft Solitaire Collection are released. But now the game comes with its own solver, but I'm still interested in maintaining and enhancing this program as I think it's interesting from a programming perspective. I just haven't really had time to spend on it yet.

Some things I'd like to figure out:

Introduction

Purpose

solitaire-player is a Java program that can quickly find an optimal solution to Pyramid or TriPeaks Solitaire for any deck of cards you give it, if a solution exists. Also, it can automatically play Pyramid and TriPeaks Solitaire in Windows 10's Microsoft Solitaire Collection.

Features

Performance

The following performance measurements were done on an Intel i7-4770k CPU (3.5GHz, 3.9GHz max) running Windows 10. They measure the time it takes to find a solution given a deck of cards, but do not include the time it takes to play the game.

Pyramid Board Challenges

Here are timings for clearing the board on 1500 random decks of cards. 502 of them have no possible way to clear the board and the timing measurement is how long the program takes to find out there's no solution.

Decks Mean (ms) Median (ms) Maximum (ms) Total (hrs:min:sec)
1500 random decks 598 156 33093 0:14:56
998 solvable decks 296 157 4547 0:04:55
502 unsolvable decks 1198 47 33093 0:10:01

Pyramid Score Challenges

Here are timings for finding out how to get the maximum possible score on the same 1500 random decks.

Decks Mean (ms) Median (ms) Maximum (ms) Total (hrs:min:sec)
1500 random decks 6224 3804 76331 2:35:36

Pyramid Card Challenges

Here are timings for finding out how to remove as many Aces as possible from the game. It will find out the best possible solution while clearing the board, and the best solution which does not clear the board, and compare them.

Decks Mean (ms) Median (ms) Maximum (ms) Total (hrs:min:sec)
1500 random decks 6198 3610 67427 2:34:57

TriPeaks Board Challenges

Here are timings for clearing the board on the same 1500 random decks. 43 of them have no possible way to clear the board and the timing measurement is how long the program takes to find out there's no solution.

Decks Mean (ms) Median (ms) Maximum (ms) Total (hrs:min:sec)
1500 random decks 111 109 329 0:02:46
1457 solvable decks 111 109 329 0:02:42
43 unsolvable decks 81 93 125 0:00:04

TriPeaks Score Challenges

Here are timings for trying to get a relatively high score on the same 1500 random decks. It doesn't guarantee the best possible score.

Decks Mean (ms) Median (ms) Maximum (ms) Total (hrs:min:sec)
1500 random decks 366 360 734 0:09:09

TriPeaks Card Challenges

Here are timings for finding out how to remove as many Aces as possible from the board on the same 1500 random decks.

Decks Mean (ms) Median (ms) Maximum (ms) Total (hrs:min:sec)
1500 random decks 109 109 360 0:02:43

Usage

Command Line program

Requirements

Steps for automatically playing Pyramid or TriPeaks Solitaire

  1. Download the release and unzip it.
  2. Go to solitaire-player/bin.
  3. Start Microsoft Solitaire Collection on Windows 10.
    • The game must be running in Windowed View, not Full Screen.
    • Only the Classic theme and card deck can be used, it won't properly detect other themes or card decks.
    • Only 100% scaling sizes works, this can be changed in Windows Display Settings.
    • The monitor resolution must be greater than 1440x900.
  4. In Microsoft Solitaire Collection start a Pyramid or TriPeaks Solitaire game - either a regular game or a challenge game.
  5. Run solitaire-player.bat with one of the following set of command line options:
    • solitaire-player.bat Pyramid
    • This runs the Board Challenge solver - clear the board in as few steps as possible.
    • solitaire-player.bat Pyramid Board
    • This also runs the Board Challenge solver.
    • solitaire-player.bat Pyramid Score
    • This runs the Score Challenge solver - maximize the score in as few steps as possible.
    • solitaire-player.bat Pyramid Score <goal score> <current score>
    • For example: "solitaire-player.bat Pyramid Score 2400 2240" means your current score is 2240 and if you reach 2400 points you win.
    • This runs the Score Challenge solver but knows it can stop playing if it reaches the goal score.
    • solitaire-player.bat Pyramid Card <number of cards to remove> <card rank to remove> <current cards of that rank removed>
    • Card ranks are one of the letters/numbers A 2 3 4 5 6 7 8 9 T J Q K.
    • For example: "solitaire-player.bat Pyramid Card 12 A 9" means the goal is to remove 12 Aces, and you've removed 9 so far in previous games.
    • This runs the Card Challenge solver which tries to find the shortest way to remove a number of cards of a given rank.

The TriPeaks options are basically the same as Pyramid but with the word TriPeaks in place of Pyramid:

Unknown Cards

In Pyramid Solitaire, we know the entire deck of cards because we can flip through the stock pile and see what they are, then restart the game. But in TriPeaks, 18 of the cards are stuck face-down until we play the game and uncover them. This program starts off by scanning through the cards in the stock pile and undoing the game, but then in TriPeaks, it will play to flip over face down cards until it knows enough of the deck to reach the goal or otherwise turn over all the cards.

It will start off showing the deck using ?? to represent unknown cards:

      ??          ??          ??
    ??  ??      ??  ??      ??  ??
  ??  ??  ??  ??  ??  ??  ??  ??  ??
7h  3d  7d  Ah  9h  5c  Td  Ac  2h  7c
8h
As 9d Ad 4s Jc 2d 7s Jh 4d Kd 9c 8d 5s 2c 4h Qd Ts 5d 4c Ks 6c Tc 3s

As it plays the game to reveal the unknown cards, keep verifying the new face up cards, but don't delete the ones that are removed from the game - it's just trying to figure out the entire deck before it restarts the game and plays the solution from the beginning.

Steps for solving a deck you give it

  1. Create a file containing a deck of 52 cards that looks like this as an example. Cards are two letters containing rank (A23456789TJQK) followed by suit (cdhs):

Pyramid Solitaire:

            6d
          5h  Ah
        Jd  4s  Ks
      6s  8c  2h  4d
    9s  Kd  6c  Ad  8s
  Ac  5c  9d  7h  3h  8d
5s  4c  Qc  Jh  Kc  Kh  3c
3s 9c As 5d Qh Ts 4h 7s Td 9h Th 7c 8h 2c 7d Tc 2d 6h 2s Js Qd 3d Qs Jc

In the example above, the 3s is the initial card at the top of the stock pile and the Jc is the bottom of the stock pile.

TriPeaks Solitaire:

      Jd          Qs          5h
    3c  6h      6s  8s      6d  Qc
  Js  Qh  Kc  Kh  9s  3h  2s  Th  8c
7h  3d  7d  Ah  9h  5c  Td  Ac  2h  7c
8h
As 9d Ad 4s Jc 2d 7s Jh 4d Kd 9c 8d 5s 2c 4h Qd Ts 5d 4c Ks 6c Tc 3s

In the example above, 8h is the cart initially at the top of the waste pile, As is the first face-down card at the top of the stock pile and 3s is the bottom.

  1. Follow steps 1, 2, and 5 from the Steps for automatically playing Pyramid or TriPeaks Solitaire instructions, except in step 5, always add -f <filename> to give the program the deck of cards to solve. It will skip any automation and just print out the solutions it finds. For both Pyramid and TriPeaks Solitaire, the file must know all the cards.

Source Code

This is a standard gradle project so you can run things like "gradlew distZip" and run the program using the distribution. There is also a Programming Guide with details for developers.