Javascript德州扑克数据库

时间:2016-10-18 06:54:30

标签: javascript mongodb database

我试图在javascript中创建texas holdem(使用节点和mongodb服务器端)。

但我目前仍然坚持如何构建数据库。

这是我到目前为止所得到的:

player1 - player9 = userid

表示一个名为player1的列,一直到player9,它将包含一个用户ID。如果没有,将是0

player 1cash- player 9cash  表示一个名为player1的列,一直到player9,它将包含一个数字现金(在用户面前)。如果没有,将是0

player 1cards- player 9cards  表示一个名为player1的列,一直到player9,它将包含两张牌(在用户面前)。如果没有,将是0

maxbet : Number

将是

中的maxbet / max买入
smallblind : userid // contains userid of small blind
bigblind : userid // contains high
blindamount : Number // amount

cards_on_table://包含表格中的所有卡片

如果我继续这样做,每场比赛将有31列。

如何更好地进行数据库交互,或者将我的数据库结构更改为更好的内容?

1 个答案:

答案 0 :(得分:1)

您可以更好地利用MongoDB的面向文档的体系结构,允许您使用对象,而不是尝试在MongoDB中强制使用关系模型(面向列,可以在单值字段中进行转换,从您的描述中可以理解)。在您的架构中:

{
    _id: ObjectId("5805d576adf2ac885283779a"),

    // Name of the room
    room_name: 'Hold Them Up',

    // When the room was created
    created_at: ISODate("2016-10-18T08:04:17.611Z"),

    // The uptime of the room in seconds or any other unit    
    uptime: 2000,

    // You could organize this as an object that contains values for
    // each of the turning phases of the game to allow for better analytics
    current_table_cards: {
        flop: ["A", "B", "C"],
        turn: "D",
        river: "E"
    },

    // You could also keep track of previous table cards
    table_cards_history: [
        {
            flop: ["A", "B", "C"],
            turn: "D",
            river: "E"
        },
        {
            flop: ["E", "D", "C"],
            turn: "B",
            river: "A"
        },
        ...

    ],

    // You could use an array to store the players that are currently playing
    // and save a history of their previous 5 hands for example
    //
    // To track the order of the players, you can either manipulate this array
    // and consider the indices the order of the players, or you could define
    // an order property on the objects inside this array
    players: [
        {
            user_id: ObjectId("5805d576adf2ac8852837791"),
            cash_amount: 3201,
            position: 2,
            win: 1,
            loss: 0,
            current_hand: ["E", "F"],
            hands_history: [
                ["A", "B"],
                ["A", "A"],
                ...
            ]
        },
        {
            user_id: ObjectId("5805d576adf2ac8852837792"),
            cash_amount: 4288,
            position: 1,
            win: 2,
            loss: 1,
            current_hand: ["C", "D"],
            hands_history: [
                ["A", "E"],
                ["B", "B"],
                ...
            ]
        },
        {
            user_id: ObjectId("5805d576adf2ac8852837793"),
            cash_amount: 2531,
            position: 3,
            win: 0,
            loss: 2,
            current_hand: ["A", "B"],
            hands_history: [
                ["D", "D"],
                ["C", "C"],
                ...
            ]
        },
        ...
    ],

    // Blind information
    small_blind: ObjectId("5805d576adf2ac8852837792"),
    big_blind: ObjectId("5805d576adf2ac8852837791"),
    blind_amount: 100
}

这只是您的应用程序的初始模型,最终可能会有更多字段,具体取决于您要为每个房间和播放器跟踪的信息。

例如,您可能希望跟踪玩家的平均投注金额,或者可以设置盲注更改时间的计时器。但是,这超出了这个问题的范围,并且是一个不同的讨论。

此外,正如 Sergio Tulentsev 在其评论中提到的,根据您需要提取的信息优化数据模型非常重要。因此,根据应用程序要求,您必须在数据模型和查询访问模式之间找到平衡点,以便优化性能。