aboutsummaryrefslogtreecommitdiff
path: root/judge/main.ml
diff options
context:
space:
mode:
Diffstat (limited to 'judge/main.ml')
-rw-r--r--judge/main.ml98
1 files changed, 66 insertions, 32 deletions
diff --git a/judge/main.ml b/judge/main.ml
index 5155e02..6a42ff8 100644
--- a/judge/main.ml
+++ b/judge/main.ml
@@ -19,7 +19,9 @@ end = struct
module G = C.G
(* Graphic helpers *)
- let grey = rgb 64 64 64
+ let grey = rgb 112 112 112
+ let red = rgb 200 0 0
+ let green = rgb 0 150 0
let center () = size_x () / 2, size_y () / 2
@@ -31,10 +33,11 @@ end = struct
set_color black;
let cr d =
draw_rect (cx - w - d) (cy - h - d)
- (cx + w + d) (cy + h + d)
+ (2 * (w + d)) (2 * (h + d))
in cr 20; cr 22;
moveto (cx - w) (cy - h);
- draw_string m
+ draw_string m;
+ synchronize ()
let tw m = fst (text_size m)
@@ -44,13 +47,13 @@ end = struct
draw_string m
let text1 l c m =
- text_l l 20 c m
+ text_l l 30 c m
let text2 l c m =
- text_l l (size_x()/2 - 20 - tw m) c m
+ text_l l (size_x()/2 - 30 - tw m) c m
let text3 l c m =
- text_l l (size_x()/2 + 20) c m
+ text_l l (size_x()/2 + 30) c m
let text4 l c m =
- text_l l (size_x() - 20 - tw m) c m
+ text_l l (size_x() - 30 - tw m) c m
let hl () =
draw_poly_line
@@ -60,6 +63,10 @@ end = struct
(* Init/Close *)
let init () =
open_graph " 800x600";
+ set_font "-misc-fixed-bold-r-normal--15-120-90--c-90-iso8859-1";
+ auto_synchronize false;
+ display_mode false;
+ remember_mode true;
fullscreen_msg "Starting up..."
let close () =
@@ -78,6 +85,11 @@ end = struct
| ScoreBoard, '\t' -> curr_view := MatchList false
| MatchList _, '\t' -> curr_view := ScoreBoard
| MatchList e, 'f' -> curr_view := MatchList (not e)
+ | MatchList _, 'r' -> curr_view := Question(
+ "Launch new round?",
+ (fun () -> C.add_rounds(); curr_view := MatchList false),
+ !curr_view
+ )
| Question(_, y, n), 'y' -> y()
| Question(_, y, n), 'n' -> curr_view := n
| v, 'q' ->
@@ -92,50 +104,71 @@ end = struct
and display () =
clear_graph ();
- match !curr_view with
+ begin match !curr_view with
| ScoreBoard -> scoreboard_disp ()
| MatchList f -> matchlist_disp f
| ViewGame g -> game_disp g
| Question (q, _, _) -> fullscreen_msg (q ^ " (y/n)")
+ end;
+ synchronize ()
and curr_view = ref ScoreBoard
(* Scoreboard view *)
and scoreboard_disp () =
- text1 2 black "score board";
- text4 2 grey "match list >";
+ text1 1 black "score board";
+ text4 1 grey "match list >";
hl();
let scores = List.sort
(fun (_, sc) (_, sc') -> sc' - sc)
(C.scores())
in
- let xx l (n, s) t =
- text1 l black t;
- text1 (l+1) black (" "^n);
- text2 (l+1) black (string_of_int s)
- in
- let scores = match scores with
- | first::q -> xx 4 first "first place"; q
- | [] -> []
- in
- let scores = match scores with
- | sec::q -> xx 7 sec "second place"; q
- | [] -> []
- in
- let scores = match scores with
- | thrd::q -> xx 10 thrd "third place"; q
- | [] -> []
- in
let show_sc i (n, s) =
- text3 (i+4) black ((string_of_int (i+3))^". "^n);
- text4 (i+1) black (string_of_int s)
+ text2 (i+4) black (string_of_int (i+1)^". ");
+ text3 (i+4) black n;
+ text4 (i+4) black (string_of_int s)
in
List.iteri show_sc scores
(* Match list view *)
and matchlist_disp show_only_running =
- (* TODO *)
- ()
+ text1 1 black "match list";
+ text2 1 black "queued matches:";
+ text3 1 black (string_of_int (C.ql ()));
+ text4 1 grey "score board >";
+ hl();
+ let games =
+ if show_only_running then
+ List.filter
+ (fun g -> match C.p1 g, C.p2 g with Dead, Dead -> false | _ -> true)
+ (C.games())
+ else C.games()
+ in
+ let time = Unix.gettimeofday() in
+ let print_g i g =
+ let cp1, cp2 = match C.s g with
+ | TurnOf _ -> black, black
+ | Won P1 -> green, red
+ | Won P2 -> red, green
+ | Tie -> grey, grey
+ | Eliminated P1 -> red, grey
+ | Eliminated P2 -> grey, red
+ in
+ let mp = function
+ | Loading -> grey, ">>>"
+ | Saving -> grey, "<<<"
+ | Dead -> black, ""
+ | StandBy t -> grey, Format.sprintf "%.2f" t
+ | Thinking (t, tb) -> black,
+ Format.sprintf "[ %.2f ]" (t -. (time -. tb))
+ in
+ let p1n, p2n = C.pn g in
+ let c, m = mp (C.p1 g) in text1 (i+4) c m;
+ text2 (i+4) cp1 p1n;
+ text3 (i+4) cp2 p2n;
+ let c, m = mp (C.p2 g) in text4 (i+4) c m
+ in
+ List.iteri print_g games
(* Game view *)
and game_disp g =
@@ -161,7 +194,8 @@ end = struct
UI.init();
begin try while true do
C.handle_events ();
- UI.handle_events ()
+ UI.handle_events ();
+ UI.display ()
done with
Exit_judge ->
C.finish ();