Revert "Try another smart dealer implementation"
This reverts commit e4e6887e64
.
This commit is contained in:
parent
e4e6887e64
commit
24dbdb9a57
56
board.lua
56
board.lua
@ -44,23 +44,63 @@ function board:init(ruleset)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function board:deal()
|
function board:deal()
|
||||||
local deal=deal(self.ruleset)
|
|
||||||
local n_usable_slots=self.ruleset.n_slots - 1
|
local n_usable_slots=self.ruleset.n_slots - 1
|
||||||
|
-- first, pull the aces
|
||||||
|
local available={}
|
||||||
|
for card=1,#self.ruleset.deck.cards do
|
||||||
|
available[card]=true
|
||||||
|
end
|
||||||
for i=1,#self.ruleset.deck.aces do
|
for i=1,#self.ruleset.deck.aces do
|
||||||
local well=self.wells[i]
|
local well=self.wells[i]
|
||||||
local ace=self.ruleset.deck.aces[i]
|
local ace=self.ruleset.deck.aces[i]
|
||||||
well:add(ace) -- temporarily, so would_accept will work
|
well:add(ace) -- temporarily, so would_accept will work
|
||||||
self:animate_move_ace_to_well(ace,i)
|
self:animate_move_ace_to_well(ace,i)
|
||||||
|
available[ace]=false
|
||||||
end
|
end
|
||||||
|
|
||||||
local rows=#deal[1]
|
local eligible_bottom_row={}
|
||||||
for y=1,rows do
|
for card=1,#self.ruleset.deck.cards do
|
||||||
for x=1,#deal do
|
local skip
|
||||||
local outx=x
|
if not available[card] then
|
||||||
if (x>n_usable_slots\2) outx+=1
|
skip=true
|
||||||
self:animate_move_new_card_to_slot(deal[x][y],outx)
|
else
|
||||||
|
for w in all(self.wells) do
|
||||||
|
if (w:would_accept(card)) skip=true break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
if (not skip) add(eligible_bottom_row,card)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- let the animation install the aces for real
|
||||||
|
for w in all(self.wells) do
|
||||||
|
w:clear()
|
||||||
|
end
|
||||||
|
|
||||||
|
function i_to_slot(i)
|
||||||
|
if (i<n_usable_slots\2) return i+1
|
||||||
|
return i+2
|
||||||
|
end
|
||||||
|
|
||||||
|
local bottom_row={}
|
||||||
|
shuf(eligible_bottom_row)
|
||||||
|
for i=1,n_usable_slots do
|
||||||
|
local card=eligible_bottom_row[i]
|
||||||
|
add(bottom_row,card)
|
||||||
|
available[card]=false
|
||||||
|
end
|
||||||
|
|
||||||
|
eligible={}
|
||||||
|
for card=1,#self.ruleset.deck.cards do
|
||||||
|
if (available[card]) add(eligible,card)
|
||||||
|
end
|
||||||
|
shuf(eligible)
|
||||||
|
for card in all(bottom_row) do
|
||||||
|
add(eligible,card)
|
||||||
|
end
|
||||||
|
for i=1,#eligible do
|
||||||
|
local ix=i_to_slot((i-1)%n_usable_slots)
|
||||||
|
local slot=self.slots[ix]
|
||||||
|
self:animate_move_new_card_to_slot(eligible[i],ix)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
37
dealer.lua
37
dealer.lua
@ -30,7 +30,7 @@ function deal(ruleset)
|
|||||||
if (card and accepts(lst[#lst-1],card)) return pop(lst)
|
if (card and accepts(lst[#lst-1],card)) return pop(lst)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function find_home(prefer_acceptor,card,source,exclude,ignore_acceptorhood)
|
local function find_home(odds,card,source,exclude)
|
||||||
assert(card!=0)
|
assert(card!=0)
|
||||||
local acceptors={}
|
local acceptors={}
|
||||||
local start_points={}
|
local start_points={}
|
||||||
@ -41,20 +41,17 @@ function deal(ruleset)
|
|||||||
-- don't place it here ever
|
-- don't place it here ever
|
||||||
elseif ruleset.deck.instantly_accepted[card] and n==max_height[s]-1 then
|
elseif ruleset.deck.instantly_accepted[card] and n==max_height[s]-1 then
|
||||||
-- can't place an instantly accepted card at the bottom of a slot
|
-- can't place an instantly accepted card at the bottom of a slot
|
||||||
elseif not ignore_acceptorhood and accepts(pek(slots[s]),card) then
|
else
|
||||||
add(acceptors,s)
|
if (accepts(pek(slots[s]),card)) add(acceptors,s)
|
||||||
elseif n<max_height[s] then
|
if (n<max_height[s]) add(start_points,s)
|
||||||
add(start_points,s)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local a
|
local acceptor=rnd(acceptors)
|
||||||
if prefer_acceptor then
|
local start_point=rnd(start_points)
|
||||||
a=rnd(acceptors) or rnd(start_points) or source
|
if (acceptor and rnd()>odds) acceptor=nil
|
||||||
else
|
|
||||||
a=rnd(start_points) or rnd(acceptors) or source
|
|
||||||
end
|
|
||||||
|
|
||||||
|
local a=acceptor or start_point or source
|
||||||
if (a) add(slots[a],card) return true
|
if (a) add(slots[a],card) return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -68,18 +65,22 @@ function deal(ruleset)
|
|||||||
if w <= ruleset.n_suits then
|
if w <= ruleset.n_suits then
|
||||||
local c=pop(slots[0])
|
local c=pop(slots[0])
|
||||||
assert(c!=0)
|
assert(c!=0)
|
||||||
if (c and not find_home(false,c,nil,0)) return
|
if (c and not find_home(1.0,c,nil,0)) return
|
||||||
exclude = 0
|
exclude = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
local card=pop(wells[w])
|
local card=pop(wells[w])
|
||||||
assert(card!=0)
|
assert(card!=0)
|
||||||
if (not find_home(true,card,nil,exclude)) return
|
if (not find_home(1.0,card,nil,exclude)) return
|
||||||
|
|
||||||
local src=flr(rnd()*(#slots+1))
|
local n_moves=48
|
||||||
local card=pop_accepted_card(slots[src])
|
for i=1,n_moves do
|
||||||
if card then
|
local src=flr(rnd()*(#slots+1))
|
||||||
if (not find_home(false,card,src,nil)) return
|
local card=pop_accepted_card(slots[src])
|
||||||
|
if card then
|
||||||
|
local odds=0.0
|
||||||
|
if (not find_home(odds,card,src,nil)) return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -88,7 +89,7 @@ function deal(ruleset)
|
|||||||
for i=0,#slots do
|
for i=0,#slots do
|
||||||
while #slots[i]>max_height[i] do
|
while #slots[i]>max_height[i] do
|
||||||
local card=pop(slots[i])
|
local card=pop(slots[i])
|
||||||
if (not find_home(false,card,nil,nil,true)) return
|
if (not find_home(0.0,card,nil,nil)) return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
1
main.p8
1
main.p8
@ -9,7 +9,6 @@ __lua__
|
|||||||
#include layout.lua
|
#include layout.lua
|
||||||
#include ruleset.lua
|
#include ruleset.lua
|
||||||
#include progression.lua
|
#include progression.lua
|
||||||
#include dealer.lua
|
|
||||||
#include main.lua
|
#include main.lua
|
||||||
__gfx__
|
__gfx__
|
||||||
00000000070000007770000000700000007000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
00000000070000007770000000700000007000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
13
ruleset.lua
13
ruleset.lua
@ -32,19 +32,17 @@ function ruleset:init(
|
|||||||
local usable_slots = n_slots - 1
|
local usable_slots = n_slots - 1
|
||||||
assert(usable_slots%2==0)
|
assert(usable_slots%2==0)
|
||||||
|
|
||||||
local n_total_cards = n_arcana + n_suits * n_cards_per_suit
|
local total_n_cards = n_arcana + n_suits * n_cards_per_suit
|
||||||
-- aces aren't usable because they are initially placed in the wells
|
-- aces aren't usable because they are initially placed in the wells
|
||||||
local n_usable_cards = n_total_cards - self.n_suits
|
local usable_n_cards = total_n_cards - self.n_suits
|
||||||
|
|
||||||
-- deal has to be symmetrical
|
-- deal has to be symmetrical
|
||||||
assert(n_usable_cards % usable_slots == 0, usable_slots-(n_usable_cards%usable_slots))
|
assert(usable_n_cards % usable_slots == 0, usable_slots-(usable_n_cards%usable_slots))
|
||||||
|
|
||||||
-- these cards would be instantly moved to the wells and
|
-- these cards would be instantly moved to the wells and
|
||||||
-- therefore cannot be in the bottom row
|
-- therefore cannot be in the bottom row
|
||||||
local instantly_placed_cards = self.n_suits + 2
|
local instantly_placed_cards = self.n_suits + 2
|
||||||
assert((n_total_cards-instantly_placed_cards)-usable_slots >= 0)
|
assert((total_n_cards-instantly_placed_cards)-usable_slots >= 0)
|
||||||
|
|
||||||
self.n_usable_cards = n_usable_cards
|
|
||||||
|
|
||||||
self:generate_deck()
|
self:generate_deck()
|
||||||
self:generate_layouts()
|
self:generate_layouts()
|
||||||
@ -57,7 +55,6 @@ function ruleset:generate_deck()
|
|||||||
aces={},
|
aces={},
|
||||||
suits={},
|
suits={},
|
||||||
cards={},
|
cards={},
|
||||||
instantly_accepted={},
|
|
||||||
rank_name="a23456789tjqk"
|
rank_name="a23456789tjqk"
|
||||||
}
|
}
|
||||||
self.deck=deck
|
self.deck=deck
|
||||||
@ -70,14 +67,12 @@ function ruleset:generate_deck()
|
|||||||
for rank=1,self.n_cards_per_suit do
|
for rank=1,self.n_cards_per_suit do
|
||||||
add(deck.cards,{suit=suit,rank=rank})
|
add(deck.cards,{suit=suit,rank=rank})
|
||||||
if (rank==1) add(deck.aces,#deck.cards)
|
if (rank==1) add(deck.aces,#deck.cards)
|
||||||
if (rank==2) deck.instantly_accepted[#deck.cards]=true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- arcana
|
-- arcana
|
||||||
for rank=0,self.n_arcana-1 do
|
for rank=0,self.n_arcana-1 do
|
||||||
add(deck.cards,{suit="a",rank=rank})
|
add(deck.cards,{suit="a",rank=rank})
|
||||||
if (rank==0 or rank==self.n_arcana-1) deck.instantly_accepted[#deck.cards]=true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function deck:draw_card(x,y,c,shadow)
|
function deck:draw_card(x,y,c,shadow)
|
||||||
|
Loading…
Reference in New Issue
Block a user