當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript goita-core.Util類代碼示例

本文整理匯總了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;未經允許,請勿轉載。