--main function 
--can return "exit"
function game()
	--the first time, place everything, but don't show cards (face down)
	--this is unneeded work as when starting a new game this will
	--be executed again but...
	--mainDeck=prepareMainDeck()
	fdebug("when starting main deck has "..tableLength(mainDeck).." cards")
	shuffleMainDeck()
	distributeCards()
	orderHands()
	disposePlayersAroundTheTable()
	positionAllCards()
	hideCardsOfPlayerNum(1) --other players have the cards already face down
	
	--init vars used to make the game progress
	activePlayer=1 --magic number :)
	findNextPlayer=false
	numberOfCardsPlayed=0
	powerOfCardsPlayed=NOVALUE
	waitingTurn=false
	nbPlayersInGame=0
	nbRanksAvailable=4
	ranks={}
	ranks[4]="president"
	ranks[3]="vice president"
	ranks[2]="vice asshole"
	ranks[1]="asshole"
	playEvent=false
	aGameIsRunning=false
	
	totalScore=0
	roundScore=0
	handScore=0
	previousRank="neutral"
	
	
	drawScene(screen, false)

	local loopNum=1
	
	--the first time, open automaticaly the main menu
	local openMenu=true

	--the main loop
	while true do
		updateInputs(Controls.read())
		if openMenu or inputFirstPress("start") then
			openMenu=false
			local mmchoice=openMainMenu() --return can be: quitMenu cancel exit newGame
			GC()
			drawScene(screen, false) --TODO: do it everytime?
			if mmchoice=="exit" then
				return "exit"
			elseif mmchoice=="newGame" then
				startNewGame()
				fdebug("in main loop after new game")
			elseif mmchoice=="newNeutralGame" then
				startNewGame(true)
				fdebug("in main loop after new neutral game")
			end
		end
		
		if inputFirstPress("select") then
			snapshot()
		end
		
		if aGameIsRunning then
			--fdebug("a game is running")
			playEvent=getPlayEvent(inputAnalogIsTouched() or inputIsPressed("triangle"), players[1].state=="finished")
	   	
		   	--2 cases: it's the turn of the user or of the AI
		   	--turn of the user
		   	if activePlayer==1 and playEvent then--first loop for the turn of the user, place everything
		   		if findNextPlayer==false then
			   		if handSize(1)==0 then
			   		
			   			local whatToSay=nil
			   			if ranks[nbRanksAvailable]=="president" then
			   				whatToSay=getRandomSpeech("getPresident")
			   			elseif ranks[nbRanksAvailable]=="vice president" then
			   				whatToSay=getRandomSpeech("getVicePresident")
			   			elseif ranks[nbRanksAvailable]=="vice asshole" then
			   				whatToSay=getRandomSpeech("getViceAsshole")
			   			end
			   			say("bottom", whatToSay)
			   		
			   			powerOfCardsPlayed=NOVALUE
			   			numberOfCardsPlayed=0
			   			cleanTableDeck()
			   			players[1].state="finished"
			   			players[1].rank=ranks[nbRanksAvailable]
			   			nbRanksAvailable=nbRanksAvailable-1
			   			findNextPlayer=true
			   			
			   			handScore=calculateHandScore(players[2].hand)+calculateHandScore(players[3].hand)+calculateHandScore(players[4].hand)
			   			
			   			stopGameIfNeeded()
			   		--trump is there since last event
			   		elseif powerOfCardsPlayed==TRUMP then
			   			powerOfCardsPlayed=NOVALUE
			   			numberOfCardsPlayed=0
			   			cleanTableDeck()
			   			putEveryoneWhoPassedInGameAgain()
			   		end   		
		   		end
		   		
		   		--detect end of round or end of game
		   		--end of round?
		   		nbPlayersInGame=getNbPlayersInGame()
		   		--debugForced("nbPlayersInGame="..nbPlayersInGame)
		   		if nbPlayersInGame==1 then
		   			powerOfCardsPlayed=NOVALUE
		   			numberOfCardsPlayed=0
		   			cleanTableDeck()
		   			putEveryoneWhoPassedInGameAgain()
		   			say("bottom", getRandomSpeech("winRound"))
		   			
		   			totalScore=totalScore+roundScore
		   			--showMessageBox("add "..roundScore.." to total and put at 0")
		   			roundScore=0
		   			
		   			
		   		end
		   		
		   		if aGameIsRunning then
			   		if handSize(1)==0 then
			   			activePlayer=nextAvailablePlayerNum(activePlayer)
			   		else
			   			stopTimer()
			   			placeCursorOnCardNum(1)
			   			makeCursorAvailable()
			   		end
			   	end
		   	elseif activePlayer==1 and cursorIsAvailable() and aGameIsRunning then --next turns for the user, let him play
		   		if inputFirstPress("cross") then
		   			--select the card
		   			invertSelectionOfCardNum(ingameCursor.indice)
		   			placeCursorOnCardNum(ingameCursor.indice)
		   		elseif inputLongPress("cross") then
		   			selectAllCardsWithValue(players[1].hand[ingameCursor.indice].value, players[1].hand[ingameCursor.indice].selected)
		   		end
		   		if inputFirstPress("square") then
		   			--cancel selection
		   			deselectAllCards(1)
		   			placeCursorOnCardNum(ingameCursor.indice) --in the case the card it was on was selected
		   		end
		   		if inputFirstPress("circle") then
					drawScene(screen) --needed by the cancelPassAcceptMenu
		   			local cpamchoice=cancelPassAcceptMenu() --accept, cancel, pass
		   			if cpamchoice=="accept" then
						local tableOfCards=takeSelectedCardsFromHand(1, false)
						local validity=theGroupIsValid(tableOfCards)
						
						if validity=="ok" or validity=="cut" then
							
							local isRoundStart=false
							if numberOfCardsPlayed==0 then
								isRoundStart=true
							end
							
							numberOfCardsPlayed=tableLength(tableOfCards)
							roundScore=roundScore+calculateScore(tableOfCards)
							--showMessageBox("[player] roundScore is now = "..roundScore)
							
							local whatToSay=nil
					   		if isRoundStart and numberOfCardsPlayed<6 then --<6 because he can say things about big groups
					   			whatToSay=getRandomSpeech("startRound")
					   			--fdebug("startRound speech player 1")
					   			--showMessageBox("startRound speech player 1")
					   		else
					   			whatToSay=getSpeechAboutCards(tableOfCards) --he will say it from here
					   		end
						
							makePlayerLeader(1)
							powerOfCardsPlayed=tableOfCards[1].power
							removeSelectedCardsFromHand(1)
							positionCards(players[1])
					   		
				   			putCardsOnTheTable(tableOfCards, 1)
				   			if validity=="cut" then
				   				say("bottom", getRandomSpeech("cut"))
				   				findNextPlayer=false
				   				totalScore=totalScore+(roundScore/2)+8.5 --when cutting, you get only half of the points of the round
				   				--showMessageBox("add "..roundScore.." to total and put at 0")
		   						roundScore=0
				   			elseif handSize(1)==0 then --wins
				   				--say("bottom", getRandomSpeech("winRound"))
				   				findNextPlayer=false
				   				totalScore=totalScore+roundScore
				   				--showMessageBox("add "..roundScore.." to total and put at 0")
		   						roundScore=0
				   			else
						   		say("bottom", whatToSay)
				   				findNextPlayer=true
				   			end
				   			if findNextPlayer then
								activePlayer=nextAvailablePlayerNum(1)
							end
							makeCursorAvailable(false)
							GC()						
		   					startTimer()
		   				else
		   					local errormsg=""
		   					if validity==3 then
		   						errormsg="you have to play cards of the\nsame value, or mixed with 2s,\nor cut"
		   					elseif validity==4 then
		   						errormsg="you have to play "..numberOfCardsPlayed.." cards"
		   					elseif validity==5 then --TODO: add correspondance table power<->name
		   						errormsg="you must play higher than\n"..powerOfCardsPlayed.." or cut"
		   					elseif validity==6 then
		   						errormsg="trump cards must be played single"
		   					elseif validity==7 then
		   						errormsg="no cards selected"
		   					else
		   						errormsg="undefined error: '"..validity.."'"
		   					end
		   					showMessageBox(errormsg)
		   				end
		   			elseif cpamchoice=="pass" then
		   				if powerOfCardsPlayed==NOVALUE then
		   					--local bgimg=Image.createEmpty(480,272)
		   					showMessageBox("you have to play")
		   				else
		   					say("bottom", getRandomSpeech("pass"))
			   				players[1].state="passed"
			   				findNextPlayer=true
			   				activePlayer=nextAvailablePlayerNum(1)
			   				makeCursorAvailable(false)
			   				deselectAllCards(1)
			   				startTimer()
			   			end
		   			end
		   		end 
		   		if inputFirstPress("right") or inputIsRepeating("right") then
		   			moveCursorToThe("right")
		   		elseif inputFirstPress("left") or inputIsRepeating("left") then
		   			moveCursorToThe("left")
		   		elseif inputFirstPress("r") or inputIsRepeating("r") then
		   			moveCursorToThe("right", 5)
		   		elseif inputFirstPress("l") or inputIsRepeating("l") then
		   			moveCursorToThe("left", 5)
		   		end
		   		
		   		
		   		
		   	elseif playEvent~=nil then  --the AI has to play
		   		fdebug("")
		   		fdebug("#-----------------------------#")
		   		nbPlayersInGame=getNbPlayersInGame()
		   		--debugForced("nbPlayersInGame="..nbPlayersInGame)
		   		   		
		   		fdebug("activePlayer: "..activePlayer)
		   		debugHand(activePlayer)
				debugOnTheTable() --fdebug("on the table: "..numberOfCardsPlayed.."x "..powerOfCardsPlayed)
						   				   		
		   		if nbPlayersInGame==1 then
		   			--find smth to say
		   			say(players[activePlayer].position, getRandomSpeech("winRound"))
		   			--showMessageBox("put roundScore at 0")
		   			roundScore=0
		   			
		   			powerOfCardsPlayed=NOVALUE
		   			numberOfCardsPlayed=0
		   			cleanTableDeck()
		   			putEveryoneWhoPassedInGameAgain()
		   			findNextPlayer=false
		   		else --nbplayersingame<>1
			   		if findNextPlayer==false then
				   		if handSize(activePlayer)==0 then
				   			powerOfCardsPlayed=NOVALUE
				   			numberOfCardsPlayed=0
				   			cleanTableDeck()
				   			players[activePlayer].state="finished"
				   			players[activePlayer].rank=ranks[nbRanksAvailable]
			   				nbRanksAvailable=nbRanksAvailable-1
				   			findNextPlayer=true
				   			
				   			--showMessageBox("put roundScore at 0")
				   			roundScore=0
				   			
				   			stopGameIfNeeded()
				   		--trump is there since last event
				   		elseif powerOfCardsPlayed==TRUMP then
				   			powerOfCardsPlayed=NOVALUE
				   			numberOfCardsPlayed=0
				   			cleanTableDeck()
				   			waitingTurn=true
				   			
				   			roundScore=0
				   			--showMessageBox("put roundScore at 0")
				   		end   		
			   		end
			   		
			   		if waitingTurn then
			   			--detect if players must be put in game again
						if powerOfCardsPlayed==NOVALUE then
							putEveryoneWhoPassedInGameAgain()
						end
			   			waitingTurn=false
			   		else--not a waiting turn
						local ai=AI()
						if ai==nil then
							fdebug("PASS")
							players[activePlayer].state="passed"
							say(players[activePlayer].position, getRandomSpeech("pass"))
						else --ai is not null
							debugAIResult(ai)
							
							local isRoundStart=false
							if numberOfCardsPlayed==0 then
								isRoundStart=true
							end
					   		numberOfCardsPlayed=tableLength(ai)
					   		roundScore=roundScore+calculateScore(ai)
					   		--showMessageBox("roundScore is now = "..roundScore)
							
							--analyze what to say about the cards before putting them on the table
					   		local whatToSay=nil
					   		if isRoundStart and numberOfCardsPlayed<6 then
					   			whatToSay=getRandomSpeech("startRound")
					   			--fdebug("startRound speech")
					   		else
					   			whatToSay=getSpeechAboutCards(ai)
					   		end
							
							makePlayerLeader(activePlayer)
							positionCards(players[activePlayer])
					   		powerOfCardsPlayed=ai[1].power
					   		
					   		putCardsOnTheTable(ai, activePlayer)
					   		
					   		if handSize(activePlayer)==0 then
					   			--say(players[activePlayer].position, "finished!!")
					   			
					   			--find something to say based on the rank
					   			whatToSay=nil
					   			if ranks[nbRanksAvailable]=="president" then
					   				whatToSay=getRandomSpeech("getPresident")
					   			elseif ranks[nbRanksAvailable]=="vice president" then
					   				whatToSay=getRandomSpeech("getVicePresident")
					   			elseif ranks[nbRanksAvailable]=="vice asshole" then
					   				whatToSay=getRandomSpeech("getViceAsshole")
					   			end
					   			say(players[activePlayer].position, whatToSay)
					   			
					   			roundScore=0
					   			--showMessageBox("put roundScore at 0")
					   			
					   			findNextPlayer=false
					   			waitingTurn=true
					   		elseif powerOfCardsPlayed==TRUMP then
					   			say(players[activePlayer].position, getRandomSpeech("cut"))
					   			findNextPlayer=false
					   			roundScore=0
					   			--showMessageBox("put roundScore at 0")
					   		else
					   			findNextPlayer=true
					   			waitingTurn=false
					   			
					   			say(players[activePlayer].position, whatToSay)
					   			
					   		end
						end
					end
				end
				
				
				if findNextPlayer and aGameIsRunning then
					activePlayer=nextAvailablePlayerNum(activePlayer)
				end
				
		   		fdebug("#-----------------------------#")
				fdebug("")
				
		   	end -- end the AI has to play
		end --end if aGameIsRunning
		
		--draw the scene
		if environment=='pc' then
			drawScene(screen)
			screen.waitVblankStart()
			screen.flip()
		else
			if activePlayer~=1 then	
				if loopNum>=3 then
					drawScene(screen)
					screen.flip()			
					loopNum=1
					screen.waitVblankStart()
				else
					loopNum=loopNum+1
					System.sleep(50)
				end
			else
				if loopNum>=2 then
					drawScene(screen)
					screen.flip()			
					loopNum=1
					screen.waitVblankStart()
				else
					loopNum=loopNum+1
					System.sleep(30)
				end
			end
		end
	end --end main loop
end












-------------------------------------
--
--	other functions
--
-------------------------------------

function showMessageBox(message)
	---local bgimg=Image.createEmpty(480,272)
	drawScene(screen)
	messageBox(message)
	fdebug("end message box")
end

function openMainMenu()
	GC()
	local bg=Image.createEmpty(480, 272)
	drawScene(bg)
	return mainMenu(bg, false) --return can be: quitMenu cancel exit
end

function drawScene(target, lazy)
	if lazy==nil then
		lazy=true
	end
	
	if lazy then
		drawGameBGBuffer(target)
		drawCardsOnTheTable(target)
		drawPlayers(target, true)
		drawIngameCursor(target)
		drawSpeechBubbles(target)
	else --not lazy, update the bgbuffer and draw lazy
		prepareGameBGBuffer()
		drawScene(target, true)
	end
end

--global
gameBGBuffer=Image.createEmpty(480,272)

function prepareGameBGBuffer() --call it update buffer?
	fdebug("prepareGameBGBuffer")
	drawCarpet(gameBGBuffer)
	drawPlayers(gameBGBuffer, false)
end

function drawGameBGBuffer(target)
	target:blit(0,0,gameBGBuffer,false)
	return target
end

--based on the number of cards in hand
function stopGameIfNeeded()
	local nbCardsInHands={}
	local i=1
	local nb0=0
	for i=1,4 do
		nbCardsInHands[i]=handSize(i)
		if nbCardsInHands[i]==0 then
			nb0=nb0+1
		end
	end
	
	if nb0>=3 then
		--3 players have 0 cards (or more?)
		--so it is the end of the game
		--find the one with cards in hand, he's the asshole!
		for i=1,4 do
			if nbCardsInHands[i]>0 then
				players[i].rank="asshole"
				say(players[i].position, getRandomSpeech("getAsshole"))
			end
			players[i].state="not_playing"
		end
		stopTimer()
		playEvent=false
		aGameIsRunning=false
		--TODO: blame player 1 if he's the asshole, or congrat him if pres.
		
		alert("saving please wait..", 30)
		local reignToSave=nil
		for i=1,4 do
			STATE["rankP"..i]=players[i].rank
		end
		if players[1].rank=="president" then
			STATE["currentReign"]=STATE["currentReign"]+1
		else --he's not pres, and was pres a couple of times
			if STATE["currentReign"]~=0 then
				reignToSave=STATE["currentReign"]
			end
			STATE["currentReign"]=0
		end
		saveState()
		
		
		if previousRank~="neutral" then --only then we calculate scores
			local tmpScoreStr="your score:\n"
			totalScore=totalScore*10
			handScore=handScore*10
			tmpScoreStr=tmpScoreStr.."rounds won: "..totalScore.."\n"
			tmpScoreStr=tmpScoreStr.."remaining cards: "..handScore.."\n"
			local socialAscensionScore=calculateSocialAscensionScore(previousRank, players[1].rank)*10
			tmpScoreStr=tmpScoreStr.."social ascension: "..socialAscensionScore.."\n"
			tmpScoreStr=tmpScoreStr.."total: "..totalScore+handScore+socialAscensionScore.."\n"
			tmpScoreStr=tmpScoreStr.."rank multiplier: "..getRankMultiplier(players[1].rank).."\n"
			local finalScore=(totalScore+handScore+socialAscensionScore)*getRankMultiplier(players[1].rank)
			tmpScoreStr=tmpScoreStr.."total: "..finalScore.." pts"
			showMessageBox(tmpScoreStr)
			
			local placeInHighScores=getPlaceInHighscores(finalScore)
			local placeInReigns=nil
			if reignToSave~=nil then
				placeInReigns=getPlaceInReigns(reignToSave)
				--fdebug("place in reigns is "..placeInReigns)
			end
			
			totalScore=0
			handScore=0
			
			--TODO: get the name instead of this
			local bgimg=Image.createEmpty(480,272)
			drawScene(bgimg)
			local message=nil
			if placeInHighScores~=nil and placeInReigns~=nil then
				message="you are at place "..placeInHighScores.." for your score\nyou are at place "..placeInReigns.." for your reign"
			elseif placeInHighScores~=nil then
				message="you are at place "..placeInHighScores.." for your score"
			elseif placeInReigns~=nil then
				message="you are at place "..placeInReigns.." for your reign"
			end
			if placeInHighScores~=nil or placeInReigns~=nil then 
				USERPREF["name"]=textInputMenu(bgimg, message.."\nplease enter your name:", USERPREF["name"])
				alert("saving...", 30)
				savePreferences()
				saveHighScores(finalScore, reignToSave, USERPREF["name"])
				
				--TODO this does not work
				if placeInHighScores~=nil then
					showHighScores(bgimg, 1, placeInHighScores, placeInReigns)
				else
					showHighScores(bgimg, 2, placeInHighScores, placeInReigns)
				end
			end
		end
		
		fdebug("end game\r\n")
		return true
	end
	return false
end

function saveState()
	savePropertiesFile("state/state.properties", STATE)
end

function saveHighScores(score, reign, name)
	if score~=nil then
		fdebug("insert in highscores: "..score)
		insertInHighscore(score, name)
	end
	
	if reign~=nil then
		fdebug("insert in reign: "..reign)
		insertInReign(reign, name)
	end
	
	savePropertiesFile("state/highscores.properties", SCORES)
end

--initializes everything to make the game run
function startNewGame(neutralGame)
	--cleaning in case a game was interupted
	if aGameIsRunning and not neutralGame==true then --can be false or null
		showMessageBox("Game interrupted!\nEveryone gets neutral\nagain!\nNo scores!")
		makeEveryOneNeutral()
		STATE["currentReign"]=0
		for i=1,4 do
			STATE["rankP"..i]="neutral"
		end
	end
	--TODO: watch the ranks, and if there is a pb, put everyone in neutral state
	if neutralGame==true then
		makeEveryOneNeutral()
		STATE["currentReign"]=0
		for i=1,4 do
			STATE["rankP"..i]="neutral"
		end
	end
	fdebug("on new game main deck has "..tableLength(mainDeck).." cards")
	--mainDeck=prepareMainDeck()
	cleanTableDeck()
	fdebug("after cleaning table deck main deck has "..tableLength(mainDeck).." cards")
	cleanHands()
	fdebug("after cleaning hands main deck has "..tableLength(mainDeck).." cards")
	shuffleMainDeck()
	distributeCards()
	orderHands()
	disposePlayersAroundTheTable()
	positionAllCards()
	
	--find the president, and if everyone is neutral, choose random
	activePlayer=playerNumByRank("president")
	findNextPlayer=true --watches if, when someone has played, we ask the
						--next player to play, or if he keeps the advantage
	numberOfCardsPlayed=0
	powerOfCardsPlayed=NOVALUE
	waitingTurn=false
	nbPlayersInGame=4
	nbRanksAvailable=4
	playEvent=false
	aGameIsRunning=true

	if activePlayer==nil then --no president, choosing a random player
		activePlayer=random(1,4)
		if activePlayer==1 then
			showMessageBox("Lucky! You start")
		else
			showMessageBox("Player "..activePlayer.." starts")
			say(players[activePlayer].position, getRandomSpeech("startsGameLucky"))
		end
	else
		local cardsToExchange={}
		cardsToExchange["president"]=getCardsToExchangeByRank("president")
		cardsToExchange["vice president"]=getCardsToExchangeByRank("vice president")
		cardsToExchange["vice asshole"]=getCardsToExchangeByRank("vice asshole")
		cardsToExchange["asshole"]=getCardsToExchangeByRank("asshole")
		local bg=Image.createEmpty(480, 272)
		drawScene(bg, false) --because players have moved, redraw everything
		exchangeCardsMenu(bg, cardsToExchange[exchangePartnerRankByRank(players[1].rank)], cardsToExchange[players[1].rank])
		addCardsToHandByRank(cardsToExchange["president"], "asshole")
		addCardsToHandByRank(cardsToExchange["asshole"], "president")
		addCardsToHandByRank(cardsToExchange["vice president"], "vice asshole")
		addCardsToHandByRank(cardsToExchange["vice asshole"], "vice president")
		orderHands()
		positionAllCards()
		
		if players[1].rank=="president" then
			showMessageBox("President, you start")
		else
			showMessageBox("The president starts")
			say(players[activePlayer].position, getRandomSpeech("startsGamePresident"))
		end
	end
	
	putEveryOneInState("in_game")
	
	totalScore=0
	roundScore=0
	handScore=0
	previousRank=players[1].rank
	
	if activePlayer==1 then
		placeCursorOnCardNum(1)
		makeCursorAvailable()
	else
		startTimer()
	end
	GC()
	fdebug("end function start game")
end

function putEveryoneWhoPassedInGameAgain()
	for i=1,4 do
   		if players[i].state=="passed" then
   			players[i].state="in_game"
   		end
   	end
end

function debugAIResult(aiResult)
	local i=0
	local str="PLAYED: "
	for i=1, tableLength(aiResult) do
		if aiResult[i].power<=9 then
			str=str..aiResult[i].power
		elseif aiResult[i].power==10 then
			str=str.."X"
		elseif aiResult[i].power==11 then
			str=str.."V"
		elseif aiResult[i].power==12 then
			str=str.."C"
		elseif aiResult[i].power==13 then
			str=str.."D"
		elseif aiResult[i].power==14 then
			str=str.."R"
		elseif aiResult[i].power==15 then
			str=str.."A"
		elseif aiResult[i].power==16 then
			str=str.."2"
		else
			str=str.."*"
		end
	end
	fdebug(str)
end

function debugOnTheTable()
	local i=0
	local str="on the table: "..numberOfCardsPlayed.." x "
	
	if powerOfCardsPlayed<=9 then
		str=str..powerOfCardsPlayed
	elseif powerOfCardsPlayed==10 then
		str=str.."X"
	elseif powerOfCardsPlayed==11 then
		str=str.."V"
	elseif powerOfCardsPlayed==12 then
		str=str.."C"
	elseif powerOfCardsPlayed==13 then
		str=str.."D"
	elseif powerOfCardsPlayed==14 then
		str=str.."R"
	elseif powerOfCardsPlayed==15 then
		str=str.."A"
	elseif powerOfCardsPlayed==16 then
		str=str.."2"
	else
		str=str.."*"
	end
	fdebug(str)
end

function debugHand(playerNum)
	local i=0
	local str="in hand: "
	local sz=handSize(playerNum)
	for i=1, sz do
		if players[playerNum].hand[i].power<=9 then
			str=str..players[playerNum].hand[i].power
		elseif players[playerNum].hand[i].power==10 then
			str=str.."X"
		elseif players[playerNum].hand[i].power==11 then
			str=str.."V"
		elseif players[playerNum].hand[i].power==12 then
			str=str.."C"
		elseif players[playerNum].hand[i].power==13 then
			str=str.."D"
		elseif players[playerNum].hand[i].power==14 then
			str=str.."R"
		elseif players[playerNum].hand[i].power==15 then
			str=str.."A"
		elseif players[playerNum].hand[i].power==16 then
			str=str.."2"
		else
			str=str.."*"
		end
	end
	str=str.." ["..sz.."]"
	fdebug(str)
end








