This repository has been archived by the owner on Aug 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
morpionDef.ml
65 lines (57 loc) · 1.56 KB
/
morpionDef.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
type joueur = Croix | Cercle
type morpion =
Grille of morpion array array
| Coup of joueur
| CoupTmp of joueur
| Vide
type morpion_case =
Center
| North
| NorthEast
| East
| SouthEast
| South
| SouthWest
| West
| NorthWest
let coords_from_morpion_case = function
Center -> 1, 1
| North -> 1, 0
| NorthEast -> 2, 0
| East -> 2, 1
| SouthEast -> 2, 2
| South -> 1, 2
| SouthWest -> 0, 2
| West -> 0, 1
| NorthWest -> 0, 0
let access t c = let (x,y) = coords_from_morpion_case c in t.(x).(y)
let change t c a = let (x,y) = coords_from_morpion_case c in t.(x).(y) <- a
let modify t c f = let (x,y) = coords_from_morpion_case c in t.(x).(y) <- f t.(x).(y)
(* faut ptet arréter de faire l'idiot...
module String = struct
let get t c = let (x,y) = coords_from_morpion_case c in t.(x).(y)
let set t c a = let (x,y) = coords_from_morpion_case c in t.(x).(y) <- a
end
*)
let morpion_case_from_coords =
let conversion =
[|
[| NorthWest ; North ; NorthEast |] ;
[| West ; Center ; East |] ;
[| SouthWest ; South ; SouthEast |]
|]
in fun x y -> conversion.(y).(x)
type chemin = morpion_case list
let string_of_morpion_case = function
Center -> "Center"
| North -> "North"
| NorthEast -> "NorthEast"
| East -> "East"
| SouthEast -> "SouthEast"
| South -> "South"
| SouthWest -> "SouthWest"
| West -> "West"
| NorthWest -> "NorthWest"
let creer_grille () = Grille (Array.make_matrix 3 3 Vide)
let creer_joueur j = Coup j
let creer_joueur_tmp j = CoupTmp j