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

mbarbin / super-master-mind / 216

31 Jan 2026 09:40AM UTC coverage: 75.947% (-12.4%) from 88.313%
216

Pull #45

github

web-flow
Merge 729c30d79 into 3d48eb3d9
Pull Request #45: Dune pkg ci migration

922 of 1214 relevant lines covered (75.95%)

2008918.11 hits per line

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

8.7
/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 In_channel.input_line In_channel.stdin with
×
9
  | Some line -> line
×
10
  | None -> raise End_of_file
×
11
;;
12

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

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

40
let cmd =
41
  Command.make
11✔
42
    ~summary:"Run interactively."
43
    (let open Command.Std in
44
     let+ solution =
45
       Arg.named_opt
11✔
46
         [ "solution" ]
47
         Code.param
48
         ~docv:"CODE"
49
         ~doc:"Specify a chosen solution (default is random)."
50
     in
51
     let solution =
×
52
       match solution with
53
       | Some solution -> solution
×
54
       | None ->
55
         Code.of_index_exn (Random.int (Lazy.force Code.cardinality)) [@coverage off]
56
     in
57
     run ~solution)
58
;;
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