ocamllabs / 2048-tutorial Goto Github PK
View Code? Open in Web Editor NEWOCaml tutorial based on the 2048 game
OCaml tutorial based on the 2048 game
After visiting the link in #16 from my iOS device, I thought it would be cool to add support for swipe input and also fit the board to the browser window.
This obviously won't be ready for the actual tutorial but perhaps can be considered later — or maybe some hints provided for those keen enough to try and implement it.
We discussed setting up Cubieboards and VMs as a contingency plan in case people turn up with Windows computers.
Plan:
Prepare an offline OPAM repository (and perhaps a copy of RWO) for distribution on USB sticks (mostly in case the network goes down).
What packages do we need?
@kayceesrk noticed that the instructions are difficult to follow in places, and could be improved with examples or diagrams. For example, the instructions for shift_left_helper
currently list various cases like this:
The first two squares are occupied by equal tiles. Merge them together, add an entry to the empties list, and process the rest of the row.
which sounds rather like medieval mathematics and could be made clearer with diagrams, perhaps like this:
We might also note that the interpretation of shift
depends on the direction of the last move.
Hi,
I'm interested in using and possibly adapting this tutorial for use in a workshop I'd like to teach.
Are there any extra restrictions on re-using this repo outside of the BSD2 license placed on the code in the 2048 directory?
The workshop would not be for profit, just fun.
Thanks
The polymorphic part isn't especially important for the tutorial, but we should note that structural equality is spelt =
rather than ==
.
A participant at the CUFP 2014 tutorial wrote an implementation of is_complete_row
that passed the tests but misbehaved when run as part of the game. It seems that the tests didn't catch the interchanging of the Some
and None
cases.
list
)null
, which is sui generis)match
should be sufficient: no need for destructuring let
or for function
when
guardsSo I investigated a bit. And it seems that the problem is in the canvas rendering performance (i.e. the call to Vgr.render
). The numbers are rather astonishing. One thing I don't get is why Safari doesn't call us more often for animating as we are still below the 16ms limit for getting a 60Hz animation.
Here's an example of the render frame timings for a transition in the three browsers:
Chrome
START:
4.244ms; 4.255ms; 2.87ms; 4.163ms; 1.889ms; 2.36ms; 3.311ms; 3.692ms; 1.605ms; 2.658ms; 2.784ms; 2.162ms; 2.258ms; 1.688ms; 1.554ms; 1.951ms; 1.641ms; 1.564ms; 1.242ms;
END : 19 frames @ 63.3333hz
Firefox
START:
21.9351ms; 21.316ms; 19.3239ms; 19.8034ms; 23.8123ms; 20.0289ms; 22.8311ms; 21.8929ms; 22.9779ms; 24.0915ms; 21.9377ms; 21.2064ms;
"END : 12 frames @ 40hz
Safari
START:
7.00021ms; 9.00006ms; 16ms; 11.0002ms; 6.99997ms; 7.00021ms; 8.99982ms; 9.99999ms; 11.0002ms; 16ms; 15.0001ms; 9.99999ms; 9.00006ms; 8.00014ms;
END : 14 frames @ 46.6667hz
It'd be useful to have a sheet with a description of the project and an outline of what to do.
It'd be helpful to have an mli
file for the Utils
module.
let
(rec
) for defining functions and valuesif
/then
/else
Probablky just basic modules and signatures (no functors)
I also think that we could could be less loose with the possible cases in provenance
by using a variant (see actual comment above the datatype). This could make this pattern match more obvious. It may however complexify the provenance computation code, so this may turn out to be a bad idea.
https://github.com/ocamllabs/2048-tutorial/blob/master/task.md says
Uncomment the Shifting entry in the tests_enabled list in 2048/tests/test_enabled.ml and run the tests again.
but there is no such file.
The worksheet shows how to build the implementation and run the tests, but not how to build the application itself.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.