Support for solving Golf using bh-solver.
ClosedPublic

Authored by shlomif on Jan 27 2019, 2:31 PM.

Details

Summary

Support for solving Golf using bh-solver.

See https://github.com/shlomif/black-hole-solitaire and
https://www.shlomifish.org/open-source/projects/black-hole-solitaire-solver/
.

This is a preliminary version but seems to work. There is an
optional build dep with a fallback on the existing algo.

Test Plan

test that the golf variant is working as before and the new solver
is working.

Diff Detail

Repository
R410 KPatience
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
shlomif created this revision.Jan 27 2019, 2:31 PM
Restricted Application added a reviewer: KDE Games. · View Herald TranscriptJan 27 2019, 2:31 PM
Restricted Application added a subscriber: kde-games-devel. · View Herald Transcript
shlomif requested review of this revision.Jan 27 2019, 2:31 PM
shlomif updated this revision to Diff 50396.Jan 27 2019, 9:01 PM

Fixes and cleanups.

  • ifdef some unused code in WITH_BH_SOLVER and a fix
  • ifdef unused code
  • Extract a method or a function.
  • Bug fix: initialize to 0.

Any comments?

aacid added a subscriber: aacid.Feb 4 2019, 9:42 PM

What's the point?

is it better? is it faster?

@aacid : for deal no. 5 (starting position) the old solver reports that "This game cannot be won", while my solver solves it quickly and to completion. I can try collecting statistics on a range of deals wrt the performance of the two solvers.

Hi!

I found out that kpat has a command line range solving mode. Here are the results of the first 5,000 deals:

Old		New		Count
---		---		-----
lost		lost		2291
lost		unknown		462
lost		won		930
unknown		lost		9
unknown		unknown		56
unknown		won		38
won		unknown		13
won		won		1201

They were generated using:

#! /bin/bash
#
# analyze.bash
# Copyright (C) 2019 Shlomi Fish <shlomif@cpan.org>
#
# Distributed under terms of the MIT license.
#


filt2()
{
    grep -E '^[1-9]' | head -5000
}
filt()
{
    filt2 | perl -lanE 'say $F[1]'
}
echo $'Old\t\tNew\t\tCount'
echo $'Old\t\tNew\t\tCount' | perl -lpE 's/\w/-/g'
paste <(< old-golfs.txt filt) <(< new-golfs.txt filt) | sort | uniq -c | perl -lanE 'say "$F[1]\t\t$F[2]\t\t$F[0]"'

The new solver (bh-solver) solves more deals including ones that were reported as impossible. It seems to be slower in bulk mode though, but it is fast enough for solving a single deal.

For the record, the kpat cmd line I used was ./kpat --start 1 --end 1000000 --solve 12 2>&1 | tee -a new-golfs.txt

Better formatted table:

Old                 New                 Count
---                 ---                 -----
lost                lost                2291
lost                unknown             462
lost                won                 930
unknown             lost                9
unknown             unknown             56
unknown             won                 38
won                 unknown             13
won                 won                 1201

and the new script:

#! /bin/bash
#
# analyze.bash
# Copyright (C) 2019 Shlomi Fish <shlomif@cpan.org>
#
# Distributed under terms of the MIT license.
#


filt2()
{
    grep -E '^[1-9]' | head -5000
}
filt()
{
    filt2 | perl -lanE 'say $F[1]'
}
head_()
{
    echo $'Old\tNew\tCount'
}
(
head_
head_ | perl -lpE 's/\w/-/g'
paste <(< old-golfs.txt filt) <(< new-golfs.txt filt) | sort | uniq -c | perl -lanE 'say "$F[1]\t$F[2]\t$F[0]"'
) | perl -lanE 'printf"%-20s%-20s%s\n",@F'

First 20,000 deals:

Old                 New                 Count
---                 ---                 -----
lost                lost                9038
lost                unknown             1971
lost                won                 3674
unknown             lost                47
unknown             unknown             254
unknown             won                 149
won                 unknown             56
won                 won                 4811
shlomif updated this revision to Diff 50964.Feb 5 2019, 4:33 PM
  • avoid compile warnings.
aacid added a comment.Feb 6 2019, 8:56 PM

Those numbers look good.

My only concern is that when we get bugs for "solver was wrong" now we have to magically guess which solver was used, but oh well.

I don't really think we have a maintainre for kpat, so i guess you can go ahead commit it and become the maintainer :D

@aacid : OK, thanks for the review. I think I will commit my changes.

This revision was not accepted when it landed; it landed in state Needs Review.Feb 7 2019, 8:49 AM
This revision was automatically updated to reflect the committed changes.