Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…ong some axis
  • Loading branch information...
commit 70fc2822975f832ed39983fd9a2e028dd91b6aa4 1 parent 4940a03
@rapha authored
Showing with 2 additions and 3 deletions.
  1. +2 −3 board.ml
View
5 board.ml
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.