Permalink
Browse files

allow the the has_won function to return as soon as it funds a win al…

…ong some axis
  • Loading branch information...
rapha committed Jun 3, 2010
1 parent 4940a03 commit 70fc2822975f832ed39983fd9a2e028dd91b6aa4
Showing with 2 additions and 3 deletions.
  1. +2 −3 board.ml
View
@@ -58,9 +58,8 @@ let drop player col board =
let has_won player board =
let four_in_a_row = List.make 4 (Some player) in
- [columns; rows; north_east; north_west]
- |> List.map ((|>) board)
- |> List.exists (List.exists (contains four_in_a_row))
+ let wins_along axis = List.exists (contains four_in_a_row) (axis board) in
+ wins_along columns || wins_along rows || wins_along north_east || wins_along north_west
let top_row col board =
List.nth (columns board) col |> List.filter Option.is_some |> List.length

0 comments on commit 70fc282

Please sign in to comment.