-
Notifications
You must be signed in to change notification settings - Fork 4
/
Tennis.fs
51 lines (41 loc) · 840 Bytes
/
Tennis.fs
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
module Tennis
open System
type Player =
| PlayerOne
| PlayerTwo
type Point =
| Love
| Fifteen
| Thirty
| Forty
| Advantage
| Win
let game = id
let score player points =
let p1, p2 = points
let advance p =
match p with
| Love -> Fifteen
| Fifteen -> Thirty
| Thirty -> Forty
| Forty -> Win
| _ -> p
let deuce =
match player with
| PlayerOne when p1 = Advantage -> (Win, Forty)
| PlayerTwo when p2 = Advantage -> (Forty, Win)
| _ -> (Forty, Forty)
let straight =
match player with
| PlayerOne -> (advance p1, p2)
| PlayerTwo -> (p1, advance p2)
match points with
| (Forty, Forty)
| (Advantage, _)
| (_, Advantage) -> deuce
| _ -> straight
let isover points =
match points with
| (Win, _) -> true
| (_, Win) -> true
| _ -> false