gobang-ai
v1.0.1
Published
describe algo for gobang
Downloads
2
Readme
gobang-ai
describe algo for gobang
Note: This is not the best solution, just to learn.
Install
npm i gobang-ai -S
NOTE
ALL INDEX START FROM 0
API
createBoard
create a board
interface Board {
width: number,
height: number,
blocks: any[], // initial value is `false`
finder: finder,
}
interface createBoard {
(width: number, height: number): Board
}
finder
create find functions in all directions
// find piece in another direction
interface DirFunc {
(i: number): number
}
interface finder {
(width: number, height: number): {
up: DirFunc,
down: DirFunc,
left: DirFunc,
right: DirFunc,
leftUp: DirFunc,
rightUp: DirFunc,
leftDown: DirFunc,
rightDown: DirFunc,
// if a piece in this board, return true
inner: (i: number) => boolean
}
}
pos2index
convert position object to index number
interface Pos {
x: number,
y: number,
}
interface pos2index {
(board: Board, pos: Pos): number
}
checkPass
check 5 pieces in one line
interface checkPass {
(board: Board, start: number): boolean
}