pong_bots smarter and starting with ggs.jeena.net

This commit is contained in:
Kallfaktorn 2011-04-26 16:28:44 +02:00
parent b7fc68a010
commit 68e97023c6
2 changed files with 14 additions and 12 deletions

View file

@ -3,8 +3,8 @@
-export([read/2, send_command/3]).
connect() ->
%{ok,Socket} = gen_tcp:connect("ggs.jeena.net", 9000,[{active, false}]),
{ok,Socket} = gen_tcp:connect("localhost", 9000,[{active, false}]),
{ok,Socket} = gen_tcp:connect("ggs.jeena.net", 9000,[{active, false}]),
%{ok,Socket} = gen_tcp:connect("localhost", 9000,[{active, false}]),
Socket.
read(Socket, Ref) ->

View file

@ -61,8 +61,10 @@ ggsNetworkReceivedCommandWithArgs(Command, Args, Ref) ->
"game" ->
game(Args, Ref);
"player1_points" ->
%io:format("Player1 win~n"),
new_round(Ref);
"player2_points" ->
%io:format("Player2 win~n"),
new_round(Ref);
_ -> ok
end.
@ -113,16 +115,16 @@ gameTick(Ref) ->
case ((BallY - MeY) < 0) of
true ->
ggs_network:send_command("up", "", Ref),
io:format("Player down sent to server~n"),
io:format("Ball: ~B~n", [BallY]),
io:format("Player: ~B~n", [MeY]);
ggs_network:send_command("up", "", Ref);
%io:format("Player down sent to server~n"),
%io:format("Ball: ~B~n", [BallY]),
%io:format("Player: ~B~n", [MeY]);
_ -> case ((BallY - MeY) > 0) of
true ->
ggs_network:send_command("down", "", Ref),
io:format("Player up sent to server~n"),
io:format("Ball: ~B~n", [BallY]),
io:format("Player: ~B~n", [MeY]);
ggs_network:send_command("down", "", Ref);
%io:format("Player up sent to server~n"),
%io:format("Ball: ~B~n", [BallY]),
%io:format("Player: ~B~n", [MeY]);
_ -> ok
end
end
@ -140,12 +142,12 @@ ball(Pos_s, Ref) ->
player1_y(YStr, Ref) ->
Y = list_to_integer(YStr),
io:format("Player1_y~n~n~n~n"),
%io:format("Player1_y~n~n~n~n"),
gen_server:cast({global, {pong_bot, Ref}}, {player1_y, Y}).
player2_y(YStr, Ref) ->
Y = list_to_integer(YStr),
io:format("Player2_y~n~n~n~n"),
%io:format("Player2_y~n~n~n~n"),
gen_server:cast({global, {pong_bot, Ref}}, {player2_y, Y}).
game(WaitOrStart, Ref) ->