Commits

Jordi Chacón  committed caa84f7

Scoring system improved. Now we used the same as in the USA pingpong federation. Also added a refresh of the new match box when a user signs up, so that he automagically appears on the select boxes without refreshing

  • Participants
  • Parent commits 9fcf5fe

Comments (0)

Files changed (3)

File priv/docroot/js/tt.js

 	     $('#nick').val("");
 	     alert("Good! Start playing!");
 	     show_ranking();
+	     show_new_match();
 	   },
 	   error: function () {
 	     alert("Nick already used. Please try a new one.");

File src/tt_scoring.erl

 
 -import(math, [log10/1]).
 
-%% @doc Simple scoring model
-%% @spec v1(Winner::integer(), Looser::integer()) -> {Winner,Looser}.
 
 gen_new_scores(W, L) ->
-    {NW, NL} = v1(W, L),
-    {format(NW), format(NL)}.
+    HasMorePoints = case W > L of
+			true  -> winner;
+			false -> loser
+		    end,
+    gen_new_scores(W, L, abs(W - L), HasMorePoints).
 
-v1(W, L) when W > L -> 
-    {W + min(1, (1 / (W - L))), L - min(0.7, (1 / ((W - L) * 2)))};
-v1(W, L) when W < L -> 
-    {W + log10(max(10, (L - W) * 3)), L - log10(max(7, L - W))};
-v1(W, L) -> 
-    {W + 1, L - 1}.
-    
-min(A, B) ->
-    case A < B of
-	true  -> A;
-	false -> B
-    end.
-	    
-max(A, B) ->
-    case A > B of
-	true  -> A;
-	false -> B
-    end.
-	    
-format(Score) ->
-    case is_integer(Score) of
-	true -> 
-	    Score;
-	false -> 
-	    [Score2] = io_lib:format("~.3f", [Score]),
-	    list_to_float(Score2)
-    end.
+gen_new_scores(W, L, Diff, winner) when Diff >= 0 andalso Diff =< 12 ->
+    {W + 8, L - 8};
+gen_new_scores(W, L, Diff, loser) when Diff >= 0 andalso Diff =< 12 ->
+    {W + 8, L - 8};
+gen_new_scores(W, L, Diff, winner) when Diff >= 13 andalso Diff =< 37 ->
+    {W + 7, L - 7};
+gen_new_scores(W, L, Diff, loser) when Diff >= 13 andalso Diff =< 37 ->
+    {W + 10, L - 10};
+gen_new_scores(W, L, Diff, winner) when Diff >= 38 andalso Diff =< 62 ->
+    {W + 6, L - 6};
+gen_new_scores(W, L, Diff, loser) when Diff >= 38 andalso Diff =< 62 ->
+    {W + 13, L - 13};
+gen_new_scores(W, L, Diff, winner) when Diff >= 63 andalso Diff =< 87 ->
+    {W + 5, L - 5};
+gen_new_scores(W, L, Diff, loser) when Diff >= 63 andalso Diff =< 87 ->
+    {W + 16, L - 16};
+gen_new_scores(W, L, Diff, winner) when Diff >= 88 andalso Diff =< 112 ->
+    {W + 4, L - 4};
+gen_new_scores(W, L, Diff, loser) when Diff >= 8 andalso Diff =< 112 ->
+    {W + 20, L - 20};
+gen_new_scores(W, L, Diff, winner) when Diff >= 113 andalso Diff =< 137 ->
+    {W + 3, L - 3};
+gen_new_scores(W, L, Diff, loser) when Diff >= 113 andalso Diff =< 137 ->
+    {W + 25, L - 25};
+gen_new_scores(W, L, Diff, winner) when Diff >= 138 andalso Diff =< 162 ->
+    {W + 2, L - 2};
+gen_new_scores(W, L, Diff, loser) when Diff >= 138 andalso Diff =< 162 ->
+    {W + 30, L - 30};
+gen_new_scores(W, L, Diff, winner) when Diff >= 163 andalso Diff =< 187 ->
+    {W + 2, L - 2};
+gen_new_scores(W, L, Diff, loser) when Diff >= 163 andalso Diff =< 187 ->
+    {W + 35, L - 35};
+gen_new_scores(W, L, Diff, winner) when Diff >= 188 andalso Diff =< 212 ->
+    {W + 1, L - 1};
+gen_new_scores(W, L, Diff, loser) when Diff >= 188 andalso Diff =< 212 ->
+    {W + 40, L - 40};
+gen_new_scores(W, L, Diff, winner) when Diff >= 213 andalso Diff =< 237 ->
+    {W + 1, L - 1};
+gen_new_scores(W, L, Diff, loser) when Diff >= 213 andalso Diff =< 237 ->
+    {W + 45, L - 45};
+gen_new_scores(W, L, Diff, winner) when Diff >= 238 ->
+    {W, L};
+gen_new_scores(W, L, Diff, loser) when Diff >= 238 ->
+    {W + 50, L - 50}.
+

File src/tt_users_resource.erl

         no_exists ->
 	    tt_couchdb:store_doc([{"type",<<"user">>},
 				  {"nick",list_to_binary(Nick)},
-				  {"score",0}, {"matches", 0},
+				  {"score",1000}, {"matches", 0},
 				  {"wins", 0}, {"losses", 0}]),
             {true, ReqData, Context};
         _ ->