• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript goita-core.Util类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中goita-core.Util的典型用法代码示例。如果您正苦于以下问题:TypeScript Util类的具体用法?TypeScript Util怎么用?TypeScript Util使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Util类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: showField

    public static showField(game: goita.Game, turn: number) {
        const player = game.board.players[turn];
        if (player.no % 2 === 0) {
            console.write("your team:" + clc.green(game.scores[0]) + " opponent:" + clc.green(game.scores[1]) + "\n");
        } else {
            console.write("opponent:" + clc.green(game.scores[0]) + " your team:" + clc.green(game.scores[1]) + "\n");
        }
        console.write("round: " + game.roundCount + "\n");
        console.write("------------------------\n");

        const history = new Array<string>();
        history.push("p1 ", "p2 ", "p3 ", "p4 ");
        for (let i = 0; i < game.board.history.dealer; i++) {
            history[i] += "|     ";
        }
        for (let i = 0; i < game.board.history.moveStack.length; i++) {
            const m = game.board.history.moveStack[i];
            const p = goita.Util.shiftTurn(i % 4, game.board.history.dealer);
            let hs = "";
            if (m.pass) {
                hs = clc.blackBright("なし");
            } else if (m.faceDown) {
                hs = goita.Koma.hidden.Text + m.attack.Text;
                hs = clc.cyanBright(hs);
            } else {
                hs = m.block.Text + m.attack.Text;
                hs = clc.cyanBright(hs);
            }
            history[p] += "| " + hs;
        }
        for (const h of history) {
            console.write(h);
            console.write("\n");
        }
        console.write("------------------------\n");
        const pLabel = new Array<string>();
        const bLine = new Array<goita.Koma[]>();
        const aLine = new Array<goita.Koma[]>();
        const empty = "_";

        for (const p of game.board.players) {
            const l = "p" + (p.no + 1) + ":";
            pLabel.push(l);
            const b = p.field.filter((k, i) => i % 2 === 0);
            bLine.push(b);
            const a = p.field.filter((k, i) => i % 2 !== 0);
            aLine.push(a);
        }

        const pNo = goita.Util.shiftTurn(player.no, 2);
        console.write("    ");
        console.write(pLabel[pNo]);
        for (const a of aLine[pNo].reverse()) {
            console.write(clc.cyan(a === goita.Koma.empty ? empty : a.Text));
        }
        console.write("\n");
        console.write("       ");
        for (const b of bLine[pNo].reverse()) {
            console.write(clc.cyan(b === goita.Koma.empty ? empty : b.Text));
        }
        console.write("\n");

        const lOpNo = goita.Util.shiftTurn(player.no, -1);
        const rOpNo = goita.Util.shiftTurn(player.no, 1);

        console.write(pLabel[lOpNo]);
        console.write("             ");
        console.write(pLabel[rOpNo]);
        console.write("\n");
        const laLine = aLine[lOpNo].map((k) => k === goita.Koma.empty ? empty : k.Text);
        const lbLine = bLine[lOpNo].map((k) => k === goita.Koma.empty ? empty : k.Text);
        const raLine = aLine[rOpNo].map((k) => k === goita.Koma.empty ? empty : k.Text);
        const rbLine = bLine[rOpNo].map((k) => k === goita.Koma.empty ? empty : k.Text);

        for (let i = 0; i < 4; i++) {
            let s = "";
            s += laLine[i];
            s += lbLine[i];
            s += "            ";
            s += rbLine[3 - i];
            s += raLine[3 - i];
            console.write(clc.cyan(s));
            console.write("\n");
        }

        console.write("    ");
        console.write(pLabel[player.no]);
        for (const b of bLine[player.no]) {
            console.write(clc.cyan(b === goita.Koma.empty ? empty : b.Text));
        }
        console.write("\n");
        console.write("       ");
        for (const a of aLine[player.no]) {
            console.write(clc.cyan(a === goita.Koma.empty ? empty : a.Text));
        }
        console.write("\n");

        console.write("------------------------\n");
    }
开发者ID:Goita,项目名称:goita-cli,代码行数:99,代码来源:cui.ts


示例2: gameLoop

function gameLoop(exitloop: () => void) {
    const exitRound = () => {
        setTimeout(() => {
            if (game.isEnd) {
                exitloop();
            } else {
                gameLoop(exitloop);
            }
        }, wait);
    };

    if (game.history.length === 0 && !game.board && command.initialState) {
        game.startNewDealWithInitialState(command.initialState);
    } else {
        game.startNewDeal();
    }
    msgs.push("round: " + game.roundCount + " has started");

    if (game.board.isEndOfDeal) {
        const f = game.board.getFinishState();
        const yaku = game.board.yakuInfo[0];
        let yakuName = "";
        switch (yaku.yaku) {
            case goita.Yaku.rokushi:
                yakuName = "6 shi";
                break;
            case goita.Yaku.nanashi:
                yakuName = "7 shi";
                break;
            case goita.Yaku.hachishi:
                yakuName = "8 shi";
                break;
            case goita.Yaku.goshigoshi_win:
                yakuName = "5-5 shi";
                break;
            default:
                break;
        }
        const player = f.nextDealerNo === command.playerNo ? "you" : "player" + f.nextDealerNo;
        msgs.push(player + " finished with " + yakuName + " by score " + f.wonScore);
        refreshUI();
        setTimeout(() => {
            exitRound();
        }, wait * 2);

        return;
    }

    if (game.board.turnPlayer.no === command.playerNo) {
        msgs.push("you are the dealer");
    } else {
        msgs.push("p" + game.board.turnPlayer.no + " is the dealer");
    }
    refreshUI();

    if (game.board.isGoshiSuspended) {
        const goshiP = game.board.goshiPlayerNo;
        let redealCount = 0;
        // ai choose first
        for (const p of goshiP.filter((gp) => goita.Util.shiftTurn(gp, 2) !== command.playerNo)) {
            const pName = "p" + (p + 1);
            msgs.push(pName + " has 5 shi");
            refreshUI();
            const decidePlayerName = "p" + (goita.Util.shiftTurn(p, 2) + 1);
            const ret = ai.continueGoshi(game.board.toThinkingInfo());
            if (ret) {
                msgs.push(decidePlayerName + " decided to play");
            } else {
                msgs.push(decidePlayerName + " decided to redeal");
                redealCount++;
            }
            refreshUI();
        }

        if (goshiP.some((gp) => goita.Util.shiftTurn(gp, 2) === command.playerNo)) {
            msgs.push("your partner has 5 shi");
            refreshUI();
            process.stdout.write("do you wish to play?\n");
            Cui.askYesNo((yes) => {
                if (yes) {
                    msgs.push("you decided to play");
                } else {
                    msgs.push("you decided to redeal");
                    redealCount++;
                }

                if (redealCount >= goshiP.length) {
                    game.board.redeal();
                    exitRound();
                } else {
                    game.board.continueGoshi();
                    roundLoop(exitRound);
                }
            });
        } else {
            if (redealCount >= goshiP.length) {
                game.board.redeal();
                exitRound();
            } else {
                game.board.continueGoshi();
//.........这里部分代码省略.........
开发者ID:Goita,项目名称:goita-cli,代码行数:101,代码来源:cli-game.ts


示例3:

 for (const p of goshiP.filter((gp) => goita.Util.shiftTurn(gp, 2) !== command.playerNo)) {
开发者ID:Goita,项目名称:goita-cli,代码行数:1,代码来源:cli-game.ts



注:本文中的goita-core.Util类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript google-maps.load函数代码示例发布时间:2022-05-25
下一篇:
TypeScript gm.default函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap