Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Shikhor Shams Wahed committed Apr 24, 2019
1 parent 7f417ea commit c5000a2
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 14 deletions.
2 changes: 1 addition & 1 deletion authors.ml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
(* TODO: set the value below *)
let hours_worked = [12; 04; 08]
let hours_worked = [20; 20; 20]
10 changes: 10 additions & 0 deletions command.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
(** Command
Representation of the different commands that a player can input during
the game.
This module contains the list of commands that are available to a player
and has a function to parse the player's input into those commands that
the machine can recognize. *)

(*The type of the input by the player. *)
type object_phrase = string list

(*The legal commands that can be recognized. *)
type command =
| Set of object_phrase
| Inventory
Expand Down
15 changes: 10 additions & 5 deletions gui.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let tutorial_value = 100
(* TUTORIAL ALGORITHM TO ENSURE PLAYER MAKES PROGRESS TOWARDS THE PROPER
INTERVAL *)

(*Feedback type to be returned to player. *)
type trade_feedback = Low | High | BigSpread | Okay

(* [check_good_interval bid ask] is an option of either None or Some bool
Expand Down Expand Up @@ -38,6 +39,8 @@ let eval_trade bid ask =
"\nA lot of traders are lifting your offer (buying from you).
This means they're buying for a low price, a bargain! Adjust your market upwards. \n"

(**[parse_input_tut str] is the option that represents the commands input
by the player. *)
let parse_input_tut str =
let wordlst = String.split_on_char ' ' (String.trim str) in
let filtered = List.filter (fun s -> String.length s >= 1) wordlst in
Expand All @@ -63,9 +66,11 @@ let query str =
false
else
begin
if (List.length text = 1) then (print_endline "Quitting tutorial..."; false)
if (List.length text = 1) then (print_endline "Quitting tutorial...";
false)
else
let response = eval_trade (int_of_string (List.nth text 0)) (int_of_string (List.nth text 1)) in
let response = eval_trade (int_of_string (List.nth text 0))
(int_of_string (List.nth text 1)) in
match (String.get response 0) with
| 'P' -> (print_endline response); false
| _ -> (print_endline response); true
Expand All @@ -92,15 +97,15 @@ let tutorial_preamble unit =
("This means traders will BUY at y and SELL at x! \n \n");
ANSITerminal.print_string [ANSITerminal.yellow]
("Suppose your market is 'set 20 40'. \n \nIn this case, the sell price of $20 is greater than the intrinsic value. \nSellers get a great deal! They can sell something worth $10 for"
^ "$20. Expect a lot of sells. Adjust your interval downwards.\n");
^ "$20. Expect a lot of sells. Adjust your interval downwards.\n");
ANSITerminal.print_string [ANSITerminal.yellow]
("\nSuppose your market is 'set 5 8'. \n \nIn this case, the buy price $8 is much less than " ^ "the intrinsic value of $10. Buys are getting a bargain! Expect a lot of buys. Adjust your interval upwards.");
ANSITerminal.print_string [ANSITerminal.yellow]
("\n\nSuppose your market is 'set 9 11'. \n\nYour market is good! With some variance, " ^ "buyers will buy at $11 which is very close to the actual price. Sellers will sell at $9. Expect roughly even " ^ " buyers and sellers. \nYou will make $11 - $9 = $2 per transaction.");
ANSITerminal.print_string [ANSITerminal.yellow]
("\n\n>>>> Starting tutorial <<<< ");
ANSITerminal.print_string [ANSITerminal.yellow]
("\nNow you try. We won't tell you the actual price... \n");
("\nNow you try. We won't tell you the actual price... \n");
tutorial_fsm ();
()

Expand All @@ -111,7 +116,7 @@ let preamble unit =
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.yellow]
"Welcome! \n";
ANSITerminal.(print_string [black; yellow]
"Welcome to the CamlCoin exchange! Here you will practice your maket making skills \n"); ()
"Welcome to the CamlCoin exchange! Here you will practice your maket making skills \n"); ()
let display_help unit =
ANSITerminal.print_string [ANSITerminal.red; ANSITerminal.blue]
("The list of possible commands are: ");
Expand Down
12 changes: 12 additions & 0 deletions gui.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
(** Gui
Representation of the tutorial provided to the player before the game is
played.
This module contains the print statements and situations that can allow a
player to understand how to play the game. It has structs that represent
undervaluing or overvaluing of a security and gives feedback to the player
based on the bid/ask prices that they have set. The tutorial simulates the
actions that traders might make based on those prices and gives a general
idea of what the right actions would be. *)

val preamble: unit -> unit

val introduction: unit -> unit
Expand Down
2 changes: 1 addition & 1 deletion main.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(*
* Main Engine - Beta
* Main Engine - Final
*
*
*)
Expand Down
8 changes: 8 additions & 0 deletions main.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(** Main
Representation of the main engine of the game.
This module contains the main engine of the game with the finite state
machine that implements the interactions of the player with the game. It
takes in input from the player and returns the effects it has on the game.
*)
1 change: 1 addition & 0 deletions marketmaker.ml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ let init_market game : t =
}
}

(*The type of result that comes from a command.*)
type result = Legal of t | Illegal

(**[display_data state] is a unit with side-effects of displaying data about
Expand Down
10 changes: 9 additions & 1 deletion marketmaker.mli
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
(** Marketmaker
Representation of the marketmaker - player - during the course of the game.
This module keeps track of the marketmaker's bid/ask prices and the
transactions that take place between the player and traders. It contains
structs to hold this data and has functions to implement changes to and
display the data.
*)
(** The abstract type of values representing adventures. *)
type bidask = {
trade_type : string;
Expand All @@ -22,12 +29,13 @@ type t = {
}

(* Trade variant. To be sent to engine *)

type send_market = {
timestamp : int;
transaction: bidask;
}

(* The transaction type. Holds information about a transaction between
a trader and marketmaker. *)
type receive_transaction = {
timestamp : int;
trade_type : string; (* hit the bid or lifted offer *)
Expand Down
6 changes: 3 additions & 3 deletions parse.ml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
open Yojson.Basic.Util
open String


(*Holds the situations from the json with the effect that each event causes.*)
type situation = {
event : string;
effect : string;
}


(*Holds the fermi questions and their answers from the json. *)
type fermiquestions =
{question : string;
answer : string;
}


(*Holds information for the introduction portion of the game. *)
type t = {
id: string;
fermi : fermiquestions list;
Expand Down
7 changes: 7 additions & 0 deletions parse.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
(** Parse
Representation of the game's intro.
This module initializes the game by extracting from the relevant json file
and providing the player with fermiquestions/diceroll. It parses the json
and introduces the situations that can occur in the json.
*)
type t
type situation = {
event : string;
Expand Down
4 changes: 2 additions & 2 deletions stats.ml
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ let trade_freq market trader =
let prnt = ["hits = "^(string_of_int hits); "lifts = "^(string_of_int lifts)]
in List.iter print_string prnt

(**[chebyshevs_var var] Uses the normal variance of a float list, and
(**[chebyshev_like_var var] Uses the normal variance of a float list, and
calculates chebyshevs variance *)
let chebyshevs_var var =
let chebyshev_like_var var =
match var with
|0. -> 0.
|_ -> 1. -. (1. -. (1./.(sqrt var)))
Expand Down
11 changes: 11 additions & 0 deletions stats.mli
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
(** Stats
Representation of the statistics of actions performed in-game.
This module uses the data gathered from the player's actions during the
course of the game and their interactions with the traders to provide them
with statistics that might aid in future decision-making.
*)

(*Holds the data about a player's transactions and bid/ask prices. *)
type graph_data = {bid_data : int list; ask_data : int list;
trade_data : string list; time_data : int list;
hidden_number : int}

(*Holds a player's dice roll data. *)
type dice_data = {
player_roll : int;
other_rolls : int list;
Expand Down
16 changes: 15 additions & 1 deletion trader.mli
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
(** Trader
Representation of the traders during the course of the game.
This module keeps track of the market's bid/ask prices when the
transactions take place between the player and traders. It contains
structs to hold data about transactions and relevant information
about each trader. It has 3 types of trader and has functions to
implement trades for each type of trader.
*)

(*Holds the bid/ask prices of the market. *)
type bidask = {
bid: int;
ask: int;
spread: int;
}

(*Holds information regarding a transaction.*)
type transaction = {
timestamp : int;
bidask: bidask;
order_type : string; (* bid or ask *)
}



(*Holds information about a particular trader's transactions and their types. *)
type orderbook = {
transactions : transaction list;
buys: int;
sells: int
}

(*Holds information about each particular trader. *)
type t = {
id : string;
hidden_number : int;
Expand All @@ -28,6 +41,7 @@ type t = {
orderbook : orderbook;
}

(*The 3 types of traders. *)
type trader_players = {
simple_ai : t;
ai1 : t;
Expand Down

0 comments on commit c5000a2

Please sign in to comment.