-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.iex.exs
147 lines (131 loc) · 4.34 KB
/
.iex.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
alias Level10.{Accounts, Games, Repo, StateHandoff}
alias Accounts.{User, UserToken, UserAuth}
alias Games.{Card, Game, GameRegistry, GameServer, GameSupervisor, Levels, Player, Settings}
join_code = "ABCD"
player = %Player{
id: "98ba6988-15ab-4e83-82b1-00330fbcfec8",
name: "Dennis"
}
defmodule Seeds do
def chrome, do: __MODULE__.open(["-a", "Google Chrome"])
def game do
%Level10.Games.Game{
current_player: %Level10.Games.Player{
id: "9762d8e9-7288-4010-b3be-468554b3319e",
name: "Right"
},
current_round: 9,
current_stage: :score,
current_turn: 26,
current_turn_drawn?: false,
discard_pile: [],
draw_pile: [],
hands: %{
"9762d8e9-7288-4010-b3be-468554b3319e" => [
%Level10.Games.Card{color: :yellow, value: :one},
%Level10.Games.Card{color: :yellow, value: :six},
%Level10.Games.Card{color: :green, value: :one},
%Level10.Games.Card{color: :red, value: :two}
],
"1f98ecfe-eccf-42d5-b0fe-7023aba16357" => []
},
join_code: "ABCD",
levels: %{
"9762d8e9-7288-4010-b3be-468554b3319e" => 1,
"1f98ecfe-eccf-42d5-b0fe-7023aba16357" => 1
},
players: [
%Level10.Games.Player{
id: "9762d8e9-7288-4010-b3be-468554b3319e",
name: "Dennis"
},
%Level10.Games.Player{
id: "1f98ecfe-eccf-42d5-b0fe-7023aba16357",
name: "Kira"
}
],
players_ready: MapSet.new(),
remaining_players:
MapSet.new([
"9762d8e9-7288-4010-b3be-468554b3319e",
"1f98ecfe-eccf-42d5-b0fe-7023aba16357"
]),
scoring: %{
"9762d8e9-7288-4010-b3be-468554b3319e" => {10, 20},
"1f98ecfe-eccf-42d5-b0fe-7023aba16357" => {10, 10}
},
settings: %Level10.Games.Settings{
skip_next_player: false
},
skipped_players: MapSet.new(),
table: %{
"9762d8e9-7288-4010-b3be-468554b3319e" => %{
0 => [
%Level10.Games.Card{color: :yellow, value: :twelve},
%Level10.Games.Card{color: :blue, value: :twelve},
%Level10.Games.Card{color: :red, value: :twelve}
],
1 => [
%Level10.Games.Card{color: :yellow, value: :three},
%Level10.Games.Card{color: :black, value: :three},
%Level10.Games.Card{color: :blue, value: :three},
%Level10.Games.Card{color: :green, value: :three},
%Level10.Games.Card{color: :red, value: :three}
]
},
"1f98ecfe-eccf-42d5-b0fe-7023aba16357" => %{
0 => [
%Level10.Games.Card{color: :blue, value: :seven},
%Level10.Games.Card{color: :blue, value: :seven},
%Level10.Games.Card{color: :red, value: :seven}
],
1 => [
%Level10.Games.Card{color: :yellow, value: :eleven},
%Level10.Games.Card{color: :red, value: :eleven},
%Level10.Games.Card{color: :yellow, value: :eleven}
]
}
}
}
end
def open(app_args \\ []) do
port = System.get_env("PORT", "4000")
url = "http://localhost:#{port}/game/ABCD?player_id="
System.cmd("open", app_args ++ [url <> "9762d8e9-7288-4010-b3be-468554b3319e"])
System.cmd("open", app_args ++ [url <> "1f98ecfe-eccf-42d5-b0fe-7023aba16357"])
end
def reset do
Games.update("ABCD", fn _ -> game() end)
end
def safari, do: __MODULE__.open(["-a", "Safari"])
def set(join_code \\ "ABCD", game) do
Games.update(join_code, fn _ -> game end)
end
def stack_deck(join_code \\ "ABCD", card) do
Games.update(join_code, fn game ->
deck = game.draw_pile
%{game | draw_pile: [card | deck]}
end)
end
def wild_hands(join_code \\ "ABCD") do
hand = List.duplicate(Card.new(:wild, :black), 10)
Games.update(join_code, fn game ->
hands = %{
"9762d8e9-7288-4010-b3be-468554b3319e" => hand,
"1f98ecfe-eccf-42d5-b0fe-7023aba16357" => hand
}
%{game | hands: hands}
end)
end
end
settings = %Settings{skip_next_player: false}
game = %{
id: join_code,
start:
{GameServer, :start_link,
[{join_code, player, settings}, [name: {:via, Horde.Registry, {GameRegistry, join_code}}]]},
shutdown: 1000,
restart: :temporary
}
Horde.DynamicSupervisor.start_child(GameSupervisor, game)
Seeds.reset()