(FUN)ctional Tetris
The classic game of Tetris, crafted in Ocaml style.
Getting Started
A live version of the app can be found here. These instructions will get you a copy of the project up and running on your local machine. See compilation for notes on how to compile the project yourself.
Prerequisites
Ocaml and the OCaml Package Manager.
Compilation
The application can be run by simply launching the html file in any modern browser (we recommend Google Chrome). However, if you wish to compile the Ocaml code into JavaScript yourself, follow the steps below:
Install Js_of_ocaml
Assuming Ocaml and OPAM are already installed on your machine, run the following command to install Js_of_ocaml.
opam install js_of_ocaml js_of_ocaml-ppx js_of_ocaml-lwt
Build the System
Inside the directory containing Ocaml source code, run the following command.
ocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml.ppx -package js_of_ocaml-lwt -linkpkg -o tetris.byte model.mli model.ml heybotL.mli heybotL.ml command.ml view.mli view.ml tetris.ml
Compile into JS
Finally, compile the bytecode into JavaScript using Js_of_ocaml.
Js_of_ocaml tetris.byte
Genetic Algorithm
Compilation
In the source directory, run the following commands to compile relevant files.
ocamlopt -o genAlg model.mli heybotL.mli genetic.mli
ocamlopt -o genAlg model.ml heybotL.ml genetic.ml
Execution
Once the files have been compiled as described above the genetic algorithm can be run by running the executable file genAlg.exe which should now be in the directory of the source code.
In order to change the number of generations that are considered change the number in the line
let () = let wgts = run_genetic **some number** in print_lst wgts
to the desired number of generations to be run. The higher the number of generations, the better the weights for the AI will be.
After the algorithm is complete the relevant numbers will be printed in the window for the executable file in the order of: height, lines_completed, holes, bumpiness.
In its current form the genetic algorithm takes a while to run since it is currently using a population size of 16 and plays up to 5 games to 90 for each pair at each generation.
Built With
- Ocaml - Functional language with imperative features
- Js_of_ocaml - Compiler from Ocaml bytecode to Javascript
- Lwt - Library providing light-weight cooperative threads
Authors
- Benjamin Gillott - bg357 - game model
- Hao Lee - hl2258 - AI
- Perry Lee Loveridge - pll37 - genetic algorithm
- Steven Ye - xy93 - view & controller
See the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE.md file for details
Acknowledgments
- TA Devin Lehmacher & the CS3110 course staff