tavla_sup.erl 4.1 KB

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