okey_sup.erl 4.2 KB

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