Skip to content

Commit 5a5d158

Browse files
committed
adding initial project files
0 parents  commit 5a5d158

23 files changed

+2804
-0
lines changed

INSTALL.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Install instructions: run 'make build' in the terminal. Make sure you are in the path with the MakeFile in it.
2+
3+
To play run 'make play'

Makefile

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
MODULES=poker command state main author bot testBot myBot
2+
OBJECTS=$(MODULES:=.cmo)
3+
MLS=$(MODULES:=.ml)
4+
MLIS=$(MODULES:=.mli)
5+
TEST=test.byte
6+
MAIN=main.byte
7+
OCAMLBUILD=ocamlbuild -use-ocamlfind
8+
PKGS=ounit2,str,ANSITerminal
9+
10+
default: build
11+
utop
12+
13+
build:
14+
$(OCAMLBUILD) $(OBJECTS)
15+
16+
test:
17+
$(OCAMLBUILD) -tag 'debug' $(TEST) && ./$(TEST)
18+
19+
play:
20+
$(OCAMLBUILD) $(MAIN) && ./$(MAIN)
21+
22+
clean:
23+
ocamlbuild -clean
24+
rm -rf doc.public doc.private
25+
26+
docs: docs-public docs-private
27+
28+
docs-public: build
29+
mkdir -p doc.public
30+
ocamlfind ocamldoc -I _build -package $(PKGS) \
31+
-html -stars -d doc.public $(MLIS)
32+
33+
docs-private: build
34+
mkdir -p doc.private
35+
ocamlfind ocamldoc -I _build -package $(PKGS) \
36+
-html -stars -d doc.private \
37+
-inv-merge-ml-mli -m A -hide-warnings $(MLIS) $(MLS)

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# cs3110-poker
2+
3+
Use [make play] to play

_tags

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
true: package(ounit2),package(ANSITerminal), package(str)

author.ml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(** This value is approximent *)
2+
let hours_worked = 80

author.mli

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
(** CS 3110 Fall 2020 MS Project
3+
@author pjf73 crf85 dea79*)
4+
5+
(************************************************************
6+
7+
Academic Integrity Statement
8+
9+
I, the person named in the @author comment above, have fully reviewed the
10+
course academic integrity policies. I have adhered to those policies in
11+
solving the assignment.
12+
13+
The policies do permit some limited collaboration among students currently
14+
enrolled in the course. If I did engage in such collaboration, here is the
15+
list of other students with whom I collaborated, and a brief summary of that
16+
collaboration:
17+
18+
- none
19+
20+
Here are any deviations from the policies that I want to document, with the
21+
understanding that being honest about my mistakes is more honorable than
22+
lying about my intellectual work:
23+
24+
- none
25+
26+
************************************************************)
27+
28+
(** [hours_worked] is the number of hours you worked on this assignment. *)
29+
val hours_worked : int

bot.ml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
type difficulty = Test | Easy | Medium | Hard
3+
4+
module type BotInfo = sig
5+
val diff : difficulty
6+
val seed : int
7+
end
8+
9+
module type Bot = sig
10+
module Info : BotInfo
11+
val get_action : State.t -> Poker.player -> Command.t
12+
end
13+
14+
module type BotMaker =
15+
functor (I : BotInfo) -> Bot with module Info = I

bot.mli

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(** A [Bot] takes a game state and produces a command *)
2+
3+
4+
(** [difficulty] represents a bot's level of complexity and skill*)
5+
type difficulty = Test | Easy | Medium | Hard
6+
7+
(** A module that matches [BotInfo] is suitable for use as
8+
the type of Info in a [Bot]. *)
9+
module type BotInfo = sig
10+
val diff : difficulty
11+
val seed : int
12+
end
13+
14+
(** A [Bot] takes a game state and produces a command *)
15+
module type Bot = sig
16+
17+
(** [Info] is a module representing information about the bot*)
18+
module Info : BotInfo
19+
20+
(** [get_action s] take a game state and produces a command.
21+
The bot acts from the perspective of [State.current_player s] *)
22+
val get_action : State.t -> Poker.player -> Command.t
23+
end
24+
25+
module type BotMaker =
26+
functor (I : BotInfo) -> Bot with module Info = I

command.ml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
type t =
2+
| Raise of int
3+
| Start
4+
| Hand
5+
| Call
6+
| Fold
7+
| Quit
8+
| Help
9+
10+
exception Malformed
11+
12+
(** [rid_spaces cmd_lst] is a helper function for parse_branch that takes
13+
in a string list [cmd_lst] which represents the command, and gets
14+
rid of trailing or leading spaces in each element and then filters for only
15+
those elements which are empty strings. *)
16+
let rid_spaces cmd_lst : string list =
17+
let open List in
18+
cmd_lst
19+
|> List.map (fun s -> String.trim s)
20+
|> filter (fun x -> String.length x > 0)
21+
22+
let parse (str : string) : t =
23+
let open String in
24+
let cmd_lst = str |> trim |> split_on_char ' ' |> rid_spaces in
25+
match cmd_lst with
26+
| "go" :: [] -> Start
27+
| "hand" :: [] -> Hand
28+
| "call" :: [] -> Call
29+
| "fold" :: [] -> Fold
30+
| "leave" :: [] -> Quit
31+
| "raise" :: num :: [] -> begin match int_of_string_opt num with
32+
| Some i -> Raise i
33+
| None -> raise Malformed
34+
end
35+
| "help" :: [] -> Help
36+
| _ -> raise Malformed

command.mli

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
(** The module handeling player actions *)
2+
3+
(** A command consists of an action and possibly an action amount as well. For
4+
example, a command can be ["start"] or it can also be ["Raise 56"]. The
5+
former begins the game, the latter raises the bet by 56 coins. *)
6+
type t = | Raise of int | Start | Hand | Call | Fold | Quit | Help
7+
8+
9+
(** [Malformed] is raised when a player's input string cannot be parsed into a
10+
command. A command is {i malformed} if the string contains no action,
11+
or if the action is "raise" and there is not a number following it,
12+
or if the action is not "raise" but there is something following it.
13+
[Failure "int_of_string"] if the substring following "raise" is not a
14+
string representation of an int*)
15+
exception Malformed
16+
17+
(** [Command.parse str] parses a player's input [str] into a command as follows.
18+
The first word will always be the action taken by the player. This can be to
19+
raise the bet, start the game, see your best hand, call, fold, quit the
20+
game, or get help.
21+
Requires: [str] contains only lowercase alphanumeric (a-z, 0-9) and space
22+
characters (only ASCII character code 32; not tabs or newlines, etc.). If
23+
there is a substring following the action, then the command is
24+
Raise and the substring consists of a string representation of an int.
25+
Raises: [Malformed] if the command is malformed. *)
26+
val parse : string -> t
27+
28+

foldBot.ml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
open Bot
2+
3+
module Make = functor (I : BotInfo) -> struct
4+
5+
module Info = I
6+
7+
let valid_bot =
8+
match I.diff with
9+
| Fold -> ()
10+
| _ -> failwith "FoldBot must have difficulty Fold"
11+
12+
let get_action s = (Fold : Command.command)
13+
14+
end

foldBot.mli

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(** A bot that only folds.
2+
created for testing purposes *)
3+
open Bot
4+
5+
(** [Make] makes a bot that only folds*)
6+
module Make : BotMaker

0 commit comments

Comments
 (0)