workign behind schedule, but here's today's set of functions:
REM INITIALISATION CODE to go at start of every project
`////////////////////////////////////////////////////////////
global mems as byte
mems=2
type packstype
memadress as dword
cards as byte
endtype
dim packs(-1) as packstype
dim decks(-1) as packstype
dim hands(-1) as packstype
`/////////////////////////////////////////////////////////////
function makepack(jokers)
add to queue packs()
pack=array count(packs())
make memblock mems,52+jokers
packs(pack).memadress=mems
packs(pack).cards=52+jokers
for t = 1 to 52+jokers
s=t-1
r=t
if r>52 then r = 53
write memblock byte mems,s,r
next t
inc mems
endfunction pack
function makedeck()
add to queue decks()
deck=array count(decks())
decks(deck).cards=0
decks(deck).memadress=mems
inc mems
endfunction deck
function copypacktodeck(pack,deck)
initcards=decks(deck).cards
endcards=decks(deck).cards+packs(pack).cards
initmem=decks(deck).memadress
packmem=packs(pack).memadress
packcards=packs(pack).cards
make memblock 1,endcards
if initcards>0
for t = 0 to initcards-1
write memblock byte 1,t,memblock byte(initmem,t)
next t
endif
for t = 0 to packcards-1
write memblock byte 1,t+initcards,memblock byte(packmem,t)
next t
if memblock exist(initmem) then delete memblock initmem
make memblock initmem,endcards
copy memblock 1,initmem,0,0,endcards
decks(deck).cards=endcards
delete memblock 1
endfunction
function shuffledeck(deck,factor)
randomize timer()
for t = 1 to factor
carda=rnd(decks(deck).cards-1)
cardb=rnd(decks(deck).cards-1)
cardc=memblock byte(decks(deck).memadress,carda)
cardd=memblock byte(decks(deck).memadress,cardb)
write memblock byte decks(deck).memadress,carda,cardd
write memblock byte decks(deck).memadress,cardb,cardc
next t
endfunction
function makehand()
add to queue hands()
hand=array count(hands())
hands(hand).cards=0
hands(hand).memadress=mems
`print mems
`wait key
inc mems
endfunction hand
function removefromdeck(deck,slot)
adr=decks(deck).memadress
initcards=decks(deck).cards
endcards=initcards-1
card=memblock byte(adr,slot)
make memblock 1,endcards
for t=0 to initcards-1
if t<slot
write memblock byte 1,t,memblock byte(adr,t)
endif
if t>slot
write memblock byte 1,t-1,memblock byte(adr,t)
endif
next t
delete memblock adr
make memblock adr,endcards
copy memblock 1,adr,0,0,endcards
delete memblock 1
decks(deck).cards=endcards
decks(deck).memadress=adr
endfunction card
function addtodeck(card,deck,slot)
adr=decks(deck).memadress
initcards=decks(deck).cards
endcards=initcards+1
make memblock 1,endcards
for t=0 to endcards-1
if t<slot
write memblock byte 1,t,memblock byte(adr,t)
endif
if t=slot then write memblock byte 1,t,card
if t>slot
write memblock byte 1,t,memblock byte(adr,t-1)
endif
next t
delete memblock adr
make memblock adr,endcards
copy memblock 1,adr,0,0,endcards
delete memblock 1
decks(deck).cards=endcards
decks(deck).memadress=adr
endfunction
function removefrompack(pack,slot)
adr=packs(pack).memadress
initcards=packs(pack).cards
endcards=initcards-1
card=memblock byte(adr,slot)
make memblock 1,endcards
for t=0 to initcards-1
if t<slot
write memblock byte 1,t,memblock byte(adr,t)
endif
if t>slot
write memblock byte 1,t-1,memblock byte(adr,t)
endif
next t
delete memblock adr
make memblock adr,endcards
copy memblock 1,adr,0,0,endcards
delete memblock 1
packs(pack).cards=endcards
packs(pack).memadress=adr
endfunction card
function addtopack(card,pack,slot)
adr=packs(pack).memadress
initcards=packs(pack).cards
endcards=initcards+1
make memblock 1,endcards
for t=0 to endcards-1
if t<slot
write memblock byte 1,t,memblock byte(adr,t)
endif
if t=slot then write memblock byte 1,t,card
if t>slot
write memblock byte 1,t,memblock byte(adr,t-1)
endif
next t
delete memblock adr
make memblock adr,endcards
copy memblock 1,adr,0,0,endcards
delete memblock 1
packs(pack).cards=endcards
packs(pack).memadress=adr
endfunction
function removefromhand(hand,slot)
adr=hands(hand).memadress
initcards=hands(hand).cards
endcards=initcards-1
card=memblock byte(adr,slot)
make memblock 1,endcards
for t=0 to initcards-1
if t<slot
write memblock byte 1,t,memblock byte(adr,t)
endif
if t>slot
write memblock byte 1,t-1,memblock byte(adr,t)
endif
next t
delete memblock adr
make memblock adr,endcards
copy memblock 1,adr,0,0,endcards
delete memblock 1
hands(hand).cards=endcards
hands(hand).memadress=adr
endfunction card
function addtohand(card,hand,slot)
adr=hands(hand).memadress
`print adr
`wait key
initcards=hands(hand).cards
endcards=initcards+1
make memblock 1,endcards
for t=0 to endcards-1
if t<slot
write memblock byte 1,t,memblock byte(adr,t)
endif
if t=slot then write memblock byte 1,t,card
if t>slot
write memblock byte 1,t,memblock byte(adr,t-1)
endif
next t
if memblock exist(adr) then delete memblock adr
make memblock adr,endcards
copy memblock 1,adr,0,0,endcards
delete memblock 1
hands(hand).cards=endcards
hands(hand).memadress=adr
endfunction
function cardID(number,suit)
card=number+(suit-1)*13
endfunction card
function suit(card)
suit=1
if card>13 then suit=2
if card>26 then suit=3
if card>39 then suit=4
if card>52 then suit=5
endfunction suit
function value(card)
number=card
if card>13 then number=card-13
if card>26 then number=card-26
if card>39 then number=card-39
if card=53 then number=14
endfunction number
function lowestinhand(low,hand) `low is lowest pos allowed, ie, if aces are high then low=2
print "hand ";hand
adr=hands(hand).memadress
print "adr ";adr
cards=hands(hand).cards
print "cards ";cards
lowest=15
for t=1 to cards
card=memblock byte(adr,t-1)
if value(card)>=low
if value(card)<lowest then lowest=value(card)
endif
next t
endfunction lowest
should be pretty self explanatory for now. i'll write a full tutorial once the whole thing's done. 99% certain the code is bug free, i had a massive bug squashing spree today and i ran out of bugs, though there may be one or two lurking somewhere.
brief tutorial:
cards work numerical as 1-53. clubs are 1-13, diamonds are 14-26, hearts are 27-39 and spades 40-52. jokers are numbered 14 and are of the magical suit number 5.
also, you'll notice that decks, hands and packs all have similar codes. this is because they are handled in a very similar way, essentially, they're just named differently to make them easier to work with.
to get started; you'll need to make a pack. once you've made a pack, you put this into a deck. i adopted this system because some game require two or more packs, or a pack to be added mid-game.
by tomorrow night i should have some more basic functions, some gui functions (converting numbers in memory to cards on the screen) and also an example demo (if anyone knows of an alternative name for the game "sh*thead" please tell me)
ttfn