---
# System prepended metadata

title: Debug 用測試碼
tags: [遊戲筆記]

---

# Debug 用測試碼

```javascript=
    function showCardIndex(): void {
        let template: any[][] = [];
        template["♠"] = []; // ♠
        template["♥"] = []; // ♥
        template["♦"] = []; // ♦
        template["♣"] = []; // ♣

        for (let i = 1; i <= 13; ++i) template["♠"].push(i);
        for (let i = 1; i <= 13; ++i) template["♥"].push(13 + i);
        for (let i = 1; i <= 13; ++i) template["♣"].push(13 * 2 + i);
        for (let i = 1; i <= 13; ++i) template["♦"].push(13 * 3 + i);

        // 使用方式
        let player1 = ("♣K ♠J ♠10 ♥10 ♦10 ♥9 ♠9 ♥8 ♦8 ♠8 ♣8 ♥7 ♣6 ♥4 ♥3 ♠3").split(" ");
        let player2 = ("♣A ♥A ♥K ♠K ♦K ♦Q ♥J ♣J ♣9 ♦9 ♠7 ♥5 ♠5 ♠4 ♦4 ♣4").split(" ");
        let player3 = ("♠2 ♦A ♥Q ♣Q ♠Q ♦J ♣10 ♦7 ♣7 ♦6 ♠6 ♥6 ♣5 ♦5 ♦3 ♣3").split(" ");

        console.log(converter(player1, template));
        console.log(converter(player2, template));
        console.log(converter(player3, template));
    }

    function converter(input: string[], template: any[][]): string {
        let result = input.map(card => {
            let list = template[card[0]];
            let value = 0;
            if (card.slice(1) == "J") value = 10;
            else if (card.slice(1) == "Q") value = 11;
            else if (card.slice(1) == "K") value = 12;
            else if (card.slice(1) == "A") value = 13;
            else value = parseInt(card.slice(1)) - 1;
            return list[value - 1];
        });
        return `[${result.join(",")}]`;
    }

    showCardIndex();

```

###### tags: `遊戲筆記`