tavla_sup.erl 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. -module(tavla_sup).
  2. -behaviour(supervisor).
  3. -export([start_link/0, stop/0]).
  4. -export([init/1, start/0, start_game/3]).
  5. -define(SERVER, ?MODULE).
  6. -define(CROWD_STANDALONE_1PL_NUM, 15).
  7. start() -> supervisor:start({local, ?SERVER}, ?MODULE, []).
  8. start_link() -> supervisor:start_link({local, ?SERVER}, ?MODULE, []).
  9. stop() -> exit(?SERVER, shutdown).
  10. start_game(Mod,Par,GameId) ->
  11. gas:info(?MODULE,"TAVLA SUP STAR CHILD"),
  12. %% Restart = transient,
  13. Restart = temporary,
  14. Shutdown = 200,
  15. ChildSpec = {GameId, {Mod, start_link, Par}, Restart, Shutdown, worker, [Mod]},
  16. supervisor:start_child(?MODULE,ChildSpec).
  17. init([]) ->
  18. gas:info(?MODULE,"TAVLA SUP STARTED"),
  19. RestartStrategy = one_for_one,
  20. MaxRestarts = 1,
  21. MaxSecondsBetweenRestarts = 600,
  22. SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts},
  23. Specs = tavla_standalone_specs(?CROWD_STANDALONE_1PL_NUM, 1),
  24. {ok, {SupFlags, Specs}}.
  25. tavla_standalone_specs(GamesNum, VirtUsersPerTable) ->
  26. VirtualUsers = nsg_crowd_lib:virtual_users(),
  27. if length(VirtualUsers) < VirtUsersPerTable ->
  28. [];
  29. true ->
  30. F = fun(_) ->
  31. GameId = game_manager:gen_game_id(),
  32. GameName = "Tavla/Crowd game: " ++ erlang:integer_to_list(GameId),
  33. Users = nsg_crowd_lib:random_users(VirtUsersPerTable, VirtualUsers),
  34. %%% Users = [robot],
  35. TableParams = [
  36. {table_name, ""},
  37. {mult_factor, 1},
  38. {slang_allowed, false},
  39. {observers_allowed, false},
  40. {tournament_type, standalone},
  41. {round_timeout, infinity},
  42. {set_timeout, infinity},
  43. {speed, fast},
  44. {game_mode, standard},
  45. {rounds, 3},
  46. {next_series_confirmation, no_exit},
  47. {pause_mode, normal},
  48. {social_actions_enabled, true},
  49. {tables_num, 1}
  50. ],
  51. CommonParams = [{speed, fast},
  52. {rounds, 3},
  53. {double_points, 1},
  54. {game_mode,standard},
  55. {speed, normal},
  56. {slang, false},
  57. {observers, false},
  58. {owner,"maxim"}
  59. ],
  60. Params = [{game, game_tavla},
  61. {game_mode, standard},
  62. {game_name, GameName},
  63. {seats, 2},
  64. {registrants, Users},
  65. {initial_points, 0},
  66. {quota_per_round, 1},
  67. {kakush_for_winners, 1},
  68. {kakush_for_loser, 1},
  69. {win_game_points, 1},
  70. {mul_factor, 1},
  71. {table_module, game_tavla_ng_table},
  72. {bot_module, game_tavla_bot},
  73. {bots_replacement_mode, enabled},
  74. {table_params, TableParams},
  75. {common_params, CommonParams}
  76. ],
  77. {GameId,
  78. {nsg_trn_standalone, start_link, [GameId, Params]},
  79. _Restart = permanent, _Shutdown = 2000, worker, [nsg_trn_standalone]}
  80. end,
  81. lists:map(F, lists:seq(1, GamesNum))
  82. end.