From 8a8a7c27147968d2d2a23c6a69b81eb913312e6a Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Wed, 22 May 2013 13:49:45 +0300 Subject: [PATCH] Convert the move matching to regexps. --- pysollib/hint.py | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/pysollib/hint.py b/pysollib/hint.py index fa852e52..daa721c8 100644 --- a/pysollib/hint.py +++ b/pysollib/hint.py @@ -913,34 +913,39 @@ class FreeCellSolver_Hint: words = ["Move"] + words - ncards = words[1] - if ncards == 'the': - # "Move the sequence on top of Stack 1 to the foundations" - # (Simple Simon) - ncards = 0 - elif ncards == 'a': - ncards = 1 - else: - ncards = int(ncards) + m = re.match('the sequence on top of Stack (\d+) to the foundations', move_s); - if ncards: - st = stack_types[words[4]] - sn = int(words[5]) + if m: + ncards = 13 + st = stack_types['stack'] + sn = int(m.group(1)) + src = st[sn] + dest = None + else: + m = re.match('(?Pa card|(?P\d+) cards) from (?Pstack|freecell) (?P\d+) to (?Pthe foundations|(?Pfreecell|stack) (?P\d+))\s*', move_s); + + if not m: + continue + + ncards = m.group('ncards') + if ncards == 'a card': + ncards = 1 + else: + ncards = int(m.group('count')) + + st = stack_types[m.group('source_type')] + sn = int(m.group('source_idx')) src = st[sn] # source stack - if words[7] == 'the': + + dest_s = m.group('dest') + if dest_s == 'the foundations': # to foundation dest = None else: # to rows or reserves - dt = stack_types[words[7]] - dn = int(words[8]) + dt = stack_types[m.group('dest_type')] + dn = int(m.group('dest_idx')) dest = dt[dn] - else: # move sequence - ncards = 13 - st = stack_types['stack'] - sn = int(words[7]) - src = st[sn] - dest = None hints.append([ncards, src, dest]) ##print src, dest, ncards