1- local function getCardValue (card )
1+ local function get_value (card )
22 if card == ' J' then
33 return 1
44 elseif card == ' Q' then
@@ -12,15 +12,15 @@ local function getCardValue(card)
1212 end
1313end
1414
15- local function simulateGame (playerA , playerB )
15+ local function simulate_game (playerA , playerB )
1616 local handA = {}
1717 for _ , card in ipairs (playerA ) do
18- table.insert (handA , getCardValue (card ))
18+ table.insert (handA , get_value (card ))
1919 end
2020
2121 local handB = {}
2222 for _ , card in ipairs (playerB ) do
23- table.insert (handB , getCardValue (card ))
23+ table.insert (handB , get_value (card ))
2424 end
2525
2626 local turn = ' A'
@@ -58,36 +58,34 @@ local function simulateGame(playerA, playerB)
5858 else
5959 turn = ' A'
6060 end
61- else
62- if currentDebt > 0 then
63- currentDebt = currentDebt - 1
64- if currentDebt == 0 then
65- for _ , p in ipairs (pile ) do
66- table.insert (otherHand , p )
67- end
68- pile = {}
69- totalTricks = totalTricks + 1
70- currentDebt = 0
71-
72- if # handA == 0 or # handB == 0 then
73- return { status = ' finished' , tricks = totalTricks , cards = cardsPlayed }
74- end
61+ elseif currentDebt > 0 then
62+ currentDebt = currentDebt - 1
63+ if currentDebt == 0 then
64+ for _ , p in ipairs (pile ) do
65+ table.insert (otherHand , p )
66+ end
67+ pile = {}
68+ totalTricks = totalTricks + 1
69+ currentDebt = 0
7570
76- if turn == ' A' then
77- turn = ' B'
78- else
79- turn = ' A'
80- end
71+ if # handA == 0 or # handB == 0 then
72+ return { status = ' finished' , tricks = totalTricks , cards = cardsPlayed }
8173 end
82- else
74+
8375 if turn == ' A' then
8476 turn = ' B'
8577 else
8678 turn = ' A'
8779 end
8880 end
81+ else
82+ if turn == ' A' then
83+ turn = ' B'
84+ else
85+ turn = ' A'
86+ end
8987 end
9088 end
9189end
9290
93- return { simulateGame = simulateGame }
91+ return { simulate_game = simulate_game }
0 commit comments