• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mbarbin / super-master-mind / 177

16 Dec 2025 02:27PM UTC coverage: 92.007% (-4.3%) from 96.355%
177

push

github

web-flow
Merge pull request #33 from mbarbin/json-opening

Use json format for opening-book

420 of 491 new or added lines in 28 files covered. (85.54%)

2 existing lines in 1 file now uncovered.

1013 of 1101 relevant lines covered (92.01%)

3368615.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.65
/src/maker.ml
1
(*********************************************************************************)
2
(*  super-master-mind: A solver for the super master mind game                   *)
3
(*  SPDX-FileCopyrightText: 2021-2025 Mathieu Barbin <mathieu.barbin@gmail.com>  *)
4
(*  SPDX-License-Identifier: MIT                                                 *)
5
(*********************************************************************************)
6

7
let input_line () =
8
  match Stdlib.In_channel.input_line In_channel.stdin with
8✔
9
  | Some line -> line
8✔
NEW
10
  | None -> raise End_of_file
×
11
;;
12

13
let rec input_code () =
14
  let prompt = "Please enter your guess: " in
8✔
15
  Stdlib.print_string prompt;
16
  Out_channel.(flush stdout);
8✔
17
  let line = input_line () in
18
  match line |> Json.of_string |> Code.Hum.of_json |> Code.create_exn with
6✔
19
  | exception e ->
3✔
20
    Stdlib.print_endline (Stdlib.Printexc.to_string e);
3✔
21
    input_code ()
3✔
22
  | code -> code
5✔
23
;;
24

25
let run ~solution =
26
  let code_size = force Cue.code_size in
1✔
27
  let rec aux i =
1✔
28
    let candidate = input_code () in
5✔
29
    let cue = Code.analyze ~solution ~candidate in
5✔
30
    let { Cue.Hum.white; black } = Cue.to_hum cue in
31
    print_dyn (Dyn.Tuple [ i |> Dyn.int; candidate |> Code.to_dyn ]);
5✔
32
    Stdlib.print_endline (Printf.sprintf "#black (correctly placed)  : %d" black);
5✔
33
    Stdlib.print_endline (Printf.sprintf "#white (incorrectly placed): %d" white);
5✔
34
    Out_channel.(flush stdout);
5✔
35
    if black < code_size then aux (Int.succ i)
4✔
36
  in
37
  aux 1
38
;;
39

40
let cmd =
41
  Command.make
19✔
42
    ~summary:"Run interactively."
43
    (let open Command.Std in
44
     let+ solution =
45
       Arg.named_opt
19✔
46
         [ "solution" ]
47
         Code.param
48
         ~docv:"CODE"
49
         ~doc:"Specify a chosen solution (default is random)."
50
     in
51
     let solution =
1✔
52
       match solution with
53
       | Some solution -> solution
1✔
54
       | None -> Code.of_index_exn (Random.int (force Code.cardinality)) [@coverage off]
55
     in
56
     run ~solution)
57
;;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc