aboutsummaryrefslogtreecommitdiff
path: root/tictactoe-2
diff options
context:
space:
mode:
Diffstat (limited to 'tictactoe-2')
-rw-r--r--tictactoe-2/apps/ttt_server/src/game.erl12
-rw-r--r--tictactoe-2/apps/ttt_server/src/ttt_server.erl11
2 files changed, 18 insertions, 5 deletions
diff --git a/tictactoe-2/apps/ttt_server/src/game.erl b/tictactoe-2/apps/ttt_server/src/game.erl
index 8c6550a..1b8aff2 100644
--- a/tictactoe-2/apps/ttt_server/src/game.erl
+++ b/tictactoe-2/apps/ttt_server/src/game.erl
@@ -2,7 +2,8 @@
-author("trygvis").
-export([
- game_loop/2]).
+ game_loop/2,
+ loop/1]).
-import(ttt, [empty_board/0]).
@@ -31,6 +32,11 @@ loop(State) ->
Str = ttt:format(State#state.board),
io:format("game ~p: current state:~n~p~n", [Id, Str]),
From ! Str,
+ loop(State);
+ code_changed ->
+ io:format("game ~p: code changed~n", [Id]),
+ ?MODULE:loop(State);
+ X ->
+ io:format("unexpected message: ~p~n", [X]),
loop(State)
- end,
- State.
+ end.
diff --git a/tictactoe-2/apps/ttt_server/src/ttt_server.erl b/tictactoe-2/apps/ttt_server/src/ttt_server.erl
index c7167fb..a0de947 100644
--- a/tictactoe-2/apps/ttt_server/src/ttt_server.erl
+++ b/tictactoe-2/apps/ttt_server/src/ttt_server.erl
@@ -52,8 +52,15 @@ loop(State) ->
io:format("Exiting~n", []);
{stop, Pid} ->
Pid ! ok;
- recompiled ->
- io:format("Reloading~n", []),
+ code_changed ->
+ io:format("Code changed~n"),
+ io:format("Code changed: ~p~n", [State#ttt_state.games]),
+ orddict:map(
+ fun(_Id, [G]) ->
+ io:format("Id=~p, v=~p~n", [_Id, G]),
+ G#ttt_game.pid ! code_changed
+ end,
+ State#ttt_state.games),
?MODULE:loop(State);
X ->
io:format("unexpected message: ~p~n", [X]),