forked from SamRod33/UNO_Game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainFunctions.ml
40 lines (36 loc) · 1.37 KB
/
mainFunctions.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
open State
open Card
open Player
open Computer
(** [update_five_most_recent_card c cards] is [c :: cards] if
[List.length cards < 5] and [cards] with the last element in the
list removed and [c] added to the beginning of the list if
[List.length cards = 5]. Requires: [List.length cards <= 5]*)
let update_five_most_recent_card card = function
| [ a; b; c; d; e ] -> [ card; a; b; c; d ]
| a -> card :: a
(** [create_players num_real num_computer] is a list of
[num_real + num_computer] players, where [num_computer] are
computers.*)
let create_players players num_real num_computer =
let rec help lst = function
| 0 -> lst
| n ->
let player =
if n > num_real then
create ("Computer " ^ string_of_int n) true n
else create ("Player " ^ string_of_int n) false n
in
help (player :: lst) (n - 1)
in
help [] (num_real + num_computer)
(** [all_players_but_one player g] is a list of all the players but
[player] in state [g].*)
let all_players_but_one player g =
List.filter (fun p -> id p <> id player) (players g)
(** [get_nth_player_id n players] is the id of the (n+1)th player in
[players] starting from the leftmost player.*)
let rec get_nth_player_id n players =
match players with
| [] -> failwith "not enough players"
| h :: t -> if n = 0 then id h else get_nth_player_id (n - 1) t