diff options
author | Alex AUVOLAT <alex.auvolat@ens.fr> | 2014-11-10 11:21:58 +0100 |
---|---|---|
committer | Alex AUVOLAT <alex.auvolat@ens.fr> | 2014-11-10 11:21:58 +0100 |
commit | b5258947e0cd7764f401681cd7c82d294c6d9b78 (patch) | |
tree | 05b5189a524aa6d7ab6d3d5294e724b6a768a86d | |
parent | 80e625a9c8d33c71fe69a375c211868fcc1938a5 (diff) | |
download | CompetIA-b5258947e0cd7764f401681cd7c82d294c6d9b78.tar.gz CompetIA-b5258947e0cd7764f401681cd7c82d294c6d9b78.zip |
Add visualization for morpion rec
-rw-r--r-- | judge/morpion_rec.ml | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/judge/morpion_rec.ml b/judge/morpion_rec.ml index d2b1c14..05d1d3e 100644 --- a/judge/morpion_rec.ml +++ b/judge/morpion_rec.ml @@ -10,7 +10,7 @@ module G = struct type loc1 = int * int type loc = loc1 * loc1 - type c = + type c = (* P1 <-> X || P2 <-> O *) | Empty | X | O @@ -104,6 +104,7 @@ module G = struct | l when List.for_all ((=) X) l -> X | l when List.for_all ((=) O) l -> O | l when List.exists ((=) X) l && List.exists ((=) O) l -> T + | l when List.exists ((=) T) l -> T | _ -> Empty) with | l when List.exists ((=) X) l -> X @@ -136,9 +137,57 @@ module G = struct let s (s, _, _) = s + + (* ************************* *) + (* Visualisation graphique ! *) + + open Graphics + open Main + open G_util + + let subpos (x1, y1, x2, y2) (l, c) = + let dx, dy = (x2 - x1) / 3, (y2 - y1) / 3 in + x1 + (l-1) * dx, y1 + (c-1) * dy, x1 + l * dx, y1 + c * dy + + let disp_l lw (x1, y1, x2, y2) = + let m = 4 in + function + | X -> + set_line_width lw; + set_color p1c; + draw_segments + [| x1+m, y1+m, x2-m, y2-m; + x1+m, y2-m, x2-m, y1+m |]; + set_line_width 1 + | O -> + set_line_width lw; + set_color p2c; + draw_circle ((x1+x2)/2) ((y1+y2)/2) (min (x2-x1) (y2-y1) / 2 - m); + set_line_width 1 + | _ -> () + + let disp_r rf sdf ((x1, y1, x2, y2) as box) mor = + let m = 4 in + let dx, dy = (x2 - x1) / 3, (y2 - y1) / 3 in + let x12, x23 = x1 + dx, x1 + 2 * dx in + let y12, y23 = y1 + dy, y1 + 2 * dy in + set_color black; + draw_segments + [| x12, y1+m, x12, y2-m; + x23, y1+m, x23, y2-m; + x1+m, y12, x2-m, y12; + x1+m, y23, x2-m, y23 |]; + List.iter (fun p -> sdf (subpos box p) (getp1 mor p)) all_p1; + disp_l 2 box (rf mor) + let display_game (s, m, q) (pn1, pn2) = + let cx, cy = center() in + disp_r + (reduce_m (reduce_m (fun x -> x))) + (disp_r (reduce_m (fun x -> x)) (disp_l 1)) + (cx - 200, cy - 200, cx + 200, cy + 200) + m (* TODO *) - () end |