예제 #1
0
def main():
    fcs = FC_Solve()

    # TEST*$test_befs
    fcs.test_befs_weights(
        "Simple - all integers",
        "5,4,3,0,2",
        [5.0, 4.0, 3.0, 0.0, 2.0])

    # TEST*$test_befs
    fcs.test_befs_weights(
        "Simple - fractions",
        "0.2,0.3,0.4,0.5,0.6",
        [0.2, 0.3, 0.4, 0.5, 0.6])

    # TEST*$test_befs
    fcs.test_befs_weights(
        "Testing end after three numbers",
        "0.2,0.35,0.4\x00500\x00600.7\x00",
        [0.2, 0.35, 0.4, 0, 0])

    # TEST*$test_befs
    fcs.test_befs_weights(
        "One number with a trailing comma",
        "100,\x002,3,4,5,6,7,8,9,100\x00",
        [100, 0, 0, 0, 0])
def test_resume_solution():
    testname = "With RunIndef"

    fcs = FC_Solve()

    limit = 10
    fcs.limit_iterations(limit)

    ret = fcs.solve_board(
"""4C 2C 9C 8C QS 4S 2H 
5H QH 3C AC 3H 4H QD 
QC 9S 6H 9H 3S KS 3D 
5D 2S JC 5C JH 6D AS 
2D KD TH TC TD 8D 
7H JS KH TS KC 7C 
AH 5S 6S AD 8H JD 
7S 6C 7D 4D 8S 9D
""")

    iters_count_ok = 1
    
    while (ret == 5):
        if (fcs.get_num_times() != limit):
            iters_count_ok = 0

        limit += 10
        fcs.limit_iterations(limit)
        ret = fcs.resume_solution()
    
    # TEST
    ok (ret == 0, "State was successfully solved.")

    # TEST
    ok (iters_count_ok == 1, "Iters count was OK throughout the solution.")
 def _out_deal(self, deal):
     board_s = self.game.calc_deal_string(deal, self.rend)
     sys.stdout.write(board_s)
     obj = FC_Solve()
     obj.input_cmd_line__generic(['-l', 'lg'])
     obj.limit_iterations(100000)
     if obj.solve_board(board_s) == 0:
         move = obj.get_next_move()
         while move:
             print([ord(move.s[x]) for x in range(4)])
             move = obj.get_next_move()
     # obj.__destroy__()
     obj = None
def test_null_plan():
    fcs = FC_Solve()

    name = "null plan"

    # TEST*$compile_flares_plan_ok
    fcs.compile_flares_plan_ok(name, None)

    # TEST
    fcs.flare_plan_num_items_is(name, 2);

    # TEST*$flare_plan_item_is_run_indef
    fcs.flare_plan_item_is_run_indef(name, 0, 0);

    # TEST*$flare_plan_item_is_checkpoint
    fcs.flare_plan_item_is_checkpoint(name + " No. 1", 1);
예제 #5
0
def test_empty_plan():
    fcs = FC_Solve()

    name = "empty string plan"

    # TEST*$compile_flares_plan_ok
    fcs.compile_flares_plan_ok(name, "")

    # TEST
    fcs.flare_plan_num_items_is(name, 2)

    # TEST*$flare_plan_item_is_run_indef
    fcs.flare_plan_item_is_run_indef(name, 0, 0)

    # TEST*$flare_plan_item_is_checkpoint
    fcs.flare_plan_item_is_checkpoint(name + " No. 1", 1)
예제 #6
0
def test_resume_solution_with_flares():
    testname = "-l ve on iterative limiting - "

    fcs = FC_Solve()

    step = 1000
    hard_limit = 100000
    limit = step
    # TEST*$input_cmd_line
    fcs.input_cmd_line("video-editing", ['-l', 'video-editing'])
    fcs.limit_iterations(limit)

    # MS deal No. 124
    ret = fcs.solve_board(
        """7S AS 2C QS TH QD 7D
5D 8D 9D JH QH 5C JD
6D TD 5H 2S 6S TC KS
TS 4S 3D 9C 3C KD 7C
6H 5S 9H 6C KC AH
AC 4C 8S 2D QC JS
9S KH 8C 4D 7H 4H
2H 3S 8H AD 3H JC
"""
    )

    iters_count_ok = 1

    while (ret == 5 and limit < hard_limit):
        if (fcs.get_num_times() != limit):
            iters_count_ok = 0

        limit += step
        fcs.limit_iterations(limit)
        ret = fcs.resume_solution()

    # TEST
    ok(ret == 0, testname + "State was successfully solved.")

    # TEST
    ok(iters_count_ok == 1,
       testname + "Iters count was OK throughout the solution.")
def test_num_states_in_collection_after_unsolved():
    testname = "NumStatesInCol-After-unsolved"

    fcs = FC_Solve()

    # TEST*$input_cmd_line
    fcs.input_cmd_line("bakers_game", ['-g', 'bakers_game']);

    # MS-Freeceel board No. 10
    ret = fcs.solve_board(
"""5S KD JC TS 9D KH 8D 
5H 2S 9H 7H TD AD 6D 
6H QD 6C TC AH 8S TH 
6S 2D 7C QC QS 7D 3H 
5D AS 7S KC 3D AC 
4D 9C QH 4H 4C 5C 
2H 3S 8H 9S JS 4S 
JH JD 3C KS 2C 8C 
""")

    # TEST
    ok (fcs.get_num_times() == 3436, "Get num times is OK.");

    # TEST
    ok (fcs.get_num_states_in_col() == 3436, "Num-states-in-collection is OK.");
예제 #8
0
def test_2():
    testname = "test_1"

    fcs = FC_Solve()

    # TEST*$input_cmd_line
    fcs.input_cmd_line(
        "dto 1",
        ["-to", "0123456789", "-dto", "1,0132456789", "-dto", "50,056234"]
    )

    # TEST
    fcs.num_by_depth_tests_order_is(testname, 3)

    # TEST
    fcs.by_depth_max_depth_of_depth_idx_is(testname, 0, 1)

    # TEST
    fcs.by_depth_max_depth_of_depth_idx_is(testname, 1, 50)
예제 #9
0
def test_num_states_in_collection_after_unsolved():
    testname = "NumStatesInCol-After-unsolved - "

    tags_str = os.getenv('FCS_TEST_TAGS')
    if not tags_str:
        tags_str = ''

    if re.search(r'\bfc_only\b', tags_str):
        for idx in range(0, 3):
            ok(True, 'skipping because not-freecell test on a freecell build',
               skip='fc_only')
        return

    fcs = FC_Solve()

    # TEST*$input_cmd_line
    fcs.input_cmd_line("bakers_game", ['-g', 'bakers_game'])

    # MS-Freeceel board No. 10
    fcs.solve_board(
            """5S KD JC TS 9D KH 8D
5H 2S 9H 7H TD AD 6D
6H QD 6C TC AH 8S TH
6S 2D 7C QC QS 7D 3H
5D AS 7S KC 3D AC
4D 9C QH 4H 4C 5C
2H 3S 8H 9S JS 4S
JH JD 3C KS 2C 8C
"""
    )

    # TEST
    ok(fcs.get_num_times() == 3436, testname + "Get num times is OK.")

    # TEST
    ok(fcs.get_num_states_in_col() == 3436,
       testname + "Num-states-in-collection is OK.")

    return
예제 #10
0
 def run(self):
     """docstring for run"""
     idxs = self.idxs
     obj = FC_Solve()
     obj.input_cmd_line(['-l', 'lg'])
     obj.limit_iterations(100000)
     self.obj = obj
     while len(idxs):
         i = idxs.pop(0)
         if i == 'seq':
             start = int(idxs.pop(0))
             end = int(idxs.pop(0))
             for deal in range(start, end + 1):
                 self._out_deal(deal)
         elif i == 'slurp':
             for line in open(idxs.pop(0), 'rt'):
                 self._out_deal(int(line))
         else:
             self._out_deal(int(i))
     return 0
def test_num_states_in_collection_after_recycle():
    testname = "NumStatesInCol-After-Recycle"

    fcs = FC_Solve()

    # MS-Freeceel board No. 24.
    ret = fcs.solve_board(
"""4C 2C 9C 8C QS 4S 2H 
5H QH 3C AC 3H 4H QD 
QC 9S 6H 9H 3S KS 3D 
5D 2S JC 5C JH 6D AS 
2D KD TH TC TD 8D 
7H JS KH TS KC 7C 
AH 5S 6S AD 8H JD 
7S 6C 7D 4D 8S 9D
""")

    # TEST
    ok (fcs.get_num_times() == 137, "Get num times is OK.");

    # TEST
    ok (fcs.get_num_states_in_col() == 191, "Num-states-in-collection is OK.");

    fcs.recycle();

    # TEST
    ok (fcs.get_num_times() == 0, "Get num times immediately after recycle.");

    # TEST
    ok (fcs.get_num_states_in_col() == 0, "Num-states-in-collection immediately after recycle.");

    # MS-Freeceel board No. 24.
    ret = fcs.solve_board(
"""4C 2C 9C 8C QS 4S 2H 
5H QH 3C AC 3H 4H QD 
QC 9S 6H 9H 3S KS 3D 
5D 2S JC 5C JH 6D AS 
2D KD TH TC TD 8D 
7H JS KH TS KC 7C 
AH 5S 6S AD 8H JD 
7S 6C 7D 4D 8S 9D
""")

    # TEST
    ok (fcs.get_num_times() == 137, "Get num times after recycle.");

    # TEST
    ok (fcs.get_num_states_in_col() == 191, "Num-states-in-collection after recycle.");
def test_with_checkpoints():
    testname = "With checkpoints"

    fcs = FC_Solve()

    # TEST*$input_cmd_line
    fcs.input_cmd_line("Input Flares",
        ["--flare-name", "dfs", "-nf",
         "--flare-name", "befs", "--method", "a-star", "-nf",
         "--flare-name", "foo", "--method", "a-star",
            "-asw", "0.2,0.3,0.5,0,0", "-nf",
         "--flare-name", "bar", "-to", "[01][23467]",
         ])

    # TEST*$compile_flares_plan_ok
    fcs.compile_flares_plan_ok(testname, "Run:500@dfs,Run:300@bar,CP:,Run:1000@befs")

    # 4 items and then the implicit checkpoint.
    # TEST
    fcs.flare_plan_num_items_is(testname, 5);

    # TEST*$flare_plan_item_is_run
    fcs.flare_plan_item_is_run(("%s No. 0" % (testname)), 0, 0, 500);

    # TEST*$flare_plan_item_is_run
    fcs.flare_plan_item_is_run(("%s No. 1" % (testname)), 1, 3, 300);

    # TEST*$flare_plan_item_is_checkpoint
    fcs.flare_plan_item_is_checkpoint(("%s No. 2" % (testname)), 2);

    # TEST*$flare_plan_item_is_run
    fcs.flare_plan_item_is_run(("%s No. 3" % (testname)), 3, 1, 1000);

    # TEST*$flare_plan_item_is_checkpoint
    fcs.flare_plan_item_is_checkpoint(("%s No. 4" % (testname)), 4);
def test_two_runs():
    # Create a fresh instance
    fcs = FC_Solve()

    name = "Two Run's"
    # TEST*$input_cmd_line
    fcs.input_cmd_line("Input Flares",
        ["--flare-name", "dfs", "-nf",
         "--flare-name", "befs", "--method", "a-star"])

    # TEST*$compile_flares_plan_ok
    fcs.compile_flares_plan_ok(name, "Run:500@befs,Run:1500@dfs")

    # 2 runs and then the implicit checkpoint.
    # TEST
    fcs.flare_plan_num_items_is(name, 3);

    # TEST*$flare_plan_item_is_run
    fcs.flare_plan_item_is_run(name + " No. 0", 0, 1, 500);

    # TEST*$flare_plan_item_is_run
    fcs.flare_plan_item_is_run(name + " No. 1", 1, 0, 1500);

    # TEST*$flare_plan_item_is_checkpoint
    fcs.flare_plan_item_is_checkpoint(name + " No. 2", 2);
예제 #14
0
def test_with_run_indef():
    testname = "With RunIndef"

    fcs = FC_Solve()

    # TEST*$input_cmd_line
    fcs.input_cmd_line(
        "Input Flares",
        ["--flare-name", "dfs", "-nf",
         "--flare-name", "befs", "--method", "a-star", "-nf",
         "--flare-name", "foo", "--method", "a-star",
            "-asw", "0.2,0.3,0.5,0,0", "-nf",
         "--flare-name", "bar", "-to", "[01][23467]",
         ])

    # TEST*$compile_flares_plan_ok
    fcs.compile_flares_plan_ok(
        testname,
        "Run:500@dfs,Run:300@bar,CP:,RunIndef:befs"
    )

    # 5 items (with an extra implicit chechpoint at the end).
    # TEST
    fcs.flare_plan_num_items_is(testname, 5)

    # TEST*$flare_plan_item_is_run
    fcs.flare_plan_item_is_run(("%s No. 0" % (testname)), 0, 0, 500)

    # TEST*$flare_plan_item_is_run
    fcs.flare_plan_item_is_run(("%s No. 1" % (testname)), 1, 3, 300)

    # TEST*$flare_plan_item_is_checkpoint
    fcs.flare_plan_item_is_checkpoint(("%s No. 2" % (testname)), 2)

    # TEST*$flare_plan_item_is_run_indef
    fcs.flare_plan_item_is_run_indef(("%s No. 3" % (testname)), 3, 1)

    # TEST*$flare_plan_item_is_checkpoint
    fcs.flare_plan_item_is_checkpoint(("%s No. 4" % (testname)), 4)
예제 #15
0
def test_with_checkpoints_and_explicit_checkpoint():
    testname = "With checkpoints with explicit checkpoint at end."

    fcs = FC_Solve()

    # TEST*$input_cmd_line
    fcs.input_cmd_line(
        "Input Flares",
        ["--flare-name", "dfs", "-nf",
         "--flare-name", "befs", "--method", "a-star", "-nf",
         "--flare-name", "foo", "--method", "a-star",
            "-asw", "0.2,0.3,0.5,0,0", "-nf",
         "--flare-name", "bar", "-to", "[01][23467]",
         ])

    # TEST*$compile_flares_plan_ok
    fcs.compile_flares_plan_ok(
        testname,
        "Run:500@dfs,Run:300@bar,CP:,Run:1000@befs,CP:"
    )

    # 5 items (without an extra and redundant explicit checkpoint at the end.)
    # TEST
    fcs.flare_plan_num_items_is(testname, 5)

    # TEST*$flare_plan_item_is_run
    fcs.flare_plan_item_is_run(("%s No. 0" % (testname)), 0, 0, 500)

    # TEST*$flare_plan_item_is_run
    fcs.flare_plan_item_is_run(("%s No. 1" % (testname)), 1, 3, 300)

    # TEST*$flare_plan_item_is_checkpoint
    fcs.flare_plan_item_is_checkpoint(("%s No. 2" % (testname)), 2)

    # TEST*$flare_plan_item_is_run
    fcs.flare_plan_item_is_run(("%s No. 3" % (testname)), 3, 1, 1000)

    # TEST*$flare_plan_item_is_checkpoint
    fcs.flare_plan_item_is_checkpoint(("%s No. 4" % (testname)), 4)