std::vector<tableau> play_all_games(const deck & hand)
candidates = play_all_games(hand);
legal = smaller = false;
for (i = 0; i < candidates.size(); i++)
if target == candidates[i]
legal = true
else if candidates[i] < target
smaller = true
play_all_games()?
std::vector<tableau> next_possible_games(tableau)
tvec play_all_games(hand)
tvec candidates, final
candidates.push_back(tableau(hand))
while !candidates.empty()
tableau t = candidates.back()
candidates.pop_back()
tvec new_tabs = possible_next_tabs(t)
if (new_tabs.empty())
final.push_back(t)
else
candidates.insert(
candidates.end(),
new_tabs.begin(), new_tabs.end())
return final
next_possible_tableaus() should not require further wishes.
play_all_games() pops an old game and pushes new games.
$ time echo ac ad ah as | acheck
final.size() = 79.
0.01s real
$ time echo ac ad ah as 2c | acheck
final.size() = 356.
0.04s real
$ time echo ac ad ah as 2c 2d | acheck
final.size() = 5764.
0.56s real
$ time echo ac ad ah as 2c 2d 2h | acheck
final.size() = 905187.
76.75s real
$ time echo ac ad ah as 2c 2d 2h 2s | acheck
Abort
2982.37s real
static bool find_smaller(
tableau tgt, deck hand, tableau & smlr)
tvec candidates
candidates.push_back(tableau(hand))
do
smlr = candidates.back()
if smlr < tgt
return true
candidates.pop_back()
tvec new_tabs =
possible_next_tableaus(smlr)
candidates.insert(
candidates.end(),
new_tabs.begin(), new_tabs.end())
std::sort(
candidates.rbegin(), candidates.rend())
while !candidates.empty()
return false
t1 can lead to
tableau t2.
bool tableau:: compatible(const tableau & t) const
returns true if and only if the given tableau leads to this tableau.
t1: | As 2s 3s | t2: | Ah As 2s 3s |
| Ah 2h | 2h |
t1 is compatible with t2; t2 is not compatible with
t1.
t1: | As 2s 3s | t2: | As 2s 3s |
| Ah 2h | 3c Ah 2h | ||
| 3c |
t1 is compatible with t2; t2 is not compatible with
t1.
bool find_target(tableau target, deck hand)
tableau t
tvec candidates
candidates.push_back(tableau(hand))
do
do
t = candidates.back()
candidates.pop_back()
while !target.compatible(t) and
!candidates.empty()
if t == target
return true
if !target.compatible(t)
return false
const tvec new_tabs =
possible_next_tableaus(t)
candidates.insert(
candidates.end(),
new_tabs.begin(), new_tabs.end())
while !candidates.empty()
return false
acheck was still working on an eight-card deck.
$ sort < o | uniq -c | sort -rn > o2
$ wc -l o o2
1000000 o
2909 o2
$ head -5 o2
12388 2dadahac2c2h as2s
11410 2s2d2cacasadah2h
11410 2d2s2cacasadah2h
11410 2d2cacasadah2h 2s
8965 2s2d2cacadasah2h
$
static bool find_legal_dp(
const tableau & target, const deck & hand)
tvec candidates;
candidates.push_back(t);
strset considered;
while (!candidates.empty())
t = candidates.back()
candidates.pop_back()
if (t == target)
return true
tvec nt = possible_next_tableaus(t)
for b = nt.begin(); b != nt.end(); b++
std::string s = b->as_string()
if considered.count(s) == 0
considered.insert(s)
candidates.back_insert(*b);
return false
$ ./gen-game -r1 | ./acheck dp probes = 18. $ ./gen-game -r1 | ./acheck dp probes = 18 $ ./gen-game -r2 | ./acheck dp probes = 1362 $ ./gen-game -r2 | ./acheck dp probes = 3488 $ ./gen-game -r2 | ./acheck dp probes = 4471 $ ./gen-game -r3 | ./acheck dp probes = 4417283
if target.compatible(*b) and (considered.count(s) == 0) considered.insert(s) candidates.push_back(*b)
$ ./gen-game -r2 | ./acheck dp probes = 1362. bp probes = 125. dp/bp time = 5.0 $ ./gen-game -r2 | ./acheck dp probes = 3488. bp probes = 3488. dp/bp time = 4.7 $ ./gen-game -r2 | ./acheck dp probes = 4471. bp probes = 627. dp/bp time = 4.4 $ ./gen-game -r3 | ./acheck dp probes = 4417283. bp probes = 574760. dp/bp time = 5.1
| Tests | C | W | - | + | R | |
|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 1 | 0 | 7 | |
| 2 | 1 | 0 | 0 | 0 | 9 | |
| 3 | 1 | 6 | 0 | 0 | 3 | |
| 4 | 2 | 4 | 1 | 0 | 3 | |
| 5 | 1 | 6 | 1 | 1 | 1 | |
| 6 | 0 | 3 | 1 | 2 | 4 |
| 000 | 100 | 200 | 300 | 500 | 600 | 1300 | |
|---|---|---|---|---|---|---|---|
| 0 | 1 | 1 | 1 | 1 | |||
| 10 | 1 | ||||||
| 20 | |||||||
| 30 | 1 | ||||||
| 40 | 1 | 1 | |||||
| 50 | 1 | ||||||
| 60 | |||||||
| 70 | |||||||
| 80 | 1 | ||||||
| 90 | 1 | ||||||
| Totals | 1 | 1 | 4 | 1 | 1 | 2 | 1 |
| 000 | 100 | 200 | 300 | |
|---|---|---|---|---|
| 0 | 1 | 1 | 1 | 1 |
| 10 | 1 | |||
| 20 | 1 | 1 | ||
| 30 | 1 | |||
| 40 | 1 | |||
| 50 | 1 | |||
| 60 | ||||
| 70 | 1 | |||
| 80 | ||||
| 90 | ||||
| Totals | 2 | 5 | 2 | 2 |
| total | pages per procedure | ||
|---|---|---|---|
| procs | 1 | 2 | 3 |
| 5 | 4 | 1 | |
| 6 | 4 | 2 | |
| 8 | 5 | 3 | |
| 8 | 7 | 1 | |
| 18 | 14 | 4 | |
| 22 | 16 | 4 | 2 |
| 25 | 21 | 4 | |
PLAYING GAME a c ************************ a|c ************************ 2 c ************************ 2|c a|c ************************ 3 c
A better game is : 7dqd2d3d7hah9d8d9cjd9s7c6dtd 3h8h6h3s5hqh asad4d5sksjs qctcthkh9h2c2s7s8skckdac4c5c 4h2h ts6s 6c3cjc8c jh qs4s 5d
void Cards::out()
unsigned i
for i = 0; i < deal.size(); i += 2
cout << deal[i] << deal[i+1] << " "
cout << endl << endl
for i = 0; i < piles.size(); i++
cout << piles[i] << endl
./acheck < ../../t3 String index 107 is out of the range [0..106]. Program received signal SIGABRT, Aborted.
for int i = 0; i <= line.size(); i++
if !isspace(line[i])
// whatever
$ ./acheck < ../../t3 String index 107 is out of the range [0..106]. Program received signal SIGABRT, Aborted.
while getline(cin, s, '\n')
lineno++
if s.size() != 0
if state == INIT
if s.size() != 104
cerr << "Input not valid"
exit (1)
else
if (s.size() % 2 != 0) || (s.size() > 104)
cerr << "Input not valid"
exit (1)
bool
Card::operator == (const Card& c1) const
bool match;
if (this->getSuit() == c1.getSuit()) &&
(this->getRank() == c1.getRank())
match = true;
else
match = false;
return (match);
bool
Card::operator == (const Card& c1) const
return (this->getSuit() == c1.getSuit()) &&
(this->getRank() == c1.getRank())
rank_Set.insert("a");
rank_Set.insert("1");
rank_Set.insert("2");
rank_Set.insert("3");
rank_Set.insert("4");
rank_Set.insert("5");
rank_Set.insert("6");
rank_Set.insert("7");
rank_Set.insert("8");
rank_Set.insert("9");
rank_Set.insert("t");
rank_Set.insert("j");
rank_Set.insert("q");
rank_Set.insert("k");
const char ranks[] = "a123456789tjqk"; std::set<char> rank_set( ranks, ranks + strlen(ranks));
int findidx(string & s) int i=-1, j = -1; switch (s[0]) case 'c' : i = CLUB ; break; case 'd' : i = DIAMOND; break; case 'h' : i = HEART ; break; case 's' : i = SPADE ; break; default : break; switch (s[1]) case 'a' : j=1; break; case 't' : j=10; break; case 'j' : j=11; break; case 'q' : j=12; break; case 'k' : j=13; break; default : j=(s[1] - '0'); assert ( i >= CLUB && i <= SPADE ); assert ( j > 0 && i < 13 ); int idx = i*13+j; return idx;
This page last modified on 5 April 2003.