okey_sup.erl 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. -module(okey_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_3PL_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,"OKEY SUP START CHILD"),
  12. Restart = transient,
  13. Shutdown = 200,
  14. ChildSpec = {GameId, {Mod, start_link, Par}, Restart, Shutdown, worker, [Mod]},
  15. supervisor:start_child(?MODULE,ChildSpec).
  16. init([]) ->
  17. gas:info(?MODULE,"OKEY SUP STARTED"),
  18. RestartStrategy = one_for_one,
  19. MaxRestarts = 1,
  20. MaxSecondsBetweenRestarts = 600,
  21. SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts},
  22. Specs = okey_standalone_specs(?CROWD_STANDALONE_3PL_NUM, 3),
  23. {ok, {SupFlags, Specs}}.
  24. okey_standalone_specs(GamesNum, VirtUsersPerTable) ->
  25. VirtualUsers = nsg_crowd_lib:virtual_users(),
  26. if length(VirtualUsers) < VirtUsersPerTable ->
  27. [];
  28. true ->
  29. F = fun(_) ->
  30. GameId = game_manager:gen_game_id(),
  31. GameName = "Okey/Crowd game - " ++ erlang:integer_to_list(GameId),
  32. Users = nsg_crowd_lib:random_users(VirtUsersPerTable, VirtualUsers),
  33. %%% Users = [robot, robot, robot],
  34. TableParams = [
  35. {table_name, ""},
  36. {mult_factor, 1},
  37. {slang_allowed, false},
  38. {observers_allowed, false},
  39. {tournament_type, standalone},
  40. {round_timeout, infinity},
  41. {set_timeout, infinity},
  42. {speed, fast},
  43. {game_type, standard},
  44. {rounds, 10},
  45. {reveal_confirmation, true},
  46. {next_series_confirmation, no_exit},
  47. {pause_mode, normal},
  48. {social_actions_enabled, true},
  49. {gosterge_finish_allowed, undefined}
  50. ],
  51. CommonParams = [{speed, fast},
  52. {rounds,10},
  53. {double_points, 1},
  54. {game_mode,standard},
  55. {slang, false},
  56. {observers, false},
  57. {owner,"maxim"}
  58. ],
  59. Params = [{game, game_okey},
  60. {game_mode, standard},
  61. {game_name, GameName},
  62. {seats, 4},
  63. {registrants, Users},
  64. {initial_points, 0},
  65. {quota_per_round, 1},
  66. {kakush_for_winners, 1},
  67. {kakush_for_loser, 1},
  68. {win_game_points, 1},
  69. {mul_factor, 1},
  70. {table_module, game_okey_table},
  71. {bot_module, game_okey_bot},
  72. {bots_replacement_mode, enabled},
  73. {table_params, TableParams},
  74. {common_params, CommonParams} %% This data will used for the gproc register
  75. ],
  76. {GameId,
  77. {nsg_trn_standalone, start_link, [GameId, Params]},
  78. _Restart = permanent, _Shutdown = 2000, worker, [nsg_trn_standalone]}
  79. end,
  80. lists:map(F, lists:seq(1, GamesNum))
  81. end.