A helper for the iMessage GamePigeon Avalanche Mancala mode. It can read a screenshot using Google Cloud Vision or accept manual board input, then compute the best single-turn move sequence.
- Avalanche-mode solver (multiple sowings in one turn).
- Screenshot OCR via Google Cloud Vision (optional).
- Manual board entry (recommended for accuracy).
- Vertical board display aligned with left/right columns.
- Prints one best move sequence (not a list).
Mancala/is the Maven project (build/run from here).src/main/java/mancala/MancalaGenerate.javais the solver.src/main/java/mancala/Mancala.javais a playable CLI version.
- Java 21 (or any JDK 8+ if you change the compiler target).
- Maven.
- For OCR mode: a Google Cloud project with Vision API enabled and a service account JSON key.
From the repo root:
cd Mancala
mvn -q -DskipTests package
mvn -q dependency:build-classpath -DincludeScope=runtime -Dmdep.outputFile=cp.txtManual input is the most reliable and does not require Google Cloud.
java -cp "$(cat cp.txt):target/mancala-1.0-SNAPSHOT.jar" \
mancala.MancalaGenerate --manualEnter numbers in this exact order:
- Top store (opponent)
- 6 rows of left right (top to bottom)
- Bottom store (you)
Example (fresh board):
0
4 4
4 4
4 4
4 4
4 4
4 4
0
You can also enter 12 numbers without stores (stores default to 0). To finish input, send EOF (macOS/Linux: Ctrl+D on a blank line; Windows: Ctrl+Z then Enter).
- Google account
- Local shell (macOS/Linux assumed)
- Ability to use absolute paths
- Go to Google Cloud Console.
- Project selector → New Project.
- Name: anything (e.g.
loadgame-vision). - Note your PROJECT_ID.
- Console → APIs & Services → Library.
- Search Cloud Vision API.
- Enable it.
- IAM & Admin → Service Accounts.
- Create Service Account (name it
vision-sa). - Grant role:
Cloud Vision API User- (or
Editorif you want zero friction)
- Finish.
- Click the service account.
- Keys tab → Add Key → Create new key.
- Type: JSON.
- Download the file (e.g.
vision-sa-<hash>.json).
mkdir -p ~/.gcp
mv ~/Downloads/vision-sa-*.json ~/.gcp/vision.json
chmod 600 ~/.gcp/vision.jsonOne-off (current session only):
export GOOGLE_APPLICATION_CREDENTIALS="$HOME/.gcp/vision.json"Verify:
echo $GOOGLE_APPLICATION_CREDENTIALSzsh:
echo 'export GOOGLE_APPLICATION_CREDENTIALS="$HOME/.gcp/vision.json"' >> ~/.zshrc
source ~/.zshrcbash:
echo 'export GOOGLE_APPLICATION_CREDENTIALS="$HOME/.gcp/vision.json"' >> ~/.bashrc
source ~/.bashrcpython - <<EOF
from google.cloud import vision
client = vision.ImageAnnotatorClient()
print("Vision client OK")
EOFIf this fails: check the credentials path and that Vision API is enabled.
- Never commit the JSON key.
- Prefer ignoring the key file (e.g.
vision.json) or the~/.gcp/folder. Avoid ignoring*.jsonglobally if this repo haspackage.jsonor other JSON files. - Rotate keys if leaked.
- Put your image somewhere accessible (e.g.
Mancala/image.jpg). - Set your credentials:
export GOOGLE_APPLICATION_CREDENTIALS="/absolute/path/to/your-service-account.json"- Run with a path argument:
java -cp "$(cat cp.txt):target/mancala-1.0-SNAPSHOT.jar" \
mancala.MancalaGenerate "/absolute/path/to/image.jpg"If you omit the path, it tries image.jpg in the current directory, then Mancala/image.jpg.
Note: the current code prints
File not found!for anyIOException, which can also mean missing/invalid Google credentials. If OCR fails, verify your key and that Vision API is enabled.
The solver prints the board like this:
OPP_STORE
L1 R1
L2 R2
L3 R3
L4 R4
L5 R5
L6 R6
MY_STORE
Where:
- Left column is the opponent side (top to bottom: board indices 13,12,11,10,9,8)
- Right column is your side (top to bottom: board indices 6,5,4,3,2,1)
- Top store = opponent (board index 0)
- Bottom store = you (board index 7)
The printed move order uses your pocket numbers 1–6:
Top store
13 6
12 5
11 4
10 3
9 2
8 1
Bottom store
So:
- Pocket 1 is bottom-right.
- Pocket 6 is top-right.
You can also play a simple text-based Mancala game:
java -cp "$(cat cp.txt):target/mancala-1.0-SNAPSHOT.jar" mancala.Mancala- Maven not found: install it via Homebrew (
brew install maven) or your OS package manager. - "File not found!" on OCR: verify the image path and
GOOGLE_APPLICATION_CREDENTIALS. - Manual input seems stuck: enter 14 numbers, or enter 12 numbers and then a blank line.
- Java compatibility warnings: ensure your JDK and
pom.xmltarget match.
- Never commit or publish your service account JSON key.
- Keep keys outside the repo (e.g.
~/secrets/) and setGOOGLE_APPLICATION_CREDENTIALS. - Before publishing, you can clean ignored build output with:
git clean -fdXAdd a license if you plan to publish or share widely.