gobang-ai

1.0.1 • Public • Published

gobang-ai

build status

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
}

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.16latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.16
1.0.03

Package Sidebar

Install

npm i gobang-ai

Weekly Downloads

6

Version

1.0.1

License

MIT

Unpacked Size

9.72 kB

Total Files

7

Last publish

Collaborators

  • tinkgu