sabaki-golaxy-live
v1.0.4
Published
A Golaxy live game integration module for Sabaki Go board
Maintainers
Readme
sabaki-golaxy-live
A Golaxy live game integration module for Sabaki Go board and other Go applications.
Installation
npm install sabaki-golaxy-liveUsage
Basic Usage
import { golaxy, getLiveReports } from 'sabaki-golaxy-live';
// 获取直播比赛列表
async function fetchLiveGames() {
try {
const games = await getLiveReports();
console.log('Live games:', games);
} catch (error) {
console.error('Failed to fetch live games:', error);
}
}
// 同步特定比赛到应用
async function syncGame(gameId) {
try {
// 设置SGF同步回调
golaxy.setSyncSgfCallback((gameId, sgfContent) => {
// 在这里实现将SGF内容加载到你的Go应用中的逻辑
console.log(`Syncing game ${gameId} with SGF content:`, sgfContent);
// 例如:yourGoApp.loadSgf(sgfContent);
});
// 开始同步
await golaxy.syncGolaxyOrYikeLizban([gameId]);
} catch (error) {
console.error('Failed to sync game:', error);
}
}
// 停止同步
golaxy.stopSync();Using GolaxyLiveReportsAgent
import { GolaxyLiveReportsAgent } from 'sabaki-golaxy-live';
// 创建智能体实例
const agent = new GolaxyLiveReportsAgent();
// 执行智能体任务
async function runAgent() {
const result = await agent.execute({
type: 'live',
limit: 10
});
if (result.success) {
console.log('Agent result:', result.data);
} else {
console.error('Agent error:', result.error);
}
}API
Golaxy Class
Constructor
new Golaxy(prop = 'name', today = new Date().toISOString().split('T')[0], isLive = true)Methods
setSyncSgfCallback(callback): 设置SGF同步回调函数async getLiveReports(name = '', page = 0): 获取直播和历史比赛报告async getGolaxyLive(gameId, moveNum): 获取特定比赛的直播数据getReportUrl(game, isLive = true): 获取比赛报告URLasync syncGolaxyOrYikeLizban(gameIds, isReport = false, requestAgain = false, isGolaxy = true): 同步Golaxy或Yike比赛convertFromCoordinate(coordinateStr): 将字符串坐标转换为(x, y)坐标convertCoordinate(coordinate): 将(x, y)坐标转换为字符串坐标getPropsBySgfStr(sgfStr): 从SGF字符串中提取属性countMovesAndGetLastMove(node): 计算步数并获取最后一步async getSgfByGolaxy(url, isD = false): 通过Golaxy API获取SGF内容async syncSgf(gameId, sgfContent): 同步SGF内容async requestGolaxyOrYikeMove(gameId, lastMoveNum, lastMove, playerBlack, playerWhite, isGolaxy = true): 请求最新的Golaxy或Yike步数startSync(gameId, lastMoveNum, lastMove, playerBlack, playerWhite): 开始同步stopSync(): 停止同步
Functions
getLiveReports(name = '', page = 0): 获取直播和历史比赛报告syncGolaxyOrYikeLizban(liveIds, is_live = true): 同步Golaxy或Yike比赛
Constants
AGENT_STATES: 智能体状态ERROR_TYPES: 错误类型TOOL_TYPES: 工具类型
License
MIT
