[ANN] Game2048Core.jl

I am pleased to announce the arrival of, Game2048Core.jl, a high(ish) performance 2048 game in pure Julia. Yes, that game from many years ago.

There are potentially a lot more performance enhancements that can be made but the basics like moving is optimized (by “borrowing” heavily from the best in class open source implementations in C++ and Rust).

This engine is suitable as a backbone for search based algorithm for playing 2048 or for testing out Reinforcement Learning (RL) algorithms, although I’ve not implemented it as an RL environment.

If you are interested in playing the game and don’t mind super rudimentary UIs then you can try Game2048.jl

11 Likes
julia> using Game2048

julia> gui_game()
ALSA lib conf.c:4499:(snd_config_update_r) Cannot access file /workspace/destdir/share/alsa/alsa.conf
ALSA lib conf.c:4499:(snd_config_update_r) Cannot access file /workspace/destdir/share/alsa/alsa.conf
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM default
┌ Warning: No audio device available, sounds and music will not play.
│ ALSA: Couldn't open audio device: No such file or directory
└ @ GameZero ~/.julia/packages/GameZero/e03cc/src/GameZero.jl:303
ERROR: LoadError: ArgumentError: Package GameZero not found in current path:
- Run `import Pkg; Pkg.add("GameZero")` to install the GameZero package.

Stacktrace:
 [1] require(into::Module, mod::Symbol)
   @ Base ./loading.jl:967
 [2] eval
   @ ./boot.jl:373 [inlined]
 [3] include_string(mapexpr::typeof(identity), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1196
 [4] include_string (repeats 2 times)
   @ ./loading.jl:1206 [inlined]
 [5] initgame(jlf::String, external::Bool)
   @ GameZero ~/.julia/packages/GameZero/e03cc/src/GameZero.jl:234
 [6] rungame(jlf::String, external::Bool)
   @ GameZero ~/.julia/packages/GameZero/e03cc/src/GameZero.jl:195
 [7] rungame
   @ ~/.julia/packages/GameZero/e03cc/src/GameZero.jl:194 [inlined]
 [8] gui_game()
   @ Game2048 ~/.julia/packages/Game2048/sEDAu/src/game-zero.jl:7
 [9] top-level scope
   @ REPL[3]:1
in expression starting at string:1

julia> ALSA lib conf.c:4499:(snd_config_update_r) Cannot access file /workspace/destdir/share/alsa/alsa.conf
(tmp) pkg> add GameZero
ALSA lib conf.c:4499:(snd_config_update_r) Cannot access file /workspace/destdir/share/alsa/alsa.conf
    Updating registry at `~/.julia/registries/General`
    Updating git-repo `https://github.com/JuliaRegistries/General.git`
   Resolving package versions...
    Updating `/tmp/Project.toml`
  [9da27670] + GameZero v0.2.1
  No Changes to `/tmp/Manifest.toml`

(tmp) pkg> add GameZeroALSA lib conf.c:4499:(snd_config_update_r) Cannot access file /workspace/destdir/share/alsa/alsa.conf
julia> gui_game()
ALSA lib conf.c:4499:(snd_config_update_r) Cannot access file /workspace/destdir/share/alsa/alsa.conf
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM default
┌ Warning: No audio device available, sounds and music will not play.
│ ALSA: Couldn't open audio device: No such file or directory
└ @ GameZero ~/.julia/packages/GameZero/e03cc/src/GameZero.jl:303
ERROR: LoadError: ArgumentError: Package Colors not found in current path:
- Run `import Pkg; Pkg.add("Colors")` to install the Colors package.

Stacktrace:
 [1] require(into::Module, mod::Symbol)
   @ Base ./loading.jl:967
 [2] eval
   @ ./boot.jl:373 [inlined]
 [3] include_string(mapexpr::typeof(identity), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1196
 [4] include_string (repeats 2 times)
   @ ./loading.jl:1206 [inlined]
 [5] initgame(jlf::String, external::Bool)
   @ GameZero ~/.julia/packages/GameZero/e03cc/src/GameZero.jl:236
 [6] rungame(jlf::String, external::Bool)
   @ GameZero ~/.julia/packages/GameZero/e03cc/src/GameZero.jl:195
 [7] rungame
   @ ~/.julia/packages/GameZero/e03cc/src/GameZero.jl:194 [inlined]
 [8] gui_game()
   @ Game2048 ~/.julia/packages/Game2048/sEDAu/src/game-zero.jl:7
 [9] top-level scope
   @ REPL[5]:1
1 Like

I built a basic StippleUI around it.

Animation could be better and will be improved over time …

Control is via arrow keys, undo (rewind) is done via pressing 'r'.
Currently there is no replay button, restarting has to be done manually with

model.bitboard[] = initbboard()

But well, that’s the status quo …

7 Likes