26F-Studio / cold_clear_ai_love2d_wrapper

Mozilla Public License 2.0
5 stars 7 forks source link

cold clear ai love2d wrapper

CI platform

This is a love2d/lua wrapper for cold clear, in order use it in tetris games made by love2d game engine.

Pitfalls

Piece id

In the code of cold clear, the pieces are represented as integer thus:

typedef enum CCPiece {
    CC_I, CC_O, CC_T, CC_L, CC_J, CC_S, CC_Z
} CCPiece;

However, for technical reasons (pun intended!), the wrapper uses a reversed order, i.e. Z S J L T O I.

Error messages

The whole API segfaults on any type errors. To see sensible error messages and stack traces, uncomment the #define DEBUG_CC macro in cold_clear_wrapper.c.

How to build

git clone https://github.com/26F-Studio/cold_clear_ai_love2d_wrapper --recursive

windows

linux

ios

android

Note: To use it on android, you need to put libcold_clear.so in /lib and copy libccloader.so to save directory.

-- Hint, but not the only way to load it
package.cpath="/data/data/org.love2d.android.embed/files/save/archive/lib?.so;"..package.cpath
love.filesystem.write("libCCloader.so", love.filesystem.read("libCCloader.so"))
require "CCloader"

How to use

See cc.lua

Some important information from coldclear.h

typedef enum CCBotPollStatus {
    CC_MOVE_PROVIDED,
    CC_WAITING,
    CC_BOT_DEAD
} CCBotPollStatus;

typedef enum CCMovement {
    CC_LEFT, CC_RIGHT,
    CC_CW, CC_CCW,
    /* Soft drop all the way down */
    CC_DROP
} CCMovement;