牌山生成プログラム
どうも、僕です。
牌山生成プログラムを公開します。
山クラス
public class Wall
{
public static int TileSize = 136;
Tile wall = new Tile[TileSize];
int drawIndex = 0;
public Wall(int seed, int diceNumber, bool 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 = 0; i < 4; i++) {
tmpWall[tileIndex] = new Tile(0, useRed && i == 0 ? true : false, tileType);
tileIndex++;
}
}
}
// 洗牌
for (int i = 0; i < 8; i++) {
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 = 0; i < TileSize; i++) {
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 = 1, C2 = 2, C3 = 3, C4 = 4, C5 = 5, C6 = 6, C7 = 7 , C8 = 8, C9 = 9,
B1 = 21, B2 = 22, B3 = 23, B4 = 24, B5 = 25, B6 = 26, B7 = 27, B8 = 28, B9 = 29,
D1 = 41, D2 = 42, D3 = 43, D4 = 44, D5 = 45, D6 = 46, D7 = 47, D8 = 48, D9 = 49,
East = 61, South = 69, West = 81, North = 89,
White = 101, Green = 109, Red = 121
}
}
リリースまでに変更があるかもしれませんが。。。
もし、プログラムとしておかしい部分があればコメントいただけると助かります。