トランプモジュール

HSPでトランプのモジュール型変数を作って適当に配る

HSPでトランプのモジュール型変数を作って適当に配る

  • タグ:
  • hsp
#runtime "hsp3cl"
#cmpopt varinit 1

#module TrumpCard name,power,suit
	#modinit str _name,int _power,int _suit
		name=_name
		power=_power
		suit=_suit
	return

	#modcfunc tcName
		return name
	#modcfunc tcPower
		return power
	#modcfunc tcSuit
		return suit
#global

#module Trump deck,iter,countMax,hash
	#define new(%1) dimtype %1,5:newmod %1,Trump
	#modinit
		randomize
		#define deckDefine names= \
				"SA","S2","S3","S4","S5","S6","S7","S8","S9","S10","SJ","SQ","SK", \
				"HA","H2","H3","H4","H5","H6","H7","H8","H9","H10","HJ","HQ","HK", \
				"CA","C2","C3","C4","C5","C6","C7","C8","C9","C10","CJ","CQ","CK", \
				"DA","D2","D3","D4","D5","D6","D7","D8","D9","D10","DJ","DQ","DK", \
				"JK","jk" :\
			powers= \
				1,2,3,4,5, 6,7,8,9,10, 11,12,13, \
				1,2,3,4,5, 6,7,8,9,10, 11,12,13, \
				1,2,3,4,5, 6,7,8,9,10, 11,12,13, \
				1,2,3,4,5, 6,7,8,9,10, 11,12,13, \
				0,0 :\
			suits= \
				1,1,1,1,1, 1,1,1,1,1, 1,1,1, \
				2,2,2,2,2, 2,2,2,2,2, 2,2,2, \
				3,3,3,3,3, 3,3,3,3,3, 3,3,3, \
				4,4,4,4,4, 4,4,4,4,4, 4,4,4, \
				0,0
		deckDefine
		foreach names
			newmod deck,TrumpCard,names(cnt),powers(cnt),suits(cnt)
		loop
		foreach deck
			hash(cnt)=cnt
		loop
		count=length(deck)
		repeat count
			r=rnd(count)
			tmp=hash(cnt)
			hash(cnt)=hash(r)
			hash(r)=tmp
		loop
		itr=0
	return

	#modcfunc trpCount
		return count

	#modfunc local trpNext var card
		card=deck(hash(iter))
		iter++
	return
	#define global trpNext(%1,%2) dimtype %2,5:trpNext@Trump %1,%2
#global

new@Trump trp
repeat trpCount(trp)
	i=cnt/4
	trpNext trp,card
	if cnt\4=0 {
		p1(i)=card
	}
	else:if cnt\4=1 {
		p2(i)=card
	}
	else:if cnt\4=2 {
		p3(i)=card
	}
	else:if cnt\4=3 {
		p4(i)=card
	}
loop

mes "【Player 1】"
foreach p1
	mes tcName(p1.cnt)+",",1
loop

mes "\n【Player 2】"
foreach p2
	mes tcName(p2.cnt)+",",1
loop

mes "\n【Player 3】"
foreach p3
	mes tcName(p3.cnt)+",",1
loop

mes "\n【Player 4】"
foreach p4
	mes tcName(p4.cnt)+",",1
loop

mes ""