Maxim Sokhatsky 10 лет назад
Родитель
Сommit
bc2fa50ac2

+ 8 - 4
apps/server/src/okey/okey_reveal.erl

@@ -1,4 +1,5 @@
 -module(okey_reveal).
+-author('Vitaly Voronov').
 -compile(export_all).
 
 main() ->
@@ -17,7 +18,7 @@ main() ->
     L3 = [{1,1},{2,1},{3,1},
           {1,3},{2,3},{3,3},
           {1,5},{2,5},{3,5},
-          okey,okey,{2,8},{2,5},
+          okey,okey,{2,8},{2,3},
           {2,9}],
 
     L4 = [{1,1},{2,1},{3,1},
@@ -26,7 +27,8 @@ main() ->
         okey,okey,{2,10},{2,6},
         {2,9}],
     Tests = [L0,L1,L2,L4,L3],
-    [ io:format("~p~n",[check_reveal(L)]) ||L <- Tests].
+    [ check_reveal(L) ||L <- Tests],
+    check_reveal(L3).
 
 check_reveal(L1) -> 
     L11 = element(1, lists:mapfoldl(fun(X, Acc) when is_atom(X) -> {{okey, okey, Acc}, Acc+1};
@@ -112,7 +114,8 @@ check2x7(L2) ->
     L2comb=lists:filter(fun(X) -> length(X) > 2 end,combs_clb(L2, [], 7)),
     case length(L2comb) > 0 of
         true -> {true, [ lists:map(fun({okey,okey,_}) -> okey;
-                                   ({X,Y,Z}) -> {X,Y} end,L)
+                                    ({C,14,X}) -> {C,1};
+                                   ({C,V,_}) -> {C,V} end,L)
                            || L <- lists:nth(length(L2comb)-1,L2comb)]};
         false-> {false,[]} end.
 
@@ -132,7 +135,8 @@ check_list(X, [H|T]) ->
     case checkuniq(myflatten(X), myflatten(H)) of
         true -> 
             {true, [ lists:map(fun({okey,_,_}) -> okey;
-                ({X,Y,Z}) -> {X,Y} end,L) || L <- lists:merge(norm(X),norm(H)) ]};
+                                    ({C,14,X}) -> {C,1};
+                ({C,V,_}) -> {C,V} end,L) || L <- lists:merge(norm(X),norm(H)) ]};
         false -> check_list(X, T) end.
 
 series([]) -> false;

+ 33 - 39
apps/server/src/okey/okey_scoring.erl

@@ -275,8 +275,7 @@ finish_info(GameMode, FinishReason, Gosterge) ->
         timeout -> timeout;
         set_timeout -> set_timeout;
         {reveal, Revealer, Tashes, Discarded, ConfirmationList} ->
-            {RightReveal, RevealWithPairs, WithColor} = check_reveal(Tashes, Gosterge),
-    gas:info(?MODULE,"check_reveal result p~n",[{RightReveal, RevealWithPairs, WithColor}]), 
+            {RightReveal, RevealWithPairs, WithColor, Hand} = check_reveal(Tashes, Gosterge),
             WinReveal = RightReveal orelse (ConfirmationList /= [] andalso lists:all(fun({_, Answer}) -> Answer == true end, ConfirmationList)),
             TestConfirmation = false,
             if WinReveal orelse TestConfirmation  ->
@@ -328,56 +327,51 @@ gosterge_to_okey({Color, Value}) ->
        true -> {Color, Value + 1}
     end.
 
-check_win([TopRow, BottomRow], Gosterge) ->
+normalize_reveal([TopRow, BottomRow], Gosterge) ->
     FlatList = TopRow ++ [null | BottomRow],
     Okey = gosterge_to_okey(Gosterge),
     Normalized = [case E of
                       Okey -> okey;
-                      false_okey -> okey;
+                      false_okey -> Okey;
                        _ -> E
                   end || E <- FlatList],
+    Sets = split_by_delimiter(null, Normalized),
+    {Sets,Normalized}.
 
-    Res = check_unordered(sets:from_list(Normalized),[],[]),
-
-    gas:info(?MODULE,"NEW check_reveal/2 ~p",[Res]),
-
-    ok.
-
-%color_masks(HandSet) -> 
-%    [H|T] = sets:to_list(HandSet),
-%    color_masks_rec(sets:from_list([H]),)
-
-masks(_) -> [].
+% test [{3,13},{3,11},{1,9},{2,8},{2,13},{3,10},null,{3,8},{4,12},{1,6},{2,12},{1,3},{4,5},{3,5},null,null,{3,2},null,null,null,null,null,null,null,null,null,null,null,null,null,null]
 
-check_unordered(HandSet,ResultMap,CombinationList) ->
-    case sets:size(HandSet) of
-        0 -> case ResultMap of
-                [{3,3},{5,1}] -> true;
-                      [{2,7}] -> true;
-                [{3,2},{4,2}] -> true;
-                [{4,1},{5,2}] -> true;
-                _ -> false end;
-        _ -> lists:any(fun(X) ->
-                NewSet = ResultMap ++ [{X,1}],
-                check_unordered(HandSet,[],[])
-              end, masks(HandSet))
-    end.
+denormalize_reveal(RevealHand, Gosterge) ->
+    Okey = gosterge_to_okey(Gosterge),
+    Den = [ [ case Tash of
+        okey -> Okey;
+        _ -> Tash end || Tash <- [null|Series] ] || Series <- RevealHand ],
+    {L1,L2}=lists:split(2,Den),
+    [lists:flatten(L1),lists:flatten(L2)].
+
+check_reveal(Tashes, Gosterge) ->
+    {Sets,Normalized} = normalize_reveal(Tashes, Gosterge),
+    {RR, RP, RC} = check_manual_reveal({Sets,Normalized}, Gosterge),
+    gas:info(?MODULE,"Manual Reveal ~n",[RR]),
+    {RightReveal, RevealWithPairs, WithColor, Hand} = case RR of
+        false -> gas:info(?MODULE,"Ok We Will Help You~n",[]),
+            case okey_reveal:check_reveal(lists:flatten(Sets)) of
+                [] -> {false,false,false, []};
+                X -> case hd(X) of
+                    {x2x7,Pairs} -> {true,true,false, Pairs};
+                    {How,Comb} -> 
+                        gas:info(?MODULE,"Automatic Reveal ~p ~p~n",[How,Comb]),
+                    Denormalized = okey_scoring:denormalize_reveal(Comb,Gosterge),
+                   wf:info(?MODULE,"Denormalized Reveal ~p",[Denormalized]),
+                        {true,false,false, Denormalized} end end;
+        true -> {RR, RP, RC, Sets} end.
 
 %% @spec check_reveal(TashPlaces, Gosterge) -> {RightReveal, WithPairs, SameColor}
 %% @end
-check_reveal([TopRow, BottomRow], Gosterge) ->
-    FlatList = TopRow ++ [null | BottomRow],
-    Okey = gosterge_to_okey(Gosterge),
-    Normalized = [case E of
-                      Okey -> okey;
-                      false_okey -> Okey;
-                       _ -> E
-                  end || E <- FlatList],
-    gas:info(?MODULE,"check_reveal/2 ~n    ~p ~p~n",[Normalized, Gosterge]), 
-    Sets = split_by_delimiter(null, Normalized),
+check_manual_reveal({Sets,Normalized}, Gosterge) ->
+    gas:info(?MODULE,"check_reveal/2 ~n    ~p ~p~n",[Sets, Gosterge]), 
     ProperHand = lists:all(fun(S) -> is_set(S) orelse is_run(S) end, Sets),
     Pairs = lists:all(fun(S) -> is_pair(S) end, Sets),
-    [Color | Rest] = [C || {C, _} <- Normalized],
+    [Color | Rest] = [C || {C, _} <- lists:flatten(Normalized)],
     SameColor = lists:all(fun(C) -> C==Color end, Rest),
     {ProperHand orelse Pairs, Pairs, ProperHand andalso SameColor}.
 

+ 7 - 2
apps/server/src/okey/okey_table.erl

@@ -589,9 +589,14 @@ do_action(SeatNum, #okey_reveal{discarded = ExtDiscarded, hand = ExtHand}, From,
 
     DeskState = StateData#okey_state.desk_state,
     Gosterme = DeskState#desk_state.gosterge,
-    {Revealed,_,_} = ?SCORING:check_reveal(Hand,Gosterme),
+
+%    CheckHand = [[{3,12},{2,12},{1,12},{2,9},{2,7},{2,8},{2,6},{2,4},
+%                    {4,8},{4,7},{4,9},{3,12},{3,13},{3,1}],[]],
+%    {Revealed,_,_,NormalizedHand} = ?SCORING:check_reveal(CheckHand,{2,3}),
+
+    {Revealed,_,_,Denormalized} = ?SCORING:check_reveal(Hand,Gosterme),
     case Revealed of
-        true -> do_game_action(SeatNum, {reveal, Discarded, Hand}, From, StateName, StateData);
+        true -> do_game_action(SeatNum, {reveal, Discarded, Denormalized}, From, StateName, StateData);
         false -> do_game_action(SeatNum, wrong_reveal, From, StateName, StateData)
     end;
 

+ 1 - 1
apps/web/priv/static/app/js/bootloader.js

@@ -310,7 +310,7 @@ function showRevealHand(o) {
         $reveal_deck.each(function(card){ card.$el && card.$el.remove(); });
 
         for (var i=0;i<2;i++)
-        for (var j=0;j<15;j++) {
+        for (var j=0;j<deck[i].length;j++) {
             var bin = deck[i][j];
             if (null != bin.value[0][2]) {
                 var card = new scope.Card({

+ 1 - 1
apps/web/src/logallow.erl

@@ -9,7 +9,7 @@ log_modules() -> [
 %    bullet_handler,
     okey_table,
     okey_desk,
-%    okey_scoring,
+    okey_scoring,
     journal,
 %    lucky,
 %    n2o_secret,