#set scoreboard values
scoreboard players set @e[tag=dummy] ingame 1
scoreboard players set @e[tag=dummy] startanimation 1
scoreboard players set @e[tag=dummy] turn 0
scoreboard players set @e[tag=dummy] clockwise 0
scoreboard players reset * choosecolordelay
scoreboard players set @e[tag=dummy] hastodraw 0
scoreboard players set @e[tag=dummy] reshuffle 0


#assign player_id
scoreboard players reset * player_id
scoreboard players add @a[tag=!spectator] player_id 0
scoreboard players set @r[scores={player_id=0}] player_id 1
scoreboard players set @r[scores={player_id=0}] player_id 2
scoreboard players set @r[scores={player_id=0}] player_id 3
scoreboard players set @r[scores={player_id=0}] player_id 4


#game_id
scoreboard players operation @e[tag=dummy] game_id = .total login_id
scoreboard players operation @a[scores={player_id=1}] game_id = @e[tag=dummy] game_id
scoreboard players operation @a[scores={player_id=2}] game_id = @e[tag=dummy] game_id
scoreboard players operation @a[scores={player_id=3}] game_id = @e[tag=dummy] game_id
scoreboard players operation @a[scores={player_id=4}] game_id = @e[tag=dummy] game_id


#tag
tag * remove turn
tag * remove drawing


#playercount
scoreboard players set @e[tag=dummy] playercount 0
execute @a[scores={player_id=1..}] ~ ~ ~ scoreboard players add @e[tag=dummy] playercount 1


#title
title @a times 10 80 10
title @a title §l§eC§bE§cR§aO


#scores
scoreboard players operation @e[tag=dummy] startingcards = @e[tag=dummy] startingcards_ui
scoreboard players operation @e[tag=dummy] drawstacking = @e[tag=dummy] drawstacking_ui



#tellraw
execute @e[tag=dummy,scores={drawstacking=1}] ~ ~ ~ tellraw @a {"rawtext": [{"text": "§7Stacking draw cards is "},{"text": "§aenabled "},{"text": "§7in this game!"}]}
execute @e[tag=dummy,scores={drawstacking=0}] ~ ~ ~ tellraw @a {"rawtext": [{"text": "§7Stacking draw cards is "},{"text": "§cdisabled "},{"text": "§7in this game!"}]}


#tp players
tp @a[scores={player_id=1}] 38.5 27.5 -47.0 0 0
tp @a[scores={player_id=2}] 38.5 27.5 -30.0 180 0
tp @a[scores={player_id=3}] 47.0 27.5 -38.5 90 0
tp @a[scores={player_id=4}] 30.0 27.5 -38.5 270 0
tp @a[tag=spectator] 38.5 30 -53.0 0 0


#fences
fill 43 27 -35 43 27 -43 air
fill 33 27 -35 33 27 -43 air
execute @e[tag=dummy,scores={playercount=2}] ~ ~ ~ fill 43 27 -35 43 27 -43 fence 1
execute @e[tag=dummy,scores={playercount=2..3}] ~ ~ ~ fill 33 27 -35 33 27 -43 fence 1


#spectator
scoreboard players reset * spectating
scoreboard players set @a[tag=spectator] spectating 5


#spectator announce
execute @a[tag=spectator] ~ ~ ~ tellraw @a {"rawtext": [{"text": "§3"},{"selector": "@s"},{"text": " is spectating!"}]}
tag @e[tag=dummy] remove has_spectators
execute @a[tag=spectator] ~ ~ ~ tag @e[tag=dummy] add has_spectators
execute @e[tag=dummy,tag=has_spectators] ~ ~ ~ tellraw @a {"rawtext": [{"text": "§3Spectators can freely walk through the middle!"}]}
tag @e[tag=dummy] remove has_spectators


execute @a[tag=spectator] ~ ~ ~ function blockinteract_spawn