open Graphics ;;
Random.self_init () ;;

let mainloop () =
  open_graph Csts.open_string ;
  set_window_title "Maeth";
  try
    while true do 
      auto_synchronize false ;
      clear_graph () ;
      Menus.print_current_interface () ;
      auto_synchronize true ;
      Menus.action_on_interface () ;
      Unix.sleepf Csts.sleep_d
    done ;
    ()
  with
    | Menus.MenuStart ->
      Csts.time_to_ans_f := float_of_int (!Csts.time_to_ans) ;
      Csts.total_time_f := float_of_int (!Csts.total_time) ;
      Csts.start_0 := Unix.gettimeofday () ;
      Csts.max_score := 
        100 
        * !Csts.difficulty 
        * !Csts.calc_length * int_of_float (Float.sqrt (float_of_int !Csts.calc_length))
        * (90 / !Csts.time_to_ans) * int_of_float (Float.sqrt (float_of_int (90 / !Csts.time_to_ans))) ;
      Maeth.init_odds () ;
      clear_graph () ;
      while true do
        ignore (Maeth.maeth_main ()) ;
      done ;;

(*
let difficulty = ref 1 ;;
let calc_length = ref 3 ;;
let time_to_ans = ref 10 ;;
let total_time = ref 60 ;;
let n_inf = ref 1 ;;
let n_sup = ref 10 ;;
*)

mainloop () ;;