nneonneo / 2048-ai

AI for the 2048 game
MIT License
1.09k stars 279 forks source link

Allow variable board size #12

Closed jkohjk closed 10 years ago

jkohjk commented 10 years ago

Would it be possible to setup a constant which defines the board size instead of hardcoding it into the places that uses it?

I was looking into modifying your AI to be able to work on this http://cyberzhg.github.io/2048/ but I wasn't sure which numbers are linked to the board size and which are not.

Thanks

nneonneo commented 10 years ago

One of the major features of this AI algorithm is that it uses 64-bit integers to represent the entire board. However, this means that you can only store a maximum of 16 4-bit tiles in a single board. Removing the hard-coded board size means replacing this efficient implementation with a more generic, but potentially less performant board representation.

Additionally, the hard-coded size limit (of 4x4) is also used to cache board updates and scoring (by indexing each row into a table, rather than recomputing the game rules each time). Neither of these will be cacheable if the size is unrestricted.

Therefore, to allow a variable board size for this implementation would eliminate most of its optimizations, and basically require a complete rewrite.