Browse Source

bert should be definitely rewritten due to neg SINT bug

Maxim Sokhatsky 11 years ago
parent
commit
b533ea26b8

+ 5 - 3
apps/server/src/okey/okey_bot.erl

@@ -276,7 +276,8 @@ do_challenge(State) ->
     ZZZ = call_rpc(S, #game_action{
                          game = GameId,
                          action = okey_challenge,
-                         args = [ {challenge, random_bool(0.2)} ]}),
+                         args = [ {challenge, random_bool(0.2)
+                                             } ]}),
     gas:info(?MODULE,"ID: ~p challenge result: ~p", [State#state.uid, ZZZ]),
     ok.
 
@@ -389,8 +390,9 @@ draw_random(List) ->
     {Item, ResList}.
 
 random_bool(Prob) ->
-    Point = crypto:rand_uniform(0, 1000),
-    Prob*1000 > Point.
+%    Point = crypto:rand_uniform(0, 1000),
+%    Prob*1000 > Point,
+    crypto:rand_uniform(0,2) == 0.
 
 get_delay(fast) -> {ok, Val}   = kvs:get(config,"games/okey/robot_delay_fast", 1000), Val;
 get_delay(normal) -> {ok, Val} = kvs:get(config,"games/okey/robot_delay_normal", 9000), Val;

+ 7 - 3
apps/server/src/okey/okey_scoring.erl

@@ -277,8 +277,9 @@ finish_info(GameMode, FinishReason, Gosterge) ->
         {reveal, Revealer, Tashes, Discarded, ConfirmationList} ->
             {RightReveal, RevealWithPairs, WithColor} = check_reveal(Tashes, Gosterge),
     gas:info(?MODULE,"check_reveal result p~n",[{RightReveal, RevealWithPairs, WithColor}]), 
-            WinReveal = RightReveal orelse lists:all(fun({_, Answer}) -> Answer == true end, ConfirmationList),
-            if WinReveal ->
+            WinReveal = RightReveal orelse (ConfirmationList /= [] andalso lists:all(fun({_, Answer}) -> Answer == true end, ConfirmationList)),
+            TestConfirmation = false,
+            if WinReveal orelse TestConfirmation  ->
                    RevealWithColor = case GameMode of
                                          ?MODE_STANDARD -> false;
                                          ?MODE_EVENODD -> WithColor;
@@ -286,11 +287,14 @@ finish_info(GameMode, FinishReason, Gosterge) ->
                                          ?MODE_COUNTDOWN -> false
                                      end,
                    Okey = gosterge_to_okey(Gosterge),
+                   wf:info(?MODULE,"Confirmation List ~p",[ConfirmationList]),
                    RevealWithOkey = Discarded == Okey,
-                   WrongRejects = if RightReveal ->
+                   
+                   WrongRejects = if RightReveal orelse TestConfirmation ->
                                          [S || {S, Answer} <- ConfirmationList, Answer==false];
                                      true -> []
                                   end,
+                   wf:info(?MODULE,"Wrong Rejects ~p",[WrongRejects]),
                    {win_reveal, Revealer, WrongRejects, RevealWithColor, RevealWithOkey, RevealWithPairs};
                true ->
                    {fail_reveal, Revealer}

+ 9 - 6
apps/server/src/okey/okey_table.erl

@@ -951,13 +951,13 @@ handle_log(User,#game_event{}=Event,
 send_to_subscriber_ge(Relay, SubscrId, Msg, #okey_state{players=Players,game_id = GameId} = State) ->
     [Name|List] = tuple_to_list(Msg),
     Event = #game_event{game = GameId, event = Name, args = lists:zip(known_records:fields(Name),List) },
-    gas:info(?MODULE,"SUBSCRIBER ~p",[SubscrId]),
+%    gas:info(?MODULE,"SUBSCRIBER ~p",[SubscrId]),
     ?RELAY:table_message(Relay, {to_subscriber, SubscrId, Event}).
 
 send_to_client_ge(Relay, PlayerId, Msg, #okey_state{players=Players,game_id = GameId} = State) ->
     [Name|List] = tuple_to_list(Msg),
     Event = #game_event{game = GameId, event = Name, args = lists:zip(known_records:fields(Name),List) },
-    gas:info(?MODULE,"SEND CLIENT ~p",[Event]),
+%    gas:info(?MODULE,"SEND CLIENT ~p",[Event]),
     ?GAME_STATS:protocol_event(table,Event,State),
     case get_player(PlayerId, Players) of
         {ok, #player{user_id=User,is_bot=false}} -> handle_log(User,Event,State);
@@ -967,7 +967,7 @@ send_to_client_ge(Relay, PlayerId, Msg, #okey_state{players=Players,game_id = Ga
 relay_publish_ge(Relay, Msg, #okey_state{players=Players,game_id = GameId} = State) ->
     [Name|List] = tuple_to_list(Msg),
     Event = #game_event{game = GameId, event = Name, args = lists:zip(known_records:fields(Name),List) },
-    gas:info(?MODULE,"RELAYX PUBLISH ~p",[Event]),
+%    gas:info(?MODULE,"RELAYX PUBLISH ~p",[Event]),
     ?GAME_STATS:protocol_event(table,Event,State),
     [ handle_log(UserId,Event,State) 
     || {_,#player{id=Id,user_id=UserId,is_bot=false},_} <- midict:to_list(Players)],
@@ -1281,6 +1281,8 @@ round_results(
         game_id=GameId,
         players=Players}) ->
 
+    wf:info(?MODULE,"Score ~p/~p",[RoundScore,TotalScore]),
+
     {Date,Time} = calendar:local_time(),
 
     Results = [begin
@@ -1290,8 +1292,6 @@ round_results(
         GoodShot = if SeatNum == Revealer -> RevealerWin; true -> not lists:member(SeatNum, WrongRejects) end,
         {_, PlayerScoreTotal} = lists:keyfind(SeatNum, 1, TotalScore),
         {_, PlayerScoreRound} = lists:keyfind(SeatNum, 1, RoundScore),
-        
-        io:format("XXX Player ~p",[Player]),
 
         RE = #reveal_event{
             id = ?GAME_STATS:timestamp(),
@@ -1317,7 +1317,7 @@ round_results(
             {true,_,false}  -> ?GAME_STATS:reveal_event(UserId,RE,State);
             _ -> skip end,
 
-        {DisplayName,IsWinner,PlayerScoreRound,PlayerScoreTotal}
+        {DisplayName,IsWinner,js_hack(PlayerScoreRound),js_hack(PlayerScoreTotal)}
 
     end || SeatNum <- lists:seq(1, ?SEATS_NUM)],
 
@@ -1327,6 +1327,9 @@ round_results(
         results = Results,
         next_action = next_round}.
 
+js_hack(Score) when Score < 0 -> Score * 1000000;
+js_hack(Score) -> Score.
+
 create_okey_series_ended(Results, Players, Confirm,
     #okey_state{tournament_type=GameKind,game_mode=GameMode,speed=Speed,rounds=Rounds}=GameState) ->
     {Date,Time} = calendar:local_time(),

+ 20 - 4
apps/web/priv/static/app/js/bootloader.js

@@ -6,17 +6,31 @@ function isSafari() {
 var svgNS = "http://www.w3.org/2000/svg";
 var color = ['#DE3F26','#606060','#48AF5E','#FFC800'];
 
-function statsRow(start_name,i,games) {
-    var start_score = 200;
+function statsRow(start_x,start_y,i,games) {
     var name = template_engine(
         '<tspan xmlns="http://www.w3.org/2000/svg" x="{this.x}" y="{this.y}">{this.body}</tspan>',{
-            x: start_name,
-            y: 180+25*i,
+            x: start_x,
+            y: start_y+25*i,
             body: games[i].value[0][0] + " — " + games[i].value[0][1]});
     var element1 = svg(name);
     document.getElementById('Stat-Right').appendChild(element1);
 }
 
+function gameresultRow(start_x,start_y,i,results) {
+   console.log(results[i].value[0][3]);
+     var round = results[i].value[0][2],
+         total = results[i].value[0][3];
+         round = round > 500000 ? -Math.round(round/1000000) : round;
+         total = total > 500000 ? -Math.round(total/1000000) : total;
+    var name = template_engine(
+        '<tspan xmlns="http://www.w3.org/2000/svg" x="{this.x}" y="{this.y}">{this.body}</tspan>',{
+            x: start_x,
+            y: start_y+30*i,
+            body: results[i].value[0][0] + " — " + round + "/" + total}); 
+    var element1 = svg(name);
+    document.getElementById('Overlay-Results').appendChild(element1);
+}
+
 function parseTransformAttribute(aa) {
     var a = aa.split(' ').join('');
     var b={};
@@ -243,6 +257,7 @@ function initPauseOverlay() {
     var html = '<g xmlns="http://www.w3.org/2000/svg" id="overlay" style="display:none;">'+
         '<rect x="216" y="91" stroke-width="0" stroke="red" width="641" height="367" rx="6" fill="skyblue" opacity="0.8"></rect>'+
         '<g>'+
+        '<text id="Overlay-Results" fill="white" font-family="Exo 2" font-size="20pt"></text>'+
         '<text id="Overlay-Text" fill="white" font-family="Exo 2" y="280" x="-116" text-anchor="middle" dx="641" font-size="30pt"> Someone paused the game</text></g>'+
         '</g>';
     var page = document.getElementById("Kakaranet-12-maxim");
@@ -272,6 +287,7 @@ function showRevealHand(o) {
             $reveal_deck = $("#RevealDeck");
             $("#RevealDeckRoot").on("click",function () {
                 $overlay.hide();
+                $("#Overlay-Results").empty();
                 if (scope.ended) scope.deck.fill([]);
             });
         }

+ 16 - 5
apps/web/priv/static/app/js/n2o/bert.js

@@ -49,11 +49,11 @@ function ltoi(S, Length) {
     isNegative = (S.charCodeAt(0) > 128);
     for (i = 0; i < Length; i++) {
         n = S.charCodeAt(i);
-        if (isNegative) { n = 255 - n; }
+        if (isNegative) { n = n - 255; }
         if (Num === 0) { Num = n; }
         else { Num = Num * 256 + n; }
     }
-    if (isNegative) { Num = Num * (0 - 1); }
+    if (isNegative) { Num = -Num; }
     return Num; };
 function btol(Int) {
     var isNegative, Rem, s = "";
@@ -140,9 +140,20 @@ function de_bin(S) {
     S = S.substring(4);
     return { value: bin(S.substring(0, Size)), rest: S.substring(Size) }; };
 function de_integer(S, Count) {
-    var Value = ltoi(S, Count);
-    S = S.substring(Count);
-    return { value: Value, rest: S }; };
+//    if (Count == 1) {
+//        var n = S.charCodeAt(0);
+//        S = S.substring(Count);
+//        var neg = (n > 128);
+//        n = n>128 ? 255 - n : n;
+//        n = n == 0 ? -1 : (n==-1 ? 0: ( n == 1 ? -2 : n));
+//        return { value: n, rest: S };
+//    } else
+//    {
+        var Value = ltoi(S, Count);
+        S = S.substring(Count);
+        return { value: Value, rest: S };
+//    } 
+    };
 function de_float(S) {
     var Size = 31;
     return { value: parseFloat(S.substring(0, Size)), rest: S.substring(Size) }; };

+ 10 - 0
apps/web/priv/static/app/js/okey/okey.js

@@ -218,6 +218,16 @@ function PostLoad()
         // $gosterme.remove();
     });
 
+    scope.apiProvider.on("okey_round_ended", function(x) {
+        var e = {detail: x.detail.json, raw: x.detail.bert};
+        console.log(String(dec(e.raw)));
+        console.log(e.detail);
+        var gameres = dec(e.raw).value[0][3][2].value[0][1];
+        $("#Overlay-Results").empty();
+        for (var i=0;i<gameres.length;i++) { gameresultRow(400,130,i,gameres); }
+
+    });
+
     scope.apiProvider.on("player_left", function(x) {
         var e = {detail: x.detail.json, raw: x.detail.bert};
         var playerInfo = e.detail.replacement.PlayerInfo;

+ 1 - 0
apps/web/priv/static/app/js/okey/okey_protocol.js

@@ -36,6 +36,7 @@ function OkeyApiProviderScope(scope) {
         "okey_next_turn",
         "okey_tile_discarded",
         "okey_tile_taken",
+        "okey_round_ended",
         "okey_revealed",
         "player_left",
         "game_paused"

+ 3 - 3
apps/web/priv/static/app/js/roster.js

@@ -89,9 +89,9 @@ function RosterHandlers(scope) {
             score    = dec(e.raw).value[0][5];
         removeChilds(document.getElementById('Stat-Left'));
         removeChilds(document.getElementById('Stat-Right'));
-//            for (var i=0;i<games.length;i++) { statsRow(24, i,games); }
-        for (var i=0;i<protocol.length;i++) { statsRow(24,i,protocol); }
-        for (var i=0;i<reveals.length;i++) { statsRow(340,i,reveals); }
+//            for (var i=0;i<games.length;i++) { statsRow(4, i,games); }
+        for (var i=0;i<protocol.length;i++) { statsRow(4,180,i,protocol); }
+        for (var i=0;i<reveals.length;i++) { statsRow(320,180,i,reveals); }
         $("#Score").text("Score: " + score).attr({y: 40});
     });
 

+ 3 - 2
apps/web/src/logallow.erl

@@ -6,10 +6,11 @@ log_modules() -> [
     n2o_bullet,
 %    okey_bot,
 %    game_session,
-    bullet_handler,
+%    bullet_handler,
+    okey_table,
 %    okey_scoring,
     journal,
-    lucky,
+%    lucky,
 %    n2o_secret,
     js_session,
     okey