fortunes_foundation/ruleset.lua

159 lines
3.7 KiB
Lua
Raw Normal View History

2024-02-05 06:11:17 +00:00
ruleset=klass()
function ruleset:init(
-- Number of unlocked slots (up to 11)
-- Includes the one in the middle
-- For Fortune's Foundation: 11
n_slots,
-- Number of suits (up to 5)
-- This is also the number of RHS wells
-- For Fortune's Foundation: 4
n_suits,
-- Number of cards per suit (up to 13)
-- For Fortune's Foundation: 13
n_cards_per_suit,
-- Number of arcana (unbounded)
-- For Fortune's Foundation: 22
2024-02-10 03:21:47 +00:00
n_arcana,
pool
2024-02-05 06:11:17 +00:00
)
self.n_slots=n_slots
self.n_suits=n_suits
self.n_cards_per_suit=n_cards_per_suit
self.n_arcana=n_arcana
2024-02-10 03:21:47 +00:00
self.pool=pool
2024-02-05 06:11:17 +00:00
assert(self.n_slots<=11)
assert(self.n_suits<=5)
assert(self.n_cards_per_suit<=13)
assert(self.n_arcana<=99)
-- the middle slot is always auxiliary in
-- Fortune's Foundation-style games
local usable_slots = n_slots - 1
assert(usable_slots%2==0)
local n_total_cards = n_arcana + n_suits * n_cards_per_suit
2024-02-05 06:11:17 +00:00
-- aces aren't usable because they are initially placed in the wells
local n_usable_cards = n_total_cards - self.n_suits
self.n_total_cards=n_total_cards
self.n_usable_cards=n_usable_cards
2024-02-05 06:11:17 +00:00
-- deal has to be symmetrical
assert(n_usable_cards % usable_slots == 0, usable_slots-(n_usable_cards%usable_slots))
2024-02-05 06:11:17 +00:00
-- these cards would be instantly moved to the wells and
-- therefore cannot be in the bottom row
local instantly_placed_cards = self.n_suits + 2
assert((n_total_cards-instantly_placed_cards)-usable_slots >= 0)
2024-02-05 06:11:17 +00:00
self:generate_deck()
self:generate_layouts()
end
function ruleset:generate_deck()
local ruleset=self
2024-02-09 00:41:40 +00:00
local possible_suits={"c","s","p","w","b"}
2024-02-05 06:11:17 +00:00
local deck={
aces={},
suits={},
cards={},
instantly_accepted={},
2024-02-05 06:11:17 +00:00
rank_name="a23456789tjqk"
}
self.deck=deck
for i=1,self.n_suits do
add(deck.suits,possible_suits[i])
end
-- suited cards
for suit in all(deck.suits) do
for rank=1,self.n_cards_per_suit do
add(deck.cards,{suit=suit,rank=rank})
if (rank==1) add(deck.aces,#deck.cards)
if (rank==2) deck.instantly_accepted[#deck.cards]=true
2024-02-05 06:11:17 +00:00
end
end
-- arcana
for rank=0,self.n_arcana-1 do
add(deck.cards,{suit="a",rank=rank})
if (rank==0 or rank==self.n_arcana-1) deck.instantly_accepted[#deck.cards]=true
2024-02-05 06:11:17 +00:00
end
2024-02-10 05:43:01 +00:00
function deck:draw_card(x,y,c)
2024-02-05 06:11:17 +00:00
local meta=deck.cards[c]
local is_extreme=meta.rank==0 or meta.rank==ruleset.n_arcana-1
local s,fg
2024-02-10 05:43:01 +00:00
local bg
2024-02-09 00:41:40 +00:00
if meta.suit=='a' or meta.suit=='b' then
2024-02-10 05:43:01 +00:00
bg=1
if (is_extreme) bg=15
2024-02-05 06:11:17 +00:00
else
2024-02-10 05:43:01 +00:00
bg=7
2024-02-05 06:11:17 +00:00
end
2024-02-10 05:43:01 +00:00
rectfill(x,y,x+8,y+15,bg)
2024-02-05 06:11:17 +00:00
if (meta.suit=='p') s,fg=0,4
if (meta.suit=='s') s,fg=1,12
if (meta.suit=='c') s,fg=2,2
if (meta.suit=='w') s,fg=3,3
2024-02-08 21:12:34 +00:00
if (meta.suit=='b') s,fg=4,14
2024-02-05 06:11:17 +00:00
if (meta.suit=='a') fg=15
if meta.suit=='a' then
local rank=""..meta.rank
pal(7,15)
2024-02-09 00:41:40 +00:00
if (is_extreme) pal(7,1)
2024-02-05 06:11:17 +00:00
print(meta.rank,x+5-#rank*2,y+1,7)
spr(5,x,y+8)
pal()
else
local name=sub(deck.rank_name,meta.rank,meta.rank)
2024-02-09 00:41:40 +00:00
local x2=x
if (meta.suit=='b') x2+=1
2024-02-05 06:11:17 +00:00
rectfill(x,y,x+3,y+6,fg)
2024-02-09 00:41:40 +00:00
print(name,x2,y+1,bg)
2024-02-05 06:11:17 +00:00
pal(7,fg)
2024-02-09 00:41:40 +00:00
spr(s,x+4,y)
2024-02-10 05:43:01 +00:00
spr(15+meta.rank,x,y+8)
2024-02-05 06:11:17 +00:00
pal()
end
return fg
end
end
function ruleset:generate_layouts()
local layouts={}
self.layouts=layouts
local ruleset=self
local width=ruleset.n_slots*10
local x=(128-width)\2
function layouts:well(i)
if i<=ruleset.n_suits then
local wx=width-ruleset.n_suits*10+(i-1)*10
return layout:new(x+wx,1,layout_mode.obscured)
end
i-=ruleset.n_suits
if (i==1) return layout:new(x,1,layout_mode.obscured)
if (i==2) return layout:new(x+10,1,layout_mode.obscured)
assert(false,"unknown well")
end
function layouts:slot(i)
if i<=ruleset.n_slots then
local sx=(i-1)*10
return layout:new(x+sx,18,layout_mode.vertical)
end
if (i==ruleset.n_slots+1) return layout:new(x+width-ruleset.n_suits*5-5,1,layout_mode.obscured)
assert(false, "unknown slot")
end
end