Skip to content

Commit

Permalink
40:40 + p1 -> not over : green
Browse files Browse the repository at this point in the history
  • Loading branch information
ilkerde committed Feb 3, 2012
1 parent e140a62 commit a807ca1
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions KataTennis.FSharp/src/Tennis.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,30 @@ type point =

let game = id

let nextpoint p =
match p with
| Forty -> Win
| _ -> p

let score player points =
let p1, p2 = points

match player with
| PlayerOne -> (nextpoint p1, p2)
| PlayerTwo -> (p1, nextpoint p2)
let advance p =
match p with
| 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
Expand Down

0 comments on commit a807ca1

Please sign in to comment.