Skip to content
RyanLin edited this page Nov 29, 2024 · 7 revisions

Table of Contents

Introduction

Darkchess (暗棋) or Banqi (Chinese: 半棋 pinyin: bànqí), or Blind Chess (盲棋), Half Chess is a two-player Chinese board game played on a 4×8 grid, or half of the xiangqi (Chinese chess) board. Most games last between ten and twenty minutes, but advanced games can last for an hour or more. Banqi is a social game, usually played for fun rather than serious competition.

details rules here


Darkchess Code

To facilitate processing by computers, Darkchess uses simplified English characters to represent each piece. The character mapping is as follows:

Code Piece (Red Side) Code Piece (Black Side) Code Description
K 帥 (King) k 將 (King) 0 空 (Empty)
G 仕 (Guard) g 士 (Guard) * 暗 (Dark, Hidden)
M 相 (Minister) m 象 (Minister)
R 俥 (Rook) r 車 (Rook)
N 傌 (Knight) n 馬 (Knight)
C 炮 (Cannon) c 包 (Cannon)
P 兵 (Pawn) p 卒 (Pawn)

API document

This document details the Darkchess Robot API, which offers two primary endpoints:

  • brain: an AI endpoint that provides strategic actions for gameplay.
  • eye: an image recognition endpoint that detects and identifies the board state.

Brain Endpoint

Returns the best Darkchess action recommendations for the current board state based on the specified algorithm.

Request Format

URL: /brain/<algo>?board=<board>&eaten=<eaten>
Method: GET

Parameter Type Description
algo String Specifies the algorithm to use for generating the next action.
Available Endpoints:
- /brain/random
- /brain/min-max (Minimax Algorithm on Wikipedia)
- /brain/alpha-beta (Alpha-Beta Pruning on Wikipedia)
- /brain/better-eval (Better Evaluation Function apply on Min-Max. note: Not working on Alpha-Beta)
board String Represents the current board state as a 32-character string.
Requirement: Length = 32 chars.
eaten String (Optional) Indicates the pieces that have been captured, represented as a string.
Requirement: Length < 32 chars.

Request Example:

GET /brain/min-max?board=00*P00M*M*0*0c0**K00gk*R**P0PG**&eaten=ppprrmgPC
0 0 * P 0 0 M *
M * 0 * 0 c 0 *
* K 0 0 g k * R
* * P 0 P G * *

eaten: p, p, p, r, r, m, g, P, C

api-example-board

example image

Success Response

Code: 200 OK

Content Example:

{
    "black": [13,29],
    "red": [17,18]
}

black: c(包) eats G(仕), red: K(帥) moves to the right

Error Response

Code: 400 BAD REQUEST


Eye Endpoint

Returns the recognized Darkchess image from the provided live camera URL or image URL.

Request Format

URL: /eye/<mode>?img=<img>
Method: GET

Parameter Type Description
mode String Specifies the recognition mode.
Available Options:
- single-chess: Recognition of a single piece image.
- full-board: Recognition of the Darkchess board.
img String The URL of the image or live camera.

Request Example:

GET /eye/full-board?img=http://192.168.1.141:8081
api-example-board

example image

Success Response

Code: 200 OK

Content Example:

{
    "board": "0000m00000**0000*p000k0000000000"
}
0 0 0 0 m 0 0 0
0 0 * * 0 0 0 0
* p 0 0 0 k 0 0
0 0 0 0 0 0 0 0

Error Response

Code: 400 BAD REQUEST