ゲームクリエイターの呟き@ゲームプログラマ

オンライン麻雀の製作過程を気ままに書いていきます。

牌山生成プログラム

どうも、僕です。

 

牌山生成プログラムを公開します。

 

山クラス

public class Wall
{
    public static int TileSize = 136;

    Tile wall = new Tile[TileSize];

    int drawIndex = 0;

    public Wall(int seedint diceNumberbool useRed = true) {
        var random = new Random(seed);
        Tile tmpWall = new Tile[TileSize];
        var tileIndex = 0;
        foreach (Tile.Type tileType in Enum.GetValues(typeof(Tile.Type)))
        {
            if (tileType != Tile.Type.None) {
                for (int i = 0i < 4i++) {
                    tmpWall[tileIndex= new Tile(0useRed && i == 0 ? true : false,  tileType);
                    tileIndex++;
                }
            }
        }
        // 洗牌
        for (int i = 0i < 8i++) {
            var n = tmpWall.Length;
            while (n > 1) {
                n--;
                var k = random.Next(n + 1);
                var tmp = tmpWall[k];
                tmpWall[k= tmpWall[n];
                tmpWall[n= tmp;
            }
        }
        // 山を分ける
        var startWall = (5 - diceNumber % 4% 4;
        var startTileIndex = startWall * 17 * 2 + diceNumber * 2;
        for (int i = 0i < TileSizei++) {
            wall[i= startTileIndex + i >= TileSize ? tmpWall[startTileIndex + i - TileSize: tmpWall[startTileIndex + i];
        }
        // ツモ位置を初期化
        drawIndex = 0;
    }

    // ツモ
    public Tile Draw() {
        var draw = wall[drawIndex];
        drawIndex++;
        return draw;
    }
}

 

牌列挙型

public class Tile
{
    // Characters マンズ
    // Bamboo 索子
    // Dots 筒子
    public enum Type : int {
        None = 0,
        C1 = 1C2 = 2C3 = 3C4 = 4C5 = 5C6 = 6C7 = 7 , C8 = 8C9 = 9,
        B1 = 21B2 = 22B3 = 23B4 = 24B5 = 25B6 = 26B7 = 27B8 = 28B9 = 29,
        D1 = 41D2 = 42D3 = 43D4 = 44D5 = 45D6 = 46D7 = 47D8 = 48D9 = 49,
        East = 61South = 69West = 81North = 89,
        White = 101Green = 109Red = 121
    }
}

 

リリースまでに変更があるかもしれませんが。。。

 

もし、プログラムとしておかしい部分があればコメントいただけると助かります。