2016-10-18 22 views
0

我試圖在JavaScript中創建德克薩斯撲克(使用節點和mongodb服務器雙面)。JavaScript的德克薩斯撲克數據庫

但我目前堅持如何構建數據庫。

這是我走到這一步:

player1 - player9 = userid 

意味着一個名爲PLAYER1高達player9一路列中,將包含一個用戶ID。如果沒有,則將爲0

player 1cash- player 9cash 表示稱爲player1的列一直到player9,其將包含桌上數字現金(在用戶面前)。如果沒有,則將是0

player 1cards- player 9cards 表示稱爲player1的列一直到player9,其將包含桌上的兩張牌(在用戶面前)。如果沒有,將0

maxbet : Number 

將在

smallblind : userid // contains userid of small blind 
bigblind : userid // contains high 
blindamount : Number // amount 

cards_on_table的MAXBET /最大團購://包含表

所有的牌。如果我對這個進行,它會每場比賽31欄。

我該如何讓這個數據庫交互更好,或者將我的db結構改爲更好的東西?

+0

「我該如何做得更好」 - 你認爲這個不好嗎? –

+0

是的,我覺得IT可以做得更好@SergioTulentsev – maria

+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在他的評論中提到,根據您需要提取的信息優化您的數據模型非常重要。因此,根據應用程序需求,您必須在數據模型和查詢訪問模式之間找到平衡,以優化性能。

+0

你在翻牌圈,轉牌圈和河牌圈是什麼意思?) – maria

+0

'flop'是在Texas Hold'Em遊戲中,前三張牌被放在桌子上,下一張牌被稱爲'turn',最後一張牌被稱爲'river':) https://en.wikipedia.org/wiki/Texas_hold_% 27em –

+0

你有時間聊聊@Vlad Z. – maria