[Toss-devel-svn] SF.net SVN: toss:[1408] trunk/Toss/Play/PlayTest.ml
Status: Beta
Brought to you by:
lukaszkaiser
From: <luk...@us...> - 2011-04-13 17:14:28
|
Revision: 1408 http://toss.svn.sourceforge.net/toss/?rev=1408&view=rev Author: lukaszkaiser Date: 2011-04-13 17:14:22 +0000 (Wed, 13 Apr 2011) Log Message: ----------- Adding and ordering Play tests. Modified Paths: -------------- trunk/Toss/Play/PlayTest.ml Modified: trunk/Toss/Play/PlayTest.ml =================================================================== --- trunk/Toss/Play/PlayTest.ml 2011-04-13 14:42:37 UTC (rev 1407) +++ trunk/Toss/Play/PlayTest.ml 2011-04-13 17:14:22 UTC (rev 1408) @@ -25,16 +25,34 @@ let test_maximax ?(debug=0) ?(advr=4.) ?(struc="") ?(time=0.) ?(loc=0) - ~iters gname move_s = + ~iters gname ?(msg="") ?(nomove=false) check_fun = let (g, s) = state_of_file ("./examples/"^gname^".toss") ~struc ~time ~loc in GameTree.set_debug_level debug; Play.set_debug_level debug; let h = Heuristic.default_heuristic ~struc:s.Arena.struc ~advr g in - let (m, ns) = Play.maximax_unfold_choose iters g s h in - assert_equal ~printer:(fun x -> x) move_s (Move.move_gs_str_short s m) + try + let (m, ns) = Play.maximax_unfold_choose iters g s h in + let move_str = Move.move_gs_str_short s m in + assert_bool + (Printf.sprintf "%s: Failed move: %s." msg move_str) (check_fun move_str) + with Not_found -> + if nomove then assert_bool "No Move: Test Passed" true else + assert_bool "No Move: Test Failed!" false +let test_algo algo ?(debug=0) ?(advr=4.) ?(struc="") ?(time=0.) ?(loc=0) + ~iters gname ?(msg="") ?(nomove=false) check_fun = + if algo = "Maximax" then + test_maximax ~debug ~advr ~struc ~time ~loc ~iters gname ~nomove check_fun + else failwith "Unsupported play algorithm" -let basic_tests = "Play" >::: [ + + + + +(* ----------------- NORMAL TESTS ------------- *) + +let basic_tests = "Basic" >::: [ + "maximax unfold once, node_info" >:: (fun () -> let (g, s) = state_of_file "./examples/Tic-Tac-Toe.toss" in @@ -59,9 +77,23 @@ assert_equal ~printer:(fun x -> string_of_int x) 250 (GameTree.size u1); ); - "maximax suggest move: Tic-Tac-Toe defense" >:: + "checkers suggest first move 5 iters" >:: (fun () -> - let struc = "MODEL [ | P:1 {}; Q:1 {} | ] \" + test_maximax "Checkers" ~debug:0 ~iters:5 + ~msg:"make any first move in checkers after 5 iters" (fun s -> true) + ); +] + + +let tictactoe_tests algo iters = + let test_do ?(struc="") ?(time=0.) ?(loc=0) ?(msg="") check_f = + test_algo algo ~debug:0 ~advr:5. ~struc ~time ~loc ~iters + "Tic-Tac-Toe" ~msg check_f in + ("Tic-Tac-Toe (" ^ algo ^ " " ^ (string_of_int iters) ^ ")") >::: [ + + "basic defense" >:: + (fun () -> + let struc = "MODEL [ | P:1 {}; Q:1 {} | ] \" . . . @@ -69,207 +101,105 @@ . P Q \"" in - test_maximax "Tic-Tac-Toe" ~struc ~loc:1 ~iters:9 "Circle{1:b3}"; - ); -] + test_do ~struc ~loc:1 (fun s -> s = "Circle{1:b3}") + ); - -let gomoku_tests_big = "Gomoku" >::: [ - "maximax suggest defense 1" >:: - (fun () -> - let struc = "MODEL [ | P:1 {}; Q:1 {} | ] \" - ... ... ... ... - ... ... ... ... - ... ... ... ... - ... ...P ... ... - ... ... ... ... - ... P.. ... ... - ... ... ... ... - ... Q..P P..P ... - ... ... ... ... - Q ... P..Q ... ... - ... ... ... ... - ... Q..Q ... ... - ... ... ... ... - ... ... ... ... - ... ... ... ... - ... ... ... ... -\" with DiagA (x, y) = ex u (R(x, u) and C(u, y)); - DiagB (x, y) = ex u (R(x, u) and C(y, u))" in - test_maximax "Gomoku" ~debug:0 ~struc ~loc:1 ~iters:160 "Circle{1:d8}"; - ); - - "maximax suggest defense 2" >:: - (fun () -> - let struc = "MODEL [ | P:1 {}; Q:1 {} | ] \" - ... ... ... ... - P.. ... ... ... - ... ... ... ... - ...P ...Q ...P ... - ... ... ... ... - Q..P Q..Q Q..P Q.. - ... ... ... ... - P.. P..Q Q..Q Q..P - ... ... ... ... - P..Q P..P Q.. ... - ... ... ... ... - ...Q P..Q Q.. P..P - ... ... ... ... - P ... P..Q ... P.. - ... ... ... ... - ... ... ... ... -\" with DiagA (x, y) = ex u (R(x, u) and C(u, y)); - DiagB (x, y) = ex u (R(x, u) and C(y, u))" in - test_maximax "Gomoku" ~debug:0 ~struc ~loc:1 ~iters:180 "Circle{1:e1}"; - ); - - "maximax suggest defense 3" >:: - (fun () -> - let struc = "MODEL [ | P:1 {}; Q:1 {} | ] \" - ... ... ... ... - ... ... ... ... - ... ... ... ... - ... ...P ... ... - ... ... ... ... - ... Q..Q ... ... - ... ... ... ... - ... P..P Q..P ... - ... ... ... ... - ... P..Q ... ... - ... ... ... ... - ... ...Q P.. ... - ... ... ... ... - ... ... ... ... - ... ... ... ... - ... ... ... ... -\" with DiagA (x, y) = ex u (R(x, u) and C(u, y)); - DiagB (x, y) = ex u (R(x, u) and C(y, u))" in - test_maximax "Gomoku" ~debug:0 ~struc ~loc:1 ~iters:210 "Circle{1:b6}"; - ); -] - -let bigtests = "PlayBig" >::: [ - gomoku_tests_big; -] - -(* ------------------------------------------ *) - - -let search_tests algo comment effort_easy time_easy effort_medium - time_medium effort_hard time_hard = - let update_game gname struc loc = - state_of_file ("./examples/"^gname^".toss") ~struc ~time:0. ~loc in - let compute_try search_method effort timer_sec (advr, state) msg pred = - if search_method = "GameTree" then - let heur = Heuristic.default_heuristic - ~struc:(snd state).Arena.struc - ~advr (fst state) in - Play.set_timeout (float(timer_sec)); - let (move, _) = Play.maximax_unfold_choose effort - (fst state) (snd state) heur in - Play.cancel_timeout (); - let move_str = Move.move_gs_str_short (snd state) move in - assert_bool - (Printf.sprintf "%s: Failed move: %s." msg move_str) (pred move_str) - else failwith "other method unsupported for now" in - let easy_case = compute_try algo effort_easy time_easy - and easy_big_case = compute_try algo effort_easy time_medium - and medium_case = compute_try algo effort_medium time_medium - and hard_small_case = compute_try algo effort_hard time_medium - and hard_case = compute_try algo effort_hard time_hard in - (algo ^ "-" ^ comment) >::: [ - - "tictactoe suggest tie" >:: (fun () -> - let state = update_game "Tic-Tac-Toe" -"MODEL [ | P:1 { }; Q:1 { } | ] \" + "basic tie" >:: + (fun () -> + let struc = "MODEL [ | P:1 { }; Q:1 { } | ] \" Q P P . P . . Q . -\"" 1 in - (* TODO: replace with easy_case after monotonic heur done *) - easy_case (5.0, state) "Q should block for tie" - (fun mov_s -> "Circle{1:a1}" = mov_s)); +\"" in + test_do ~struc ~loc:1 ~msg:"Q should block for tie" + (fun s -> s = "Circle{1:a1}") + ); - "tictactoe suggest optimal single" >:: - (fun () -> - let state = update_game "Tic-Tac-Toe" -"MODEL [ | P:1 { }; Q:1 { } | ] \" + "suggest optimal single" >:: + (fun () -> + let struc = "MODEL [ | P:1 { }; Q:1 { } | ] \" . . . . . . . . P -\"" 1 in - easy_case (5.0, state) "Q play the middle for tie" - (fun mov_s -> "Circle{1:b2}" = mov_s)); +\"" in + test_do ~struc ~loc:1 ~msg:"Q play the middle for tie" + (fun s -> s = "Circle{1:b2}") + ); - "tictactoe suggest optimal multi" >:: - (fun () -> - let state = update_game "Tic-Tac-Toe" -"MODEL [ | P:1 { }; Q:1 { } | ] \" + "suggest optimal multi" >:: + (fun () -> + let struc = "MODEL [ | P:1 { }; Q:1 { } | ] \" . . . . P . . . . -\"" 1 in - easy_case (5.0, state) ("Q should play the corner for tie"^ - " (heuristic still ignores monotonicity?)") - (fun mov_s -> List.mem mov_s - ["Circle{1:a1}"; "Circle{1:a3}"; "Circle{1:c1}"; "Circle{1:c3}"])); +\"" in + test_do ~struc ~loc:1 ~msg:("Q should play the corner for tie " ^ + " (heuristic not monotone?)") + (fun s -> List.mem s + ["Circle{1:a1}"; "Circle{1:a3}"; "Circle{1:c1}"; "Circle{1:c3}"]) + ); - "tictactoe suggest avoid endgame diagonal" >:: - (fun () -> - let state = update_game "Tic-Tac-Toe" -"MODEL [ | P:1 { }; Q:1 { } | ] \" + "avoid endgame diagonal" >:: + (fun () -> + let struc = "MODEL [ | P:1 { }; Q:1 { } | ] \" Q . P . P . . . . -\"" 1 in - easy_case (5.0, state) "Q should block diagonal" - (fun mov_s -> "Circle{1:a1}" = mov_s)); +\"" in + test_do ~struc ~loc:1 ~msg:"Q should block diagonal" + (fun s -> s = "Circle{1:a1}") + ); - "tictactoe suggest avoid endgame straight" >:: - (fun () -> - let state = update_game "Tic-Tac-Toe" -"MODEL [ | P:1 { }; Q:1 { } | ] \" + "avoid endgame straight" >:: + (fun () -> + let struc = "MODEL [ | P:1 { }; Q:1 { } | ] \" . P Q . P . . . . -\"" 1 in - easy_case (5.0, state) "Q should block straight" - (fun mov_s -> "Circle{1:b1}" = mov_s); - ); +\"" in + test_do ~struc ~loc:1 ~msg:"Q should block straight" + (fun s -> s = "Circle{1:b1}"); + ); - "tictactoe suggest win" >:: - (fun () -> - let state = update_game "Tic-Tac-Toe" -"MODEL [ | P:1 { }; Q:1 { } | ] \" + "basic win" >:: + (fun () -> + let struc = "MODEL [ | P:1 { }; Q:1 { } | ] \" P . . . P P Q . Q -\"" 1 in - easy_case (5.0, state) "Q should win" - (fun mov_s -> "Circle{1:b1}" = mov_s)); +\"" in + test_do ~struc ~loc:1 ~msg:"Q should win" + (fun s -> s = "Circle{1:b1}") + ); + ] - "breakthrough suggest avoid endgame" >:: - (fun () -> - let state = update_game "Breakthrough" -"MODEL [ | | ] \" +let breakthrough_tests algo iters = + let test_do ?(struc="") ?(time=0.) ?(loc=0) ?(msg="") check_f = + test_algo algo ~debug:0 ~advr:2. ~struc ~time ~loc ~iters + "Breakthrough" ~msg check_f in + ("Breakthrough (" ^ algo ^ " " ^ (string_of_int iters) ^ ")") >::: [ + + "avoid endgame" >:: + (fun () -> + let struc = "MODEL [ | | ] \" ... ... ... ... B B..B B..B B..B B.. ... ... ... ... @@ -286,17 +216,17 @@ ... W..W ...W W.. ... ... ... ... W..W ...W W..W W..W -\"" 0 in - easy_case (2.0, state) "W shouldn't move from b1" - (fun mov_s -> - not (List.mem mov_s - ["WhiteStraight{1:b1, 2:b2}"; - "WhiteDiag{1:b1, 2:a2}"; "WhiteDiag{1:b1, 2:c2}"]))); +\"" in + test_do ~struc ~loc:0 ~msg:"W shouldn't move from b1" + (fun mov_s -> + not (List.mem mov_s + ["WhiteStraight{1:b1, 2:b2}"; + "WhiteDiag{1:b1, 2:a2}"; "WhiteDiag{1:b1, 2:c2}"])) + ); - "breakthrough suggest endgame" >:: - (fun () -> - let state = update_game "Breakthrough" -"MODEL [ | | ] \" + "endgame attack" >:: + (fun () -> + let struc = "MODEL [ | | ] \" ... ... ... ... B B..B B..B B..B B.. ... ... ... ... @@ -313,14 +243,13 @@ W.. W..W ...W W.. ... ... ... ... W.. ...W W..W W..W -\"" 1 in - easy_case (2.0, state) "B should attack left" - (fun mov_s -> "BlackDiag{1:b3, 2:a2}" = mov_s)); +\"" in + test_do ~struc ~loc:1 ~msg:"B should attack left" + (fun mov_s -> "BlackDiag{1:b3, 2:a2}" = mov_s)); - "breakthrough suggest midgame" >:: - (fun () -> - let state = update_game "Breakthrough" -"MODEL [ | | ] \" + "midgame capture" >:: + (fun () -> + let struc = "MODEL [ | | ] \" ... ... ... ... B..B B.. B..B ... ... ... ... ... @@ -337,14 +266,13 @@ ... ... ... ... ... ... ... ... W..W ...W ...W W..W -\"" 0 in - easy_case (2.0, state) "W should beat the lower B" (* or medium *) - (fun mov_s -> "WhiteDiag{1:e3, 2:f4}" = mov_s)); +\"" in + test_do ~struc ~loc:0 ~msg:"W should beat the lower B" + (fun mov_s -> "WhiteDiag{1:e3, 2:f4}" = mov_s)); - "breakthrough suggest adv_ratio" >:: - (fun () -> - let state = update_game "Breakthrough" -"MODEL [ | | ] \" + "too big adv_ratio" >:: + (fun () -> + let struc = "MODEL [ | | ] \" ... ... ... ... B B..B B..B B..B B.. ... ... ... ... @@ -361,16 +289,15 @@ W W.. W..W W.. W.. ... ... ... ... W..W W..W W..W W..W -\"" 0 in - easy_case (2.0, state) "W should play cool" - (fun mov_s -> - mov_s <> "WhiteDiag{1:e4, 2:f5}" - && mov_s <> "WhiteDiag{1:e4, 2:d5}")); +\"" in + test_do ~struc ~loc:0 ~msg:"W should play cool" + (fun mov_s -> + mov_s <> "WhiteDiag{1:e4, 2:f5}" + && mov_s <> "WhiteDiag{1:e4, 2:d5}")); - "breakthrough suggest depth" >:: - (fun () -> - let state = update_game "Breakthrough" -"MODEL [ | | ] \" + "preserve piece" >:: + (fun () -> + let struc = "MODEL [ | | ] \" ... ... ... ... B ...B ...B B..B B.. ... ... ... ... @@ -387,18 +314,25 @@ ... ... W..W W.. ... ... ... ... W..W W..W W..W W..W -\"" 0 in - medium_case (2.0, state) "W should not lose the piece" - (fun mov_s -> - mov_s <> "WhiteDiag{1:d5, 2:e6}" - && mov_s <> "WhiteDiag{1:d5, 2:c6}" - && mov_s <> "WhiteStraight{1:d5, 2:d6}")); +\"" in + test_do ~struc ~loc:0 ~msg:"W should not lose the piece" + (fun mov_s -> + mov_s <> "WhiteDiag{1:d5, 2:e6}" + && mov_s <> "WhiteDiag{1:d5, 2:c6}" + && mov_s <> "WhiteStraight{1:d5, 2:d6}") + ); + ] - "gomoku8x8 avoid endgame" >:: - (fun () -> - let state = update_game "Gomoku" -"MODEL [ | | ] \" +let gomoku8x8_tests algo iters = + let test_do ?(struc="") ?(time=0.) ?(loc=0) ?(msg="") check_f = + test_algo algo ~debug:0 ~advr:5. ~struc ~time ~loc ~iters + "Gomoku" ~msg check_f in + ("Gomoku8x8 (" ^ algo ^ " " ^ (string_of_int iters) ^ ")") >::: [ + + "avoid endgame 1" >:: + (fun () -> + let struc = "MODEL [ | | ] \" ... ... ... ... ... ... ... ... ... ... ... ... @@ -416,12 +350,14 @@ ... ... ... ... ... ... ... ... \" with DiagA (x, y) = ex u (R(x, u) and C(u, y)) ; - DiagB (x, y) = ex u (R(x, u) and C(y, u))" 0 in - easy_big_case (5.0, state) "P should block" - (fun mov_s -> "Cross{1:b5}" = mov_s); + DiagB (x, y) = ex u (R(x, u) and C(y, u))" in + test_do ~struc ~loc:0 ~msg:"P should block" + (fun mov_s -> "Cross{1:b5}" = mov_s) + ); - let state = update_game "Gomoku" -"MODEL [ | | ] \" + "avoid endgame 2" >:: + (fun () -> + let struc = "MODEL [ | | ] \" ... ... ... ... ... ... ... ... ... ... ... ... @@ -439,17 +375,15 @@ ... ... ... ... ... ... ... ... \" with DiagA (x, y) = ex u (R(x, u) and C(u, y)) ; - DiagB (x, y) = ex u (R(x, u) and C(y, u))" 0 in - easy_big_case (5.0, state) "P should block with line" - (fun mov_s -> "Cross{1:f7}" = mov_s); + DiagB (x, y) = ex u (R(x, u) and C(y, u))" in + test_do ~struc ~loc:0 ~msg:"P should block with line" + (fun mov_s -> "Cross{1:f7}" = mov_s); + ); -); - - "gomoku8x8 block gameover" >:: - (fun () -> - let state = update_game "Gomoku" -"MODEL [ | | ] \" + "block gameover" >:: + (fun () -> + let struc = "MODEL [ | | ] \" ... ... ... ... ... ... ... ... ... ... ... ... @@ -467,17 +401,15 @@ ... ... ... ... ... ... ... ... \" with DiagA (x, y) = ex u (R(x, u) and C(u, y)) ; - DiagB (x, y) = ex u (R(x, u) and C(y, u))" 0 in - easy_big_case (5.0, state) "P should block" - (fun mov_s -> "Cross{1:a3}" = mov_s); + DiagB (x, y) = ex u (R(x, u) and C(y, u))" in + test_do ~struc ~loc:0 ~msg:"P should block" + (fun mov_s -> "Cross{1:a3}" = mov_s); + ); -); - - "gomoku8x8 more pieces" >:: - (fun () -> - let state = update_game "Gomoku" -"MODEL [ | | ] \" + "more pieces" >:: + (fun () -> + let struc = "MODEL [ | | ] \" ... ... ... ... P ... ... ... ... ... ... ... ... @@ -495,15 +427,14 @@ ... ... ... ... ... ... ...Q ... \" with DiagA (x, y) = ex u (R(x, u) and C(u, y)) ; - DiagB (x, y) = ex u (R(x, u) and C(y, u))" 0 in - easy_big_case (5.0, state) "should block the open line" - (fun mov_s -> "Cross{1:e7}" = mov_s); -); + DiagB (x, y) = ex u (R(x, u) and C(y, u))" in + test_do ~struc ~loc:0 ~msg:"P should block the open line" + (fun mov_s -> "Cross{1:e7}" = mov_s); + ); - "gomoku8x8 attack" >:: - (fun () -> - let state = update_game "Gomoku" -"MODEL [ | | ] \" + "attack" >:: + (fun () -> + let struc = "MODEL [ | | ] \" ... ... ... ... ... ... ... ... ... ... ... ... @@ -521,15 +452,22 @@ ... ... ... ... ... ... Q.. ... \" with DiagA (x, y) = ex u (R(x, u) and C(u, y)) ; - DiagB (x, y) = ex u (R(x, u) and C(y, u))" 0 in - easy_big_case (5.0, state) "should attack the diagonal" - (fun mov_s -> "Cross{1:d4}" = mov_s); -); + DiagB (x, y) = ex u (R(x, u) and C(y, u))" in + test_do ~struc ~loc:0 ~msg:"P should attack the diagonal" + (fun mov_s -> "Cross{1:d4}" = mov_s); + ); + ] - "connect4 simple" >:: - (fun () -> - let state = update_game "Connect4" -"MODEL [ | | ] \" + +let connect4_tests algo iters = + let test_do ?(struc="") ?(time=0.) ?(loc=0) ?(msg="") check_f = + test_algo algo ~debug:0 ~advr:5. ~struc ~time ~loc ~iters + "Connect4" ~msg check_f in + ("Connect4 (" ^ algo ^ " " ^ (string_of_int iters) ^ ")") >::: [ + + "simple attack" >:: + (fun () -> + let struc = "MODEL [ | | ] \" . . . . . . . @@ -543,15 +481,14 @@ P Q Q +Q . . . \" with DiagA (x, y) = ex u (R(x, u) and C(u, y)) ; - DiagB (x, y) = ex u (R(x, u) and C(y, u))" 0 in - easy_case (2.0, state) "should attack" - (fun mov_s -> "Cross{1:a4}" = mov_s); -); + DiagB (x, y) = ex u (R(x, u) and C(y, u))" in + test_do ~struc ~loc:0 ~msg:"P should attack" + (fun mov_s -> "Cross{1:a4}" = mov_s); + ); - "connect4 avoid losing" >:: - (fun () -> - let state = update_game "Connect4" -"MODEL [ | | ] \" + "avoid losing" >:: + (fun () -> + let struc = "MODEL [ | | ] \" ... ... ... ... ... ... ... ... ... ... @@ -565,16 +502,14 @@ ... ... ... ... ... Q..P P..P Q.. \" with DiagA (x, y) = ex u (R(x, u) and C(u, y)) ; - DiagB (x, y) = ex u (R(x, u) and C(y, u))" 0 in - hard_small_case (2.0, state) "should not attack" - (fun mov_s -> "Cross{1:f3}" <> mov_s); -); + DiagB (x, y) = ex u (R(x, u) and C(y, u))" in + test_do ~struc ~loc:0 ~msg:"P should not attack" + (fun mov_s -> "Cross{1:f3}" <> mov_s); + ); - - "connect4 endgame" >:: - (fun () -> - let state = update_game "Connect4" -"MODEL [ | | ] \" + "endgame" >:: + (fun () -> + let struc = "MODEL [ | | ] \" . . . . . . . @@ -588,20 +523,153 @@ P P P Q Q . . \" with DiagA (x, y) = ex u (R(x, u) and C(u, y)) ; - DiagB (x, y) = ex u (R(x, u) and C(y, u))" 0 in - hard_case (2.0, state) "should defend" - (fun mov_s -> "Cross{1:e2}" = mov_s); -); + DiagB (x, y) = ex u (R(x, u) and C(y, u))" in + test_do ~struc ~loc:0 ~msg:"P should defend" + (fun mov_s -> "Cross{1:e2}" = mov_s); + ); + ] +let tests = "Play" >::: [ + basic_tests; + tictactoe_tests "Maximax" 3; + breakthrough_tests "Maximax" 5; + gomoku8x8_tests "Maximax" 4; + connect4_tests "Maximax" 7; ] -let tests = "Play" >::: [ - basic_tests; - search_tests "GameTree" "iters 75 230 300" 75 120 230 240 300 360; + +(* ----------------- BIG TESTS ------------- *) + +let chess_tests_big = "ChessBig" >::: [ + + "random first move" >:: + (fun () -> + test_maximax "Chess" ~debug:0 ~iters:0 + ~msg:"make any first move in chess" (fun s -> true) + ); + + "first move 1 iter" >:: + (fun () -> + test_maximax "Chess" ~debug:0 ~iters:1 + ~msg:"make a selected first move in chess" (fun s -> true) + ); + + "detect draw" >:: + (fun () -> + let struc = +"MODEL [ | bB:1 {}; wB:1 {}; wN:1 {}; wP:1 {}; wQ:1 {}; wR:1 {} | ] \" + ... ... ... ... + ... ... +bN ... + ... ... ... ... + ... ... ... ... + ... ... ... ... + ... bP. ...-bNwK. + ... ... ... ... + ...bP ... ... ... + ... ... ... ... + bR. ... ...bQ ... + ... ... ... ... + ... ...bK ... ...bP + ... ... ... ... + ... ... ... ... + ... ... ... ... + ... ... ... ... +\" with +D1(x, y) = ex z ( (R(x, z) and C(z, y)) or (R(y, z) and C(z, x)) ) ; +D2(x, y) = ex z ( (R(x, z) and C(y, z)) or (R(y, z) and C(x, z)) )" in + test_maximax "Chess" ~debug:0 ~iters:1 ~struc + ~msg:"detect draw in chess" ~nomove:true (fun _ -> false) + ); ] +let gomoku_tests_big = "GomokuBig" >::: [ + "maximax suggest defense 1" >:: + (fun () -> + let struc = "MODEL [ | P:1 {}; Q:1 {} | ] \" + ... ... ... ... + ... ... ... ... + ... ... ... ... + ... ...P ... ... + ... ... ... ... + ... P.. ... ... + ... ... ... ... + ... Q..P P..P ... + ... ... ... ... + Q ... P..Q ... ... + ... ... ... ... + ... Q..Q ... ... + ... ... ... ... + ... ... ... ... + ... ... ... ... + ... ... ... ... +\" with DiagA (x, y) = ex u (R(x, u) and C(u, y)); + DiagB (x, y) = ex u (R(x, u) and C(y, u))" in + test_maximax "Gomoku" ~debug:0 ~struc ~loc:1 ~iters:160 + (fun s -> s = "Circle{1:d8}"); + ); + + "maximax suggest defense 2" >:: + (fun () -> + let struc = "MODEL [ | P:1 {}; Q:1 {} | ] \" + ... ... ... ... + P.. ... ... ... + ... ... ... ... + ...P ...Q ...P ... + ... ... ... ... + Q..P Q..Q Q..P Q.. + ... ... ... ... + P.. P..Q Q..Q Q..P + ... ... ... ... + P..Q P..P Q.. ... + ... ... ... ... + ...Q P..Q Q.. P..P + ... ... ... ... + P ... P..Q ... P.. + ... ... ... ... + ... ... ... ... +\" with DiagA (x, y) = ex u (R(x, u) and C(u, y)); + DiagB (x, y) = ex u (R(x, u) and C(y, u))" in + test_maximax "Gomoku" ~debug:0 ~struc ~loc:1 ~iters:180 + (fun s -> s = "Circle{1:e1}"); + ); + + "maximax suggest defense 3" >:: + (fun () -> + let struc = "MODEL [ | P:1 {}; Q:1 {} | ] \" + ... ... ... ... + ... ... ... ... + ... ... ... ... + ... ...P ... ... + ... ... ... ... + ... Q..Q ... ... + ... ... ... ... + ... P..P Q..P ... + ... ... ... ... + ... P..Q ... ... + ... ... ... ... + ... ...Q P.. ... + ... ... ... ... + ... ... ... ... + ... ... ... ... + ... ... ... ... +\" with DiagA (x, y) = ex u (R(x, u) and C(u, y)); + DiagB (x, y) = ex u (R(x, u) and C(y, u))" in + test_maximax "Gomoku" ~debug:0 ~struc ~loc:1 ~iters:210 + (fun s -> s = "Circle{1:b6}"); + ); +] + + +let bigtests = "PlayBig" >::: [ + chess_tests_big; + gomoku_tests_big; +] + + +(* ----------------- RUN THE TESTS ------------- *) + let exec = Aux.run_test_if_target "PlayTest" tests let execbig = Aux.run_test_if_target "PlayTest" bigtests This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |