cards=[[ \๐ก \๐ข \๐ฃ \๐ค \๐ฅ \๐ฆ \๐ง \๐จ \๐ฉ \๐ช \๐ซ \๐ญ \๐ฎ] [ \๐ฑ \๐ฒ \๐ณ \๐ด \๐ต \๐ถ \๐ท \๐ธ \๐น \๐บ \๐ป \๐ฝ \๐พ] [ \๐ \๐ \๐ \๐ \๐
\๐ \๐ \๐ \๐ \๐ \๐ \๐ \๐] [ \๐ \๐ \๐ \๐ \๐ \๐ \๐ \๐ \๐ \๐ \๐ \๐ \๐]]
deck=[[0 0 false ] [0 1 2] [0 2 3] [0 3 4] [0 4 5] [0 5 6] [0 6 7] [0 7 8] [0 8 9] [0 9 10] [0 10 10] [0 11 10] [0 12 10] [1 0 false ] [1 1 2] [1 2 3] [1 3 4] [1 4 5] [1 5 6] [1 6 7] [1 7 8] [1 8 9] [1 9 10] [1 10 10] [1 11 10] [1 12 10] [2 0 false ] [2 1 2] [2 2 3] [2 3 4] [2 4 5] [2 5 6] [2 6 7] [2 7 8] [2 8 9] [2 9 10] [2 10 10] [2 11 10] [2 12 10] [3 0 false ] [3 1 2] [3 2 3] [3 3 4] [3 4 5] [3 5 6] [3 6 7] [3 7 8] [3 8 9] [3 9 10] [3 10 10] [3 11 10] [3 12 10] ]
sdeck=JSON.parse JSON.stringify deck
shuffle = !-> for x,i in deck when (x=Math.floor(Math.random() * (i + 1));true)
[deck[i],deck[x]] = [deck[x],deck[i]]
gid=(id) -> document.getElementById(id)
window.mca=mc=[];window.dca=dc=[];defbet=gid("defbet");m=gid("money");bet=gid("bet");mch=gid("mcards");dch=gid("dcards");l=gid("log")
tod = !-> dc.push (c=deck.pop!); dch.innerHTML+=cards[c[0]][c[1]]
log = (msg)!-> l.innerHTML=msg
window.more = tom = !-> mc.push (c=deck.pop!); mch.innerHTML+=cards[c[0]][c[1]]; summ(mc)>21 and (log "ะะตัะตะฑะพั";gid("e").disabled=true;gid("g").disabled=false)
clear = !->
gid("g").disabled=!(gid("e").disabled=false);log "";bet.innerHTML=0;mch.innerHTML=dch.innerHTML="";mc.length=0;dc.length=0;deck:=JSON.parse JSON.stringify sdeck;shuffle!
window.s=summ = (ar)->
sum=0;tzs=0
for c in ar
(c[2] and sum+=c[2]) or tzs++
for i in [1 to tzs]
(sum+11>21 and sum+=1) or sum+=11
sum
betbet = -> if +m.innerHTML<+defbet.value then log "ะฃ ะฒะฐั ะฝะตั ััะพะปัะบะพ ะดะตะฝะตะณ!"; false else bet.innerHTML=+defbet.value;m.innerHTML-=+defbet.value;true
window.dub = !-> if +m.innerHTML<+bet.innerHTML then log "ะฃ ะฒะฐั ะฝะตั ััะพะปัะบะพ ะดะตะฝะตะณ!" else m.innerHTML-=+bet.innerHTML;bet.innerHTML*=2;tom!
window.give = !-> (clear!; betbet!) and (tom!;tom!;tod!;true) or gid("g").disabled=false;!mc[0][2] and !mc[1][2] and (log "ะั ะฒัะธะณัะฐะปะธ!"; m.innerHTML = +m.innerHTML + +bet.innerHTML*3;gid("e").disabled=true;gid("g").disabled=false)
window.enough = !->
win=true
while summ(dc) < 17
tod!
log if summ(dc)>21 or summ(dc)<summ(mc) then "ะั ะฒัะธะณัะฐะปะธ!" else (win=false; "ะั ะฟัะพะธะณัะฐะปะธ")
gid("g").disabled=false
gid("e").disabled=true
win and m.innerHTML = +m.innerHTML + +bet.innerHTML*2