Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 79.21 KB | None | 0 0
  1. #ifndef PLAYER_H_INCLUDED
  2. #define PLAYER_H_INCLUDED
  3.  
  4. class player
  5. {
  6. public:
  7.     //player specifics
  8.     std::string name;
  9.     sf::IPAddress ip;
  10.     sf::SocketTCP Client;
  11.     sf::SocketTCP Client2; //only for stop commands
  12.     bool ai;
  13.     int pid;
  14.  
  15.     gamesettings settings;
  16.  
  17.  
  18.     // hand specifics
  19.     std::vector<Tile> menzen;
  20.     std::vector<std::vector<Tile> > open; //render main vector backwards, inside vectors normally
  21.     std::vector<Tile> discards;
  22.     std::vector<Tile> waits;
  23.     std::vector<Tile> furitile;
  24.     Tile tsumopai;
  25.  
  26.     Tile win_pai;
  27.     int won_from;
  28.  
  29.     int riichi;
  30.     int kans;
  31.     int won; //0=not won, 1=ron, 2=tsumo, 3=chakan, 4=rinshan
  32.     bool openriichi;
  33.     bool rtilepon; //check to turn the next discard if riichi-discard was called
  34.     bool nodraw; //important for pons/chis etc.
  35.     bool nokandraw;
  36.  
  37.     bool stopbutton; //if this is true, immediatly stop sending buttons!
  38.     SYSTEMTIME ST;
  39.  
  40.     bool riichifuri;
  41.  
  42.     bool none_bt, riichi_bt, oriichi_bt, tsumo_bt, ron_bt, chi_bt, pon_bt, kan_bt, reshuffle_bt;
  43.  
  44.     int wind;
  45.     g3::big_int pts;
  46.  
  47.     player()
  48.     {
  49.         name="Nuhp";
  50.         ai=0;
  51.         pid=0;
  52.         won_from=0;
  53.         riichi=0;
  54.         kans=0;
  55.         won=0;
  56.         openriichi = 0;
  57.         rtilepon=0;
  58.         nodraw=0;
  59.         nokandraw=0;
  60.         stopbutton=0;
  61.         wind=ton;
  62.         pts=25000;
  63.         riichifuri=false;
  64.         none_bt=false;
  65.         riichi_bt=false;
  66.         oriichi_bt=false;
  67.         tsumo_bt=false;
  68.         ron_bt=false;
  69.         chi_bt=false;
  70.         pon_bt=false;
  71.         kan_bt=false;
  72.         reshuffle_bt=false;
  73.     }
  74.  
  75.     std::string update_st()
  76.     {
  77.         std::stringstream sstr;
  78.  
  79.         GetSystemTime(&ST);
  80.         sstr << "[" << ST.wHour<< ":"<<ST.wMinute<<":"<<ST.wSecond<<":"<< ST.wMilliseconds<<"] ";
  81.  
  82.         return sstr.str();
  83.     }
  84.  
  85.     void send_buttons()
  86.     {
  87.         if(ip=="255.255.255.255")
  88.         {
  89.             return;
  90.         }
  91.         sf::Packet pack;
  92.         sf::Int8 request = 3;
  93.         pack << request;
  94.         pack << none_bt << riichi_bt << oriichi_bt << tsumo_bt << ron_bt << chi_bt << pon_bt << kan_bt << reshuffle_bt;
  95.         Client.Send(pack);
  96.         network_stream << std::endl << update_st()  << "Sent Request-ID 3 to " << ip << " with " << pack.GetDataSize() << "B" <<std::endl;
  97.         pack.Clear();
  98.     }
  99.  
  100.     void send_player_update(sf::SocketTCP& TClient, sf::IPAddress& tip)
  101.     {
  102.         sf::Packet pack;
  103.         sf::Int8 request = 1;
  104.         pack << request;
  105.         sf::Int8 men_size = menzen.size();
  106.         sf::Int8 open_size = open.size();
  107.  
  108.         sf::Int8 twind=wind;
  109.         pack << twind;
  110.         pack << men_size;
  111.         for(unsigned int a=0; a!=menzen.size(); a++)
  112.         {
  113.             pack << menzen[a];
  114.         }
  115.         pack << tsumopai;
  116.         pack << open_size;
  117.         for(unsigned int a=0; a!=open.size(); a++)
  118.         {
  119.             sf::Int8 open2_size = open[a].size();
  120.             pack << open2_size;
  121.             for(unsigned int b=0; b!=open[a].size(); b++)
  122.             {
  123.                 pack << open[a][b];
  124.             }
  125.         }
  126.  
  127.         sf::Int8 disc_size = discards.size();
  128.         pack << disc_size;
  129.         for(unsigned int a=0; a!=discards.size(); a++)
  130.         {
  131.             pack << discards[a];
  132.         }
  133.         pack << riichi;
  134.         pack << pts;
  135.         if(TClient.Send(pack)==sf::Socket::Done)
  136.         {
  137.             network_stream << std::endl << update_st()  << "Sent Request-ID 1 to " << tip << " with " << pack.GetDataSize() << "B" <<std::endl;
  138.         }
  139.         else
  140.         {
  141.             network_stream << std::endl << update_st()  << "Sending of Request ID 1 to " << tip << " failed!"  <<std::endl;
  142.         }
  143.         pack.Clear();
  144.     }
  145.  
  146.     void send_other_player_update(sf::SocketTCP& TClient, sf::IPAddress& tip, int mode=0)
  147.     {
  148.         sf::Packet pack;
  149.         sf::Int8 request = 4;
  150.         pack << request;
  151.         sf::Int8 men_size = menzen.size();
  152.         sf::Int8 open_size = open.size();
  153.  
  154.  
  155.         sf::Int8 twind=wind;
  156.         pack << twind;
  157.         pack << men_size;
  158.         std::vector<Tile> tmenzen=menzen;
  159.         for(unsigned int a=0; a!=tmenzen.size(); a++)
  160.         {
  161.             if(!openriichi&&mode==0)
  162.             {
  163.                 tmenzen[a]=Tile(m,1);
  164.             }
  165.             pack << tmenzen[a];
  166.         }
  167.         Tile ttsumopai=tsumopai;
  168.         if(ttsumopai!=deftile&&!openriichi&&mode==0)
  169.         {
  170.             ttsumopai=Tile(m,1);
  171.         }
  172.         pack << ttsumopai;
  173.         pack << open_size;
  174.         for(unsigned int a=0; a!=open.size(); a++)
  175.         {
  176.             sf::Int8 open2_size = open[a].size();
  177.             pack << open2_size;
  178.             for(unsigned int b=0; b!=open[a].size(); b++)
  179.             {
  180.                 pack << open[a][b];
  181.             }
  182.         }
  183.  
  184.         sf::Int8 disc_size = discards.size();
  185.         pack << disc_size;
  186.         for(unsigned int a=0; a!=discards.size(); a++)
  187.         {
  188.             pack << discards[a];
  189.         }
  190.         pack << riichi;
  191.         pack << pts;
  192.         TClient.Send(pack);
  193.         network_stream << std::endl << update_st()  << "Sent Request-ID 4 to " << tip << " with " << pack.GetDataSize() << "B" <<std::endl;
  194.         pack.Clear();
  195.     }
  196.  
  197.     int receive_clickpos(int mode=0)
  198.     {
  199.         if(ai&&tsumopai!=deftile)
  200.         {
  201.             sf::Sleep(0.500);
  202.             return -1;
  203.         }
  204.         else if(ai)
  205.         {
  206.             sf::Sleep(0.500);
  207.             return 0;
  208.         }
  209.  
  210.         if(stopbutton)
  211.         {
  212.             return 0;
  213.         }
  214.  
  215.  
  216.         sf::Packet pack;
  217.         sf::Int8 request = 0;
  218.         pack << request;
  219.         sf::Int8 tmode=mode;
  220.         pack << tmode;
  221.         Client.Send(pack);
  222.         network_stream << std::endl << update_st()  << "Sent Request-ID 0 to " << ip << " with " << pack.GetDataSize() << "B" <<std::endl;
  223.         pack.Clear();
  224.         sf::Packet pack2;
  225.         Client.Receive(pack2);
  226.         sf::Int32 tclickpos;
  227.         pack2 >> tclickpos;
  228.  
  229.         pack2.Clear();
  230.         int clickpos=tclickpos;
  231.         network_stream << std::endl << update_st()  << "Received Clickpos " << clickpos << " from " << ip << std::endl;
  232.         return clickpos;
  233.     }
  234.  
  235.     void request_udpclickpos(int pos, Tile& kantile)
  236.     {
  237.         sf::Packet pack;
  238.         sf::Int8 request = 9;
  239.         pack << request;
  240.         sf::Int8 tpos=pos;
  241.         pack << tpos;
  242.         pack << kantile;
  243.  
  244.            Client.Send(pack);
  245.             network_stream << std::endl << update_st()  << "Sent Request-ID 9 to " << ip << " with " << pack.GetDataSize() << "B" <<std::endl;
  246.  
  247.         pack.Clear();
  248.     }
  249.  
  250.  
  251.     void darken_hand(std::vector<int>& works)
  252.     {
  253.         tsumopai.highlight=0;
  254.         for(unsigned int a=0; a!=menzen.size(); a++)
  255.         {
  256.             menzen[a].highlight=0;
  257.         }
  258.  
  259.         for(unsigned int a=0; a!=works.size(); a++)
  260.         {
  261.             if(works[a]==-1)
  262.             {
  263.                 tsumopai.highlight=1;
  264.             }
  265.             else
  266.             {
  267.                 menzen[works[a]].highlight=1;
  268.             }
  269.         }
  270.     }
  271.  
  272.     void darken_hand()
  273.     {
  274.         tsumopai.highlight=0;
  275.         for(unsigned int a=0; a!=menzen.size(); a++)
  276.         {
  277.             menzen[a].highlight=0;
  278.         }
  279.     }
  280.  
  281.     void darken_hand(std::vector<std::vector<int> >& works)
  282.     {
  283.         tsumopai.highlight=0;
  284.         for(unsigned int a=0; a!=menzen.size(); a++)
  285.         {
  286.             menzen[a].highlight=0;
  287.         }
  288.  
  289.         for(unsigned int a=0; a!=works.size(); a++)
  290.         {
  291.             for(unsigned int b=0; b!=works[a].size(); b++)
  292.             {
  293.                 if(works[a][b]==-1)
  294.                 {
  295.                     tsumopai.highlight=1;
  296.                 }
  297.                 else
  298.                 {
  299.                     menzen[works[a][b]].highlight=1;
  300.                 }
  301.             }
  302.         }
  303.     }
  304.  
  305.     void undarken_hand()
  306.     {
  307.         tsumopai.highlight=1;
  308.         for(unsigned int a=0; a!=menzen.size(); a++)
  309.         {
  310.             menzen[a].highlight=1;
  311.         }
  312.  
  313.     }
  314.  
  315.  
  316.     void sort_hand()
  317.     {
  318.         std::sort(menzen.begin(),menzen.end());
  319.     }
  320.  
  321.     void walldraw(std::vector<Tile>& wall)
  322.     {
  323.         for(unsigned int a=0; a!=wall.size(); a++)
  324.         {
  325.             if(wall[a]!=deftile)
  326.             {
  327.                 tsumopai=wall[a];
  328.                 wall[a]--;
  329.                 break;
  330.             }
  331.         }
  332.     }
  333.  
  334.     void init_hand(std::vector<Tile>& wall)
  335.     {
  336.         int count=0;
  337.         for(unsigned int a=0; count!=13; a++)
  338.         {
  339.             if(wall[a]!=deftile)
  340.             {
  341.                 menzen.push_back(wall[a]);
  342.                 count++;
  343.                 wall[a]--;
  344.             }
  345.         }
  346.         sort_hand();
  347.     }
  348.  
  349.     void kandraw(std::vector<Tile>& wall)
  350.     {
  351.         int pos=0;
  352.         if(wall[134]!=deftile)
  353.         {
  354.             pos = 134;
  355.         }
  356.         else if(wall[135]!=deftile)
  357.         {
  358.             pos = 135;
  359.         }
  360.         else if(wall[132]!=deftile)
  361.         {
  362.             pos = 132;
  363.         }
  364.         else if(wall[133]!=deftile)
  365.         {
  366.             pos=133;
  367.         }
  368.         tsumopai=wall[pos];
  369.         wall[pos]--;
  370.     }
  371.  
  372.     void flip_dora(std::vector<Tile>& wall)
  373.     {
  374.         if(wall[124].visible)
  375.         {
  376.             wall[122].visible=1;
  377.         }
  378.         else if(wall[126].visible)
  379.         {
  380.             wall[124].visible=1;
  381.         }
  382.         else if(wall[128].visible)
  383.         {
  384.             wall[126].visible=1;
  385.         }
  386.         else if(wall[130].visible)
  387.         {
  388.             wall[128].visible=1;
  389.         }
  390.         else
  391.         {
  392.             wall[130].visible=1;
  393.         }
  394.     }
  395.  
  396.     void discard(const int& pos)
  397.     {
  398.         if(pos==-1||pos==tsumopai_tile)
  399.         {
  400.             discards.push_back(tsumopai);
  401.             tsumopai--;
  402.             return;
  403.         }
  404.         else
  405.         {
  406.  
  407.             if(rtilepon)
  408.             {
  409.                 menzen[pos].position=1;
  410.                 rtilepon=false;
  411.             }
  412.             discards.push_back(menzen[pos]);
  413.             menzen.erase(menzen.begin()+pos);
  414.             if(tsumopai!=deftile)
  415.             {
  416.                 menzen.push_back(tsumopai);
  417.             }
  418.             tsumopai--;
  419.             sort_hand();
  420.         }
  421.     }
  422.     void rdiscard(const int& pos)
  423.     {
  424.         if(pos==-1||pos==tsumopai_tile)
  425.         {
  426.             tsumopai.position=1;
  427.             discards.push_back(tsumopai);
  428.             tsumopai--;
  429.             return;
  430.         }
  431.         else
  432.         {
  433.             menzen[pos].position=1;
  434.             discards.push_back(menzen[pos]);
  435.             menzen.erase(menzen.begin()+pos);
  436.             if(tsumopai!=deftile)
  437.             {
  438.                 menzen.push_back(tsumopai);
  439.             }
  440.             tsumopai--;
  441.             sort_hand();
  442.         }
  443.     }
  444.  
  445.     int relpos(const player& p2)
  446.     {
  447.         if(wind==ton)
  448.         {
  449.             if(p2.wind==nan2)
  450.             {
  451.                 return 1;
  452.             }
  453.             if(p2.wind==shaa)
  454.             {
  455.                 return 2;
  456.             }
  457.             if(p2.wind==pei)
  458.             {
  459.                 return 3;
  460.             }
  461.         }
  462.         else if(wind==nan2)
  463.         {
  464.             if(p2.wind==ton)
  465.             {
  466.                 return 3;
  467.             }
  468.             if(p2.wind==shaa)
  469.             {
  470.                 return 1;
  471.             }
  472.             if(p2.wind==pei)
  473.             {
  474.                 return 2;
  475.             }
  476.         }
  477.         else if(wind==shaa)
  478.         {
  479.             if(p2.wind==nan2)
  480.             {
  481.                 return 3;
  482.             }
  483.             if(p2.wind==ton)
  484.             {
  485.                 return 2;
  486.             }
  487.             if(p2.wind==pei)
  488.             {
  489.                 return 1;
  490.             }
  491.         }
  492.         else if(wind==pei)
  493.         {
  494.             if(p2.wind==nan2)
  495.             {
  496.                 return 2;
  497.             }
  498.             if(p2.wind==shaa)
  499.             {
  500.                 return 3;
  501.             }
  502.             if(p2.wind==ton)
  503.             {
  504.                 return 1;
  505.             }
  506.         }
  507.         return 0;
  508.  
  509.     }
  510.  
  511.     void ponchi(player& p2, int pos1, int pos2)
  512.     {
  513.         Tile called=p2.discards[p2.discards.size()-1];
  514.         if(called.position)
  515.         {
  516.             p2.rtilepon=true;
  517.         }
  518.         called.position=1;
  519.         p2.discards[p2.discards.size()-1].norend=1;
  520.  
  521.         std::vector<Tile> tmp;
  522.  
  523.         if(relpos(p2)==1)
  524.         {
  525.             tmp.push_back(called);
  526.             tmp.push_back(menzen[pos2]);
  527.             tmp.push_back(menzen[pos1]);
  528.         }
  529.         if(relpos(p2)==2)
  530.         {
  531.             tmp.push_back(menzen[pos2]);
  532.             tmp.push_back(called);
  533.             tmp.push_back(menzen[pos1]);
  534.         }
  535.         if(relpos(p2)==3)
  536.         {
  537.             tmp.push_back(menzen[pos2]);
  538.             tmp.push_back(menzen[pos1]);
  539.             tmp.push_back(called);
  540.         }
  541.         open.push_back(tmp);
  542.         menzen.erase(menzen.begin()+pos2);
  543.         menzen.erase(menzen.begin()+pos1);
  544.  
  545.     }
  546.  
  547.     void kan(int pos1, int pos2,int pos3, int pos4)
  548.     {
  549.         std::vector<Tile> tmp;
  550.         std::vector<int> postmp;
  551.         postmp.push_back(pos1);
  552.         postmp.push_back(pos2);
  553.         postmp.push_back(pos3);
  554.         postmp.push_back(pos4);
  555.         std::sort(postmp.begin(),postmp.end());
  556.         pos1=postmp[0];
  557.         pos2=postmp[1];
  558.         pos3=postmp[2];
  559.         pos4=postmp[3];
  560.         if(pos1==-1)
  561.         {
  562.             pos1=postmp[1];
  563.             pos2=postmp[2];
  564.             pos3=postmp[3];
  565.             pos4=-1;
  566.         }
  567.  
  568.         tmp.push_back(menzen[pos1]);
  569.         tmp.push_back(menzen[pos2]);
  570.         tmp.push_back(menzen[pos3]);
  571.         if(pos4==-1)
  572.         {
  573.             tmp.push_back(tsumopai);
  574.             tsumopai--;
  575.         }
  576.         else
  577.         {
  578.             tmp.push_back(menzen[pos4]);
  579.             menzen.erase(menzen.begin()+pos4);
  580.         }
  581.         menzen.erase(menzen.begin()+pos3);
  582.         menzen.erase(menzen.begin()+pos2);
  583.         menzen.erase(menzen.begin()+pos1);
  584.         tmp[0].visible=false;
  585.         tmp[3].visible=false;
  586.         open.push_back(tmp);
  587.         kans++;
  588.         if(tsumopai!=deftile)
  589.         {
  590.             menzen.push_back(tsumopai);
  591.             tsumopai--;
  592.         }
  593.  
  594.         sort_hand();
  595.     }
  596.  
  597.     void latekan(const int& pos)
  598.     {
  599.         if(pos==-1)
  600.         {
  601.             for(unsigned int a=0; a!=open.size(); a++)
  602.             {
  603.                 if(std::count(open[a].begin(),open[a].end(),tsumopai))
  604.                 {
  605.                     for(unsigned int b=0; b!=open[a].size(); b++)
  606.                     {
  607.                         if(open[a][b].position)
  608.                         {
  609.                             Tile inserting=tsumopai;
  610.                             inserting.position=1;
  611.                             open[a].insert(open[a].begin()+b,inserting);
  612.                             break;
  613.                         }
  614.                     }
  615.                     break;
  616.                 }
  617.             }
  618.             tsumopai--;
  619.         }
  620.         else
  621.         {
  622.             for(unsigned int a=0; a!=open.size(); a++)
  623.             {
  624.                 if(std::count(open[a].begin(),open[a].end(),menzen[pos]))
  625.                 {
  626.                     for(unsigned int b=0; b!=open[a].size(); b++)
  627.                     {
  628.                         if(open[a][b].position)
  629.                         {
  630.                             Tile inserting=menzen[pos];
  631.                             inserting.position=1;
  632.                             open[a].insert(open[a].begin()+b,inserting);
  633.                             break;
  634.                         }
  635.                     }
  636.                     break;
  637.                 }
  638.             }
  639.             menzen.erase(menzen.begin()+pos);
  640.             menzen.push_back(tsumopai);
  641.             tsumopai--;
  642.             sort_hand();
  643.         }
  644.         kans++;
  645.         sort_hand();
  646.     }
  647.  
  648.     void daiminkan(player& p2, const int& pos1, const int& pos2, const int& pos3)
  649.     {
  650.         Tile called=p2.discards[p2.discards.size()-1];
  651.         if(called.position)
  652.         {
  653.             p2.rtilepon=true;
  654.         }
  655.         called.position=1;
  656.         p2.discards[p2.discards.size()-1];
  657.  
  658.         std::vector<Tile> tmp;
  659.  
  660.         if(relpos(p2)==1)
  661.         {
  662.             tmp.push_back(called);
  663.             tmp.push_back(menzen[pos3]);
  664.             tmp.push_back(menzen[pos2]);
  665.             tmp.push_back(menzen[pos1]);
  666.         }
  667.         if(relpos(p2)==2)
  668.         {
  669.             tmp.push_back(menzen[pos3]);
  670.             tmp.push_back(menzen[pos2]);
  671.             tmp.push_back(called);
  672.             tmp.push_back(menzen[pos1]);
  673.         }
  674.         if(relpos(p2)==3)
  675.         {
  676.             tmp.push_back(menzen[pos3]);
  677.             tmp.push_back(menzen[pos2]);
  678.             tmp.push_back(menzen[pos1]);
  679.             tmp.push_back(called);
  680.         }
  681.  
  682.         open.push_back(tmp);
  683.  
  684.         menzen.erase(menzen.begin()+pos3);
  685.         menzen.erase(menzen.begin()+pos2);
  686.         menzen.erase(menzen.begin()+pos1);
  687.         kans++;
  688.  
  689.     }
  690.  
  691.     int count_dora(const std::vector<Tile>& wall)
  692.     {
  693.         int dorano=0;
  694.         std::vector<Tile> doras;
  695.  
  696.         for(unsigned int a=0; a!=wall.size(); a++)
  697.         {
  698.             if(wall[a].visible)
  699.             {
  700.                 doras.push_back(wall[a]+1);
  701.             }
  702.         }
  703.         for(unsigned int a=0; a!=menzen.size(); a++)
  704.         {
  705.             for(unsigned int b=0; b!=doras.size(); b++)
  706.             {
  707.                 if(menzen[a]==doras[b])
  708.                 {
  709.                     dorano++;
  710.                 }
  711.             }
  712.         }
  713.         for(unsigned int a=0; a!=open.size(); a++)
  714.         {
  715.             for(unsigned int b=0; b!=open[a].size(); b++)
  716.             {
  717.                 for(unsigned int c=0; c!=doras.size(); c++)
  718.                 {
  719.                     if(open[a][b]==doras[c])
  720.                     {
  721.                         dorano++;
  722.                     }
  723.                 }
  724.             }
  725.         }
  726.  
  727.         return dorano;
  728.     }
  729.  
  730.     int count_udora(const std::vector<Tile>& wall, const Tile& wtile)
  731.     {
  732.         int dorano=0;
  733.         //uradora
  734.         std::vector<Tile> doras;
  735.  
  736.         for(unsigned int a=0; a!=wall.size(); a++)
  737.         {
  738.             if(wall[a].visible)
  739.             {
  740.                 doras.push_back(wall[a+1]+1);
  741.             }
  742.         }
  743.         for(unsigned int a=0; a!=menzen.size(); a++)
  744.         {
  745.             for(unsigned int b=0; b!=doras.size(); b++)
  746.             {
  747.                 if(menzen[a]==doras[b])
  748.                 {
  749.                     dorano++;
  750.                 }
  751.             }
  752.         }
  753.         for(unsigned int a=0; a!=open.size(); a++)
  754.         {
  755.             for(unsigned int b=0; b!=open[a].size(); b++)
  756.             {
  757.                 for(unsigned int c=0; c!=doras.size(); c++)
  758.                 {
  759.                     if(open[a][b]==doras[c])
  760.                     {
  761.                         dorano++;
  762.                     }
  763.                 }
  764.             }
  765.         }
  766.         for(unsigned int a=0; a!=doras.size(); a++)
  767.         {
  768.             if(doras[a]==wtile)
  769.             {
  770.                 dorano++;
  771.                 break;
  772.             }
  773.         }
  774.  
  775.         return dorano;
  776.     }
  777.  
  778.     unsigned int get_han(const int& rwind, const int& wturn, const int& tileno, const Tile& wtile, const int& winmode, const handconfig& config, const int& fu, int dorano, int akadorano, int uradorano, int& yakuman_only)
  779.     {
  780.  
  781.         yakuman_only=false;
  782.         bool ippatsu=false;
  783.         int poscount=0;
  784.         for(unsigned int a=0; a!=discards.size(); a++)
  785.         {
  786.             if(discards[a].position)
  787.             {
  788.                 poscount++;
  789.                 if(a==discards.size()-1)
  790.                 {
  791.                     ippatsu=true;
  792.                 }
  793.             }
  794.         }
  795.         if(poscount>1)
  796.         {
  797.             ippatsu=false;
  798.         }
  799.  
  800.         int hantotal=0;
  801.         int yakuman=0;
  802.         int add_yakuman=0;
  803.         std::vector<Tile> tmenzen=menzen; //menzen+wtile
  804.         tmenzen.push_back(wtile);
  805.  
  806.         for(unsigned int a=0; a!=settings.yakulist.size(); a++)
  807.         {
  808.             if(settings.yakulist[a].check_true(tmenzen,open, rwind, wind, riichi, wturn, tileno, wtile, winmode, config,fu,openriichi,ippatsu))
  809.             {
  810.                 if(check_(open))
  811.                 {
  812.                     hantotal+=settings.yakulist[a].openhan;
  813.                     if(settings.yakulist[a].openhan>=26)
  814.                     {
  815.                         add_yakuman+=settings.yakulist[a].openhan/13;
  816.                     }
  817.                     else if(settings.yakulist[a].openhan>=13)
  818.                     {
  819.                         yakuman++;
  820.                     }
  821.                 }
  822.                 else
  823.                 {
  824.                     hantotal+=settings.yakulist[a].han;
  825.                     if(settings.yakulist[a].han>=26)
  826.                     {
  827.                         add_yakuman+=settings.yakulist[a].han/13;
  828.                     }
  829.                     else if(settings.yakulist[a].han>=13)
  830.                     {
  831.                         yakuman++;
  832.                     }
  833.                 }
  834.             }
  835.  
  836.         }
  837.         hantotal+=dorano;
  838.         hantotal+=akadorano;
  839.         hantotal+=uradorano;
  840.         if(!settings.han_max)
  841.         {
  842.             settings.han_max=hantotal;
  843.         }
  844.         if(settings.aotenjou)
  845.         {
  846.             return std::max(hantotal,settings.han_max);
  847.         }
  848.         if(hantotal>=13&&!yakuman)
  849.         {
  850.             return std::max(hantotal,settings.han_max);
  851.         }
  852.         if(!yakuman)
  853.         {
  854.             return hantotal;
  855.         }
  856.         if(settings.yakuman_mode==0&&add_yakuman)
  857.         {
  858.             yakuman_only=true;
  859.             return (yakuman+add_yakuman)*13;
  860.         }
  861.         if(settings.yakuman_mode==0&&yakuman)
  862.         {
  863.             yakuman_only=true;
  864.             return yakuman*13;
  865.         }
  866.         if(settings.yakuman_mode==1&&add_yakuman)
  867.         {
  868.             yakuman_only=true;
  869.             return 26;
  870.         }
  871.         if(settings.yakuman_mode==1&&yakuman)
  872.         {
  873.             yakuman_only=true;
  874.             return 13;
  875.         }
  876.         if(settings.yakuman_mode==2&&yakuman)
  877.         {
  878.             yakuman_only=true;
  879.             return yakuman*13;
  880.         }
  881.         if(settings.yakuman_mode==3&&yakuman)
  882.         {
  883.             yakuman_only=true;
  884.             return 13;
  885.         }
  886.         return 0;
  887.     }
  888.  
  889.     int get_fu(const handconfig& config=handconfig(), const int& rwind=ton, const int& winmode=0, const Tile& wtile=deftile)
  890.     {
  891.         //check Chiitoitsu
  892.         if(config.size()==7)
  893.         {
  894.             return 25;
  895.         }
  896.  
  897.         //Fuutei
  898.         int futotal=20;
  899.  
  900.         //Menzen Ron / Min Tsumo
  901.         if(winmode==0&&!check_(open))
  902.         {
  903.             futotal+=10;
  904.         }
  905.         if(winmode==1&&check_(open))
  906.         {
  907.             futotal+=2;
  908.         }
  909.  
  910.         int ank=0;
  911.         //Mentsu
  912.         for(unsigned int a=0; a!=open.size(); a++)
  913.         {
  914.             if(open[a].size()==4&&open[a][0].value>1&&open[a][0].value<9&&open[a][0].visible==false)
  915.             {
  916.                 futotal+=16;
  917.                 ank++;
  918.             }
  919.             else if(open[a].size()==4&&(open[a][0].value==1||open[a][0].value>8)&&open[a][0].visible==false)
  920.             {
  921.                 futotal+=32;
  922.                 ank++;
  923.             }
  924.             else if(open[a].size()==4&&open[a][0].value>1&&open[a][0].value<9)
  925.             {
  926.                 futotal+=8;
  927.             }
  928.             else if(open[a].size()==4&&(open[a][0].value==1||open[a][0].value>8))
  929.             {
  930.                 futotal+=16;
  931.             }
  932.             else if(m_type(open[a])==2&&open[a][0].value>1&&open[a][0].value<9)
  933.             {
  934.                 futotal+=2;
  935.             }
  936.             else if(m_type(open[a])==2&&(open[a][0].value==1||open[a][0].value>8))
  937.             {
  938.                 futotal +=4;
  939.             }
  940.         }
  941.  
  942.         for(unsigned int a=0; a!=config.size(); a++)
  943.         {
  944.             if(m_type(config[a])==2&&config[a][0].value>1&&config[a][0].value<9)
  945.             {
  946.                 if(config[a][0]==wtile)
  947.                 {
  948.                     int roncnt=0;
  949.                     for(unsigned int c=0; c!=config.size(); c++)
  950.                     {
  951.                         for(unsigned int d=0; d!=config[c].size(); d++)
  952.                         {
  953.                             if(config[c][d]==wtile)
  954.                             {
  955.                                 roncnt++;
  956.                             }
  957.                         }
  958.                     }
  959.                     if(roncnt<4)
  960.                     {
  961.                         futotal+=2;
  962.                     }
  963.                     else
  964.                     {
  965.                         futotal+=4;
  966.                         ank++;
  967.                     }
  968.                 }
  969.                 else
  970.                 {
  971.                     futotal+=4;
  972.                     ank++;
  973.                 }
  974.  
  975.             }
  976.             else if(m_type(config[a])==2&&(config[a][0].value==1||config[a][0].value>8))
  977.             {
  978.                 if(config[a][0]==wtile)
  979.                 {
  980.                     int roncnt=0;
  981.                     for(unsigned int c=0; c!=config.size(); c++)
  982.                     {
  983.                         for(unsigned int d=0; d!=config[c].size(); d++)
  984.                         {
  985.                             if(config[c][d]==wtile)
  986.                             {
  987.                                 roncnt++;
  988.                             }
  989.                         }
  990.                     }
  991.                     if(roncnt<4)
  992.                     {
  993.                         futotal+=4;
  994.                     }
  995.                     else
  996.                     {
  997.                         futotal+=8;
  998.                         ank++;
  999.                     }
  1000.                 }
  1001.                 else
  1002.                 {
  1003.                     futotal+=8;
  1004.                     ank++;
  1005.                 }
  1006.             }
  1007.             else if(m_type(config[a])==3&&config[a][0]==rwind&&rwind==wind)
  1008.             {
  1009.                 futotal +=4;
  1010.             }
  1011.             else if(m_type(config[a])==3&&(config[a][0].value==haku||config[a][0].value==hatsu||config[a][0].value==chun||config[a][0].value==rwind||config[a][0].value==wind))
  1012.             {
  1013.                 futotal+=2;
  1014.             }
  1015.         }
  1016.  
  1017.         //checking possible waits
  1018.         bool ryanmen(false),shanpon(false),tanki(false),penchan(false), kanchan(false);
  1019.         for(unsigned int a=0; a!=config.size(); a++)
  1020.         {
  1021.             for(unsigned int b=0; b!=config[a].size(); b++)
  1022.             {
  1023.                 if(config[a][b]!=wtile)
  1024.                 {
  1025.                     continue;
  1026.                 }
  1027.                 std::vector<Tile> temp = config[a];
  1028.                 temp.erase(temp.begin()+b);
  1029.                 if(temp.size()==1)
  1030.                 {
  1031.                     tanki=true;
  1032.                     break;
  1033.                 }
  1034.                 else if(temp[1]==temp[0]+1&&temp[0]!=1&&temp[0]!=8)
  1035.                 {
  1036.                     ryanmen=true;
  1037.                     break;
  1038.                 }
  1039.                 else if(temp[1]==temp[0]+1&&(temp[0]==1||temp[0]==8))
  1040.                 {
  1041.                     penchan=true;
  1042.                     break;
  1043.                 }
  1044.                 else if(temp[1]==temp[0]+2)
  1045.                 {
  1046.                     kanchan=true;
  1047.                     break;
  1048.                 }
  1049.                 else if(temp[1]==temp[0])
  1050.                 {
  1051.                     shanpon=true;
  1052.                     break;
  1053.                 }
  1054.             }
  1055.         }
  1056.         //prioritize han from yaku (sanankou,pinfu) over fu from waits
  1057.         if((futotal==20||(winmode==0&&futotal==30))&&!check_(open)&&ryanmen)
  1058.         {
  1059.             return futotal;
  1060.         }
  1061.         else if(ank>=3&&tanki&&ryanmen)
  1062.         {
  1063.             return futotal;
  1064.         }
  1065.         else if(tanki||penchan||kanchan)
  1066.         {
  1067.             futotal+=2;
  1068.         }
  1069.  
  1070.         //Kuipinfu
  1071.         if(futotal<=20&&check_(open))
  1072.         {
  1073.             return 30;
  1074.         }
  1075.  
  1076.         return futotal;
  1077.     }
  1078.  
  1079.     g3::big_int get_payment(const player& p2, const int& rwind, const int& wturn, const int& tileno, const Tile& wtile, const int& winmode, const int& dorano, const int& udorano, std::vector<std::string>& yakunames, std::vector<int>& hanvalues, std::string& totals, bool wareme)
  1080.     {
  1081.         bool ron;
  1082.         if(winmode==1||winmode==3)
  1083.         {
  1084.             ron=true;
  1085.         }
  1086.         else
  1087.         {
  1088.             ron=false;
  1089.         }
  1090.  
  1091.         bool ippatsu=false;
  1092.         int poscount=0;
  1093.         for(unsigned int a=0; a!=discards.size(); a++)
  1094.         {
  1095.             if(discards[a].position)
  1096.             {
  1097.                 poscount++;
  1098.                 if(a==discards.size()-1)
  1099.                 {
  1100.                     ippatsu=true;
  1101.                 }
  1102.             }
  1103.         }
  1104.         if(poscount>1)
  1105.         {
  1106.             ippatsu=false;
  1107.         }
  1108.  
  1109.         std::vector<Tile> tmenzen=menzen;
  1110.         tmenzen.push_back(wtile);
  1111.         std::vector<handconfig> posconf = get_config(tmenzen);
  1112.         std::vector<g3::big_int> pospay(posconf.size(),0);
  1113.         std::vector<int> poshan(posconf.size(),0);
  1114.         std::vector<g3::big_int> posfu(posconf.size(),0);
  1115.         std::vector<int> yakuman_only(posconf.size(),0);
  1116.  
  1117.         int akadora=0;
  1118.         if(wtile.aka)
  1119.         {
  1120.             akadora++;
  1121.         }
  1122.         for(unsigned int a=0; a!=menzen.size(); a++)
  1123.         {
  1124.             if(menzen[a].aka)
  1125.             {
  1126.                 akadora++;
  1127.             }
  1128.         }
  1129.         for(unsigned int a=0; a!=open.size(); a++)
  1130.         {
  1131.             for(unsigned int b=0; b!=open[a].size(); b++)
  1132.             {
  1133.                 if(open[a][b].aka)
  1134.                 {
  1135.                     akadora++;
  1136.                 }
  1137.             }
  1138.         }
  1139.  
  1140.         for(unsigned int a=0; a!=posconf.size(); a++)
  1141.         {
  1142.             g3::big_int payment;
  1143.             g3::big_int fu=get_fu(posconf[a], rwind, winmode, wtile);
  1144.  
  1145.             int multiplier;
  1146.  
  1147.             if(wind==ton&&!ron)
  1148.             {
  1149.                 multiplier=2;
  1150.             }
  1151.             else if(wind==ton&&ron)
  1152.             {
  1153.                 multiplier=6;
  1154.             }
  1155.             else if(!ron&&p2.wind!=ton)
  1156.             {
  1157.                 multiplier=1;
  1158.             }
  1159.             else if(!ron&&p2.wind==ton)
  1160.             {
  1161.                 multiplier=2;
  1162.             }
  1163.             else if(ron)
  1164.             {
  1165.                 multiplier=4;
  1166.             }
  1167.  
  1168.             if(fu!=25)
  1169.             {
  1170.                 fu.round_fu();
  1171.             }
  1172.             int t_uradorano=0;
  1173.             if(riichi&&(settings.uradora==1||settings.uradora==3))
  1174.             {
  1175.                 t_uradorano=udorano;
  1176.             }
  1177.             else if(!riichi&&(settings.uradora==2||settings.uradora==3))
  1178.             {
  1179.                 t_uradorano=udorano;
  1180.             }
  1181.             int han = get_han(rwind, wturn, tileno, wtile, winmode, posconf[a],fu, dorano, akadora, t_uradorano,yakuman_only[a]);
  1182.  
  1183.             payment=g3::Get2powX(han+2);
  1184.             payment *= fu;
  1185.             //limits
  1186.             if(!settings.aotenjou)
  1187.             {
  1188.                 if(han<6&&payment>2000)
  1189.                 {
  1190.                     payment=2000;
  1191.                 }
  1192.                 else if(han==6||han==7)
  1193.                 {
  1194.                     payment=3000;
  1195.                 }
  1196.                 else if(han==8||han==9||han==10)
  1197.                 {
  1198.                     payment=4000;
  1199.                 }
  1200.                 else if(han==11||han==12)
  1201.                 {
  1202.                     payment=6000;
  1203.                 }
  1204.                 else if(han>=13)
  1205.                 {
  1206.                     payment=8000;
  1207.                     payment*=(han/13);
  1208.                 }
  1209.  
  1210.             }
  1211.             payment *= multiplier;
  1212.             if(wareme)
  1213.             {
  1214.                 payment *=settings.wareme_multi;
  1215.             }
  1216.             payment.round_100();
  1217.  
  1218.             pospay[a]=payment;
  1219.             posfu[a]=fu;
  1220.             poshan[a]=han;
  1221.         }
  1222.  
  1223.         int highest=0;
  1224.         int highpos=0;
  1225.         for(unsigned int a=0; a!=pospay.size(); a++)
  1226.         {
  1227.             if(pospay[a]>highest)
  1228.             {
  1229.                 highest=pospay[a];
  1230.                 highpos=a;
  1231.             }
  1232.         }
  1233.  
  1234.         std::stringstream sstr;
  1235.  
  1236.         sstr << poshan[highpos] << " Han ";
  1237.         if(!settings.aotenjou&&poshan[highpos]==5)
  1238.         {
  1239.             sstr << ": Mangan";
  1240.         }
  1241.         else if(!settings.aotenjou&&(poshan[highpos]==6||poshan[highpos]==7))
  1242.         {
  1243.             sstr << ": Haneman";
  1244.         }
  1245.         else if(!settings.aotenjou&&(poshan[highpos]==8||poshan[highpos]==9||poshan[highpos]==10))
  1246.         {
  1247.             sstr << ": Baiman";
  1248.         }
  1249.         else if(!settings.aotenjou&&(poshan[highpos]==11||poshan[highpos]==12))
  1250.         {
  1251.             sstr << ": Sanbaiman";
  1252.         }
  1253.         else if(!settings.aotenjou&&poshan[highpos]>=13)
  1254.         {
  1255.             sstr << ": Kazoe Yakuman";
  1256.         }
  1257.         else
  1258.         {
  1259.             sstr << posfu[highpos] << " Fu";
  1260.         }
  1261.  
  1262.         if(yakuman_only[highpos])
  1263.         {
  1264.             sstr.clear();
  1265.             int yakuman_number = poshan[highpos]/13;
  1266.             switch(yakuman_number)
  1267.             {
  1268.                 case 2: sstr << "Double ";break;
  1269.                 case 3: sstr << "Triple ";break;
  1270.                 case 4: sstr << "Quadruple ";break;
  1271.                 case 5: sstr << "Quintuple ";break;
  1272.                 case 6: sstr << "Sextuple ";break;
  1273.                 case 7: sstr << "Septuple ";break;
  1274.                 case 8: sstr << "Octuple ";break;
  1275.                 case 9: sstr << "Nonuple ";break;
  1276.                 default: break;
  1277.             }
  1278.             sstr << "Yakuman";
  1279.         }
  1280.         totals = sstr.str();
  1281.  
  1282.         if(yakunames.size()!=0)
  1283.         {
  1284.             return pospay[highpos];
  1285.         }
  1286.         if(dorano&&!yakuman_only[highpos])
  1287.         {
  1288.             yakunames.push_back("Dora");
  1289.             hanvalues.push_back(dorano);
  1290.         }
  1291.         if(akadora&&!yakuman_only[highpos])
  1292.         {
  1293.             yakunames.push_back("Akadora");
  1294.             hanvalues.push_back(akadora);
  1295.         }
  1296.         if(udorano&&riichi&&!yakuman_only[highpos])
  1297.         {
  1298.             yakunames.push_back("Uradora");
  1299.             hanvalues.push_back(udorano);
  1300.         }
  1301.         for(unsigned int a=0; a!=settings.yakulist.size(); a++)
  1302.         {
  1303.             std::vector<Tile> tmenzen=menzen;
  1304.             tmenzen.push_back(wtile);
  1305.             if(settings.yakulist[a].check_true(tmenzen,open, rwind, wind, riichi, wturn, tileno, wtile, winmode, posconf[highpos],posfu[highpos],openriichi,ippatsu))
  1306.             {
  1307.                 if(yakuman_only[highpos])
  1308.                 {
  1309.                    if(check_(open)&&settings.yakulist[a].openhan>=13)
  1310.                     {
  1311.                         yakunames.push_back(settings.yakulist[a].name);
  1312.                         int push_back_han = settings.yakulist[a].openhan;
  1313.                         if(push_back_han>=26&&(settings.yakuman_mode==2||settings.yakuman_mode==3))
  1314.                         {
  1315.                             push_back_han=13;
  1316.                         }
  1317.                         hanvalues.push_back(push_back_han);
  1318.                     }
  1319.                     else if(!check_(open)&&settings.yakulist[a].han>=13)
  1320.                     {
  1321.                         yakunames.push_back(settings.yakulist[a].name);
  1322.                         int push_back_han = settings.yakulist[a].han;
  1323.                         if(push_back_han>=26&&(settings.yakuman_mode==2||settings.yakuman_mode==3))
  1324.                         {
  1325.                             push_back_han=13;
  1326.                         }
  1327.                         hanvalues.push_back(push_back_han);
  1328.                     }
  1329.                 }
  1330.                 else
  1331.                 {
  1332.                     if(check_(open))
  1333.                     {
  1334.                         yakunames.push_back(settings.yakulist[a].name);
  1335.                         hanvalues.push_back(settings.yakulist[a].openhan);
  1336.                     }
  1337.                     else
  1338.                     {
  1339.                         yakunames.push_back(settings.yakulist[a].name);
  1340.                         hanvalues.push_back(settings.yakulist[a].han);
  1341.                     }
  1342.                 }
  1343.             }
  1344.         }
  1345.  
  1346.         return pospay[highpos];
  1347.     }
  1348.  
  1349.     bool check_tenpai()
  1350.     {
  1351.         bool tp=is_tenpai(menzen,waits);
  1352.         if(!tp)
  1353.         {
  1354.             return false;
  1355.         }
  1356.         //check if wait isn't already 4times in hand
  1357.         for(unsigned int a=0; a!=waits.size(); a++)
  1358.         {
  1359.             int count=0;
  1360.             for(unsigned int b=0; b!=menzen.size(); b++)
  1361.             {
  1362.                 if(waits[a]==menzen[b])
  1363.                 {
  1364.                     count++;
  1365.                 }
  1366.             }
  1367.             for(unsigned int b=0; b!=open.size(); b++)
  1368.             {
  1369.                 for(unsigned int c=0; c!=open[b].size(); c++)
  1370.                 {
  1371.                     if(waits[a]==open[b][c])
  1372.                     {
  1373.                         count++;
  1374.                     }
  1375.                 }
  1376.             }
  1377.             if(count>=4)
  1378.             {
  1379.                 waits.erase(waits.begin()+a);
  1380.                 a--;
  1381.             }
  1382.         }
  1383.         return tp&&waits.size();
  1384.     }
  1385.  
  1386.     int check_furiten()
  1387.     {
  1388.         if(settings.furiten_mode==0)
  1389.         {
  1390.             return 0;
  1391.         }
  1392.         if(!check_tenpai())
  1393.         {
  1394.             return 0;
  1395.         }
  1396.         if(riichifuri&&settings.riichi_furiten&&(settings.furiten_mode==1||settings.furiten_mode==4))
  1397.         {
  1398.             std::cout << "RiichiFuriten!" << std::endl;
  1399.             return 2;
  1400.         }
  1401.         //0=no furiten, 1=furiten for turn, 2=completely furiten
  1402.         for(unsigned int a=0; a!=discards.size(); a++)
  1403.         {
  1404.             for(unsigned int b=0; b!=waits.size(); b++)
  1405.             {
  1406.                 if(discards[a]==waits[b]&&(settings.furiten_mode==1||settings.furiten_mode==4))
  1407.                 {
  1408.                     std::cout << "Furiten!" << std::endl;
  1409.                     return 2;
  1410.                 }
  1411.             }
  1412.         }
  1413.         for(unsigned int a=0; a!=furitile.size(); a++)
  1414.         {
  1415.             for(unsigned int b=0; b!=waits.size(); b++)
  1416.             {
  1417.                 if(furitile[a]==waits[b]&&(settings.furiten_mode==2||settings.furiten_mode==3||settings.furiten_mode==4))
  1418.                 {
  1419.                     std::cout << "Temporary Furiten!" << std::endl;
  1420.                     return 1;
  1421.                 }
  1422.             }
  1423.         }
  1424.         return 0;
  1425.     }
  1426.  
  1427.     bool check_win(const Tile& wtile, const int& rwind, const int& wturn, const int& tileno, const int& winmode)
  1428.     {
  1429.         if(winmode!=2&&winmode!=4&&check_furiten())
  1430.         {
  1431.             return false;
  1432.         }
  1433.         std::vector<Tile> temp = menzen;
  1434.         temp.push_back(wtile);
  1435.         std::sort(temp.begin(),temp.end());
  1436.         std::vector<handconfig> posconf = get_config(temp);
  1437.         for(unsigned int a=0; a!=posconf.size(); a++)
  1438.         {
  1439.             g3::big_int payment;
  1440.             g3::big_int fu=get_fu(posconf[a], rwind, winmode, wtile);
  1441.             int tmp_ym;
  1442.             if(get_han(rwind, wturn, tileno, wtile, winmode, posconf[a],fu,0,0,0,tmp_ym)&&is_winning_hand(temp))
  1443.             {
  1444.                 return true;
  1445.             };
  1446.         }
  1447.         return false;
  1448.     }
  1449.  
  1450.     int get_clickpos(sf::RenderWindow& GameWindow, int mode=0)
  1451.     {
  1452.         if(ai&&tsumopai!=deftile)
  1453.         {
  1454.             sf::Sleep(0.500);
  1455.             return -1;
  1456.         }
  1457.         else if(ai)
  1458.         {
  1459.             sf::Sleep(0.500);
  1460.             return 0;
  1461.         }
  1462.         int choice = NOTHING;
  1463.         bool clicked = false;
  1464.         int start = 0;
  1465.  
  1466.         while(choice == NOTHING&&!stopbutton)
  1467.         {
  1468.             choice = NOTHING;
  1469.             static bool pressed = false;
  1470.             if(pressed==false)
  1471.             {
  1472.                 if(GameWindow.GetInput().IsMouseButtonDown(sf::Mouse::Left))
  1473.                 {
  1474.                     pressed = true;
  1475.                 }
  1476.             }
  1477.             if(pressed==true)
  1478.             {
  1479.                 pressed = GameWindow.GetInput().IsMouseButtonDown(sf::Mouse::Left);
  1480.                 if(pressed == false)
  1481.                 {
  1482.                     choice = get_choice(GameWindow);
  1483.                     int clicktime = std::clock();
  1484.                     int time_past = clicktime - start;
  1485.                     if(clicked&&choice==NOTHING&&time_past<200)
  1486.                     {
  1487.                         if(mode==0)
  1488.                         {
  1489.                             choice = None;
  1490.                         }
  1491.                         else if(mode==2)
  1492.                         {
  1493.                             choice = NOTHING;
  1494.                         }
  1495.                         else
  1496.                         {
  1497.                             choice = tsumopai_tile;
  1498.                         }
  1499.                         clicked = false;
  1500.                     }
  1501.                     else if(choice==NOTHING)
  1502.                     {
  1503.                         clicked=true;
  1504.                         start=std::clock();
  1505.                     }
  1506.                     if(choice == tsumopai_tile && !tsumopai.highlight)
  1507.                     {
  1508.                         choice = NOTHING;
  1509.                     }
  1510.                     else if(choice>=hand0&&choice<Chi&&!menzen[choice].highlight)
  1511.                     {
  1512.                         choice = NOTHING;
  1513.                     }
  1514.                 }
  1515.             }
  1516.             if(stopbutton)
  1517.             {
  1518.                 std::cout << std::endl << "ABORTED CLICKPOS" << std::endl;
  1519.             }
  1520.         }
  1521.         none_bt=false;
  1522.         riichi_bt=false;
  1523.         oriichi_bt=false;
  1524.         tsumo_bt=false;
  1525.         ron_bt=false;
  1526.         chi_bt=false;
  1527.         pon_bt=false;
  1528.         kan_bt=false;
  1529.         reshuffle_bt=false;
  1530.         send_buttons();
  1531.  
  1532.         if(stopbutton)
  1533.         {
  1534.             stopbutton=false;
  1535.             choice = None;
  1536.         }
  1537.  
  1538.         return choice;
  1539.  
  1540.     }
  1541.  
  1542.     int get_button(player& p2, std::vector<int>& works, std::vector<std::vector<int> >& chiworks, const int& rwind, const int& wturn, const int& tileno, const Tile& kantile, sf::RenderWindow& GameWindow, int mode=0)
  1543.     {
  1544.         //0=none, 1=tsumo, 2=riichi, 3=chi, 4=pon, 5=closedkan, 6=latekan, 7=daimin, 8=ron
  1545.         if(ai)
  1546.         {
  1547.             return None;    //AI doesn't call
  1548.         }
  1549.  
  1550.         Tile calltile;
  1551.         if(p2.discards.size())
  1552.         {
  1553.             calltile=p2.discards[p2.discards.size()-1];
  1554.         }
  1555.  
  1556.         bool tsumo(false),riichi_tempbool(false),chi(false),pon(false),closedkan(false),latek(false),daimin(false),ron(false);
  1557.         std::vector<int> riichiwk, ponwk,kanwk;
  1558.         std::vector<std::vector<int> > chiwk;
  1559.  
  1560.         //tsumo (rinshan)
  1561.         if(tsumopai!=deftile&&kantile==tsumopai)
  1562.         {
  1563.             if(check_win(tsumopai, rwind, wturn, tileno, 3))
  1564.             {
  1565.                 tsumo=true;
  1566.             }
  1567.         }
  1568.         //tsumo (normal)
  1569.         else if(tsumopai!=deftile)
  1570.         {
  1571.             if(check_win(tsumopai, rwind, wturn, tileno, 1))
  1572.             {
  1573.                 tsumo=true;
  1574.             }
  1575.         }
  1576.  
  1577.         //riichi
  1578.         if(!riichi&&tsumopai!=deftile&&(!check_(open)||settings.minriichi)&&tileno>=18)
  1579.         {
  1580.             std::vector<Tile> triichi=menzen;
  1581.             triichi.push_back(tsumopai);
  1582.             for(unsigned int a=0; a!=triichi.size(); a++)
  1583.             {
  1584.                 std::vector<Tile> ttriichi=triichi;
  1585.                 ttriichi.erase(ttriichi.begin()+a);
  1586.                 std::sort(ttriichi.begin(),ttriichi.end());
  1587.                 if(is_tenpai(ttriichi))
  1588.                 {
  1589.                     if(a==triichi.size()-1)
  1590.                     {
  1591.                         riichi_tempbool=true;
  1592.                         riichiwk.push_back(-1);
  1593.                     }
  1594.                     else
  1595.                     {
  1596.                         riichi_tempbool=true;
  1597.                         riichiwk.push_back(a);
  1598.                     }
  1599.                 }
  1600.             }
  1601.         }
  1602.  
  1603.         //chi
  1604.         if(tsumopai==deftile&&relpos(p2)==3&&!riichi&&tileno>=18)
  1605.         {
  1606.             //get valid pairs
  1607.             for(unsigned int a=0; a!=menzen.size(); a++)
  1608.             {
  1609.                 for(unsigned int b=a; b!=menzen.size(); b++)
  1610.                 {
  1611.                     if(a==b||menzen[a].suit!=menzen[b].suit||menzen[a].suit!=calltile.suit||menzen[a].suit==j)
  1612.                     {
  1613.                         continue;
  1614.                     }
  1615.                     std::vector<int> tmp(2);
  1616.                     tmp[0]=a;
  1617.                     tmp[1]=b;
  1618.                     //ryanmen
  1619.                     if(menzen[b].value==menzen[a].value+1&&menzen[a].value!=1&&menzen[a].value!=8&&(calltile.value==menzen[a].value-1||calltile.value==menzen[b].value+1))
  1620.                     {
  1621.                         chiwk.push_back(tmp);
  1622.                     }
  1623.                     //penchan
  1624.                     else if(menzen[b].value==menzen[a].value+1&&menzen[a].value==1&&calltile.value==3)
  1625.                     {
  1626.                         chiwk.push_back(tmp);
  1627.                     }
  1628.                     else if(menzen[b].value==menzen[a].value+1&&menzen[a].value==8&&calltile.value==7)
  1629.                     {
  1630.                         chiwk.push_back(tmp);
  1631.                     }
  1632.                     //kanchan
  1633.                     else if(menzen[b].value==menzen[a].value+2&&calltile.value==menzen[a].value+1)
  1634.                     {
  1635.                         chiwk.push_back(tmp);
  1636.                     }
  1637.                 }
  1638.             }
  1639.             //sort vectors
  1640.             for(unsigned int a=0; a!=chiwk.size(); a++)
  1641.             {
  1642.                 std::sort(chiwk[a].begin(),chiwk[a].end());
  1643.             }
  1644.             //remove same position-pairs
  1645.             for(unsigned int a=0; a!=chiwk.size(); a++)
  1646.             {
  1647.                 for(unsigned int b=a; b!=chiwk.size(); b++)
  1648.                 {
  1649.                     if(a==b)
  1650.                     {
  1651.                         continue;
  1652.                     }
  1653.                     if(chiwk[a]==chiwk[b])
  1654.                     {
  1655.                         chiwk.erase(chiwk.begin()+b);
  1656.                         b--;
  1657.                     }
  1658.                 }
  1659.             }
  1660.             if(chiwk.size())
  1661.             {
  1662.                 chi=true;
  1663.             }
  1664.         }
  1665.  
  1666.         //pon
  1667.         if(tsumopai==deftile&&!riichi&&tileno>=18)
  1668.         {
  1669.             int poncnt=0;
  1670.             for(unsigned int a=0; a!=menzen.size(); a++)
  1671.             {
  1672.                 if(menzen[a]==calltile)
  1673.                 {
  1674.                     poncnt++;
  1675.                     if(ponwk.size()<2)
  1676.                     {
  1677.                         ponwk.push_back(a);
  1678.                     }
  1679.                 }
  1680.             }
  1681.             if(poncnt>=2)
  1682.             {
  1683.                 pon=true;
  1684.             }
  1685.         }
  1686.  
  1687.         //kan (daimin)
  1688.         if(tsumopai==deftile&&!riichi&&tileno>=18)
  1689.         {
  1690.             int kancnt=0;
  1691.             for(unsigned int a=0; a!=menzen.size(); a++)
  1692.             {
  1693.                 if(menzen[a]==calltile)
  1694.                 {
  1695.                     kancnt++;
  1696.                     kanwk.push_back(a);
  1697.                 }
  1698.             }
  1699.             if(kancnt>=3)
  1700.             {
  1701.                 daimin=true;
  1702.             }
  1703.         }
  1704.  
  1705.         //kan (chakan)
  1706.  
  1707.         if(tsumopai!=deftile&&!riichi&&tileno>=18)
  1708.         {
  1709.             for(unsigned int a=0; a!=menzen.size(); a++)
  1710.             {
  1711.                 for(unsigned int b=0; b!=open.size(); b++)
  1712.                 {
  1713.                     if(std::count(open[b].begin(),open[b].end(),menzen[a])==3)
  1714.                     {
  1715.                         kanwk.push_back(a);
  1716.                         latek=true;
  1717.                     }
  1718.                 }
  1719.             }
  1720.             for(unsigned int a=0; a!=open.size(); a++)
  1721.             {
  1722.                 if(std::count(open[a].begin(),open[a].end(),tsumopai)==3)
  1723.                 {
  1724.                     kanwk.push_back(-1);
  1725.                     latek=true;
  1726.                 }
  1727.             }
  1728.         }
  1729.  
  1730.         //kan (closed)
  1731.         if(tsumopai!=deftile&&tileno>=18)
  1732.         {
  1733.             bool tpai=false;
  1734.             for(unsigned int a=0; a!=menzen.size(); a++)
  1735.             {
  1736.                 int tilecnt=0;
  1737.                 for(unsigned int b=0; b!=menzen.size(); b++)
  1738.                 {
  1739.                     if(menzen[a]==menzen[b])
  1740.                     {
  1741.                         tilecnt++;
  1742.                     }
  1743.                 }
  1744.                 bool tp=false;
  1745.                 if(tsumopai==menzen[a])
  1746.                 {
  1747.                     tilecnt++;
  1748.                     tp=true;
  1749.                 }
  1750.                 if(tilecnt==4)
  1751.                 {
  1752.                     tpai=tp;
  1753.                     kanwk.push_back(a);
  1754.                     closedkan=true;
  1755.                 }
  1756.             }
  1757.             if(tpai)
  1758.             {
  1759.                 kanwk.push_back(-1);
  1760.             }
  1761.  
  1762.             //if riichi, check if config won't be changed
  1763.             if(riichi&&closedkan)
  1764.             {
  1765.                 for(unsigned int a=0; a!=kanwk.size(); a++)
  1766.                 {
  1767.                     if(kanwk[a]!=-1&&menzen[kanwk[a]]!=tsumopai)
  1768.                     {
  1769.                         kanwk.erase(kanwk.begin()+a);
  1770.                         a--;
  1771.                     }
  1772.                 }
  1773.                 if(!kanwk.size())
  1774.                 {
  1775.                     closedkan=false;
  1776.                 }
  1777.                 else
  1778.                 {
  1779.                     handconfig pos_hands;
  1780.                     for(unsigned int a=0; a!=waits.size(); a++)
  1781.                     {
  1782.                         std::vector<Tile> tmphand=menzen;
  1783.                         tmphand.push_back(waits[a]);
  1784.                         std::sort(tmphand.begin(),tmphand.end());
  1785.                         pos_hands.push_back(tmphand);
  1786.                     }
  1787.  
  1788.                     std::vector<handconfig> pos_configs;
  1789.                     for(unsigned int a=0; a!=pos_hands.size(); a++)
  1790.                     {
  1791.                         std::vector<handconfig> tmpconfs = get_config(pos_hands[a]);
  1792.                         for(unsigned int b=0; b!=tmpconfs.size(); b++)
  1793.                         {
  1794.                             pos_configs.push_back(tmpconfs[b]);
  1795.                         }
  1796.                     }
  1797.  
  1798.                     for(unsigned int a=0; a!=pos_configs.size(); a++)
  1799.                     {
  1800.                         for(unsigned int b=0; b!=pos_configs[a].size(); b++)
  1801.                         {
  1802.                             for(unsigned int c=0; c!=pos_configs[a][b].size(); c++)
  1803.                             {
  1804.                                 if(pos_configs[a][b][c]==tsumopai)
  1805.                                 {
  1806.                                     if(m_type(pos_configs[a][b])!=2)
  1807.                                     {
  1808.                                         closedkan=false;
  1809.                                     }
  1810.                                     break;
  1811.                                 }
  1812.                             }
  1813.                         }
  1814.                     }
  1815.                 }
  1816.             }
  1817.         }
  1818.  
  1819.         //ron (chakan)
  1820.         if(tsumopai==deftile&&calltile==kantile&&kantile!=deftile)
  1821.         {
  1822.             if(check_win(calltile, rwind, wturn, tileno, 4))
  1823.             {
  1824.                 ron=true;
  1825.                 if(riichi)
  1826.                 {
  1827.                     riichifuri=true;
  1828.                 }
  1829.             }
  1830.         }
  1831.  
  1832.         //ron (normal)
  1833.         else if(tsumopai==deftile)
  1834.         {
  1835.             if(check_win(calltile, rwind, wturn, tileno, 0))
  1836.             {
  1837.                 ron=true;
  1838.             }
  1839.         }
  1840.  
  1841.         works=std::vector<int>();
  1842.         int a=0;
  1843.  
  1844.         if(!tsumo&&!riichi_tempbool&&!chi&&!pon&&!closedkan&&!daimin&&!latek&&!ron)
  1845.         {
  1846.             return None;
  1847.         }
  1848.         //0=none, 1=tsumo, 2=riichi, 3=chi, 4=pon, 5=kan, 6=ron
  1849.         if(tsumopai==deftile)
  1850.         {
  1851.             none_bt = true;
  1852.         }
  1853.         else
  1854.         {
  1855.             none_bt = false;
  1856.         }
  1857.         if(tsumo)
  1858.         {
  1859.             tsumo_bt=true;
  1860.         }
  1861.         else
  1862.         {
  1863.             tsumo_bt = false;
  1864.         }
  1865.         if(riichi_tempbool)
  1866.         {
  1867.             riichi_bt=true;
  1868.         }
  1869.         else
  1870.         {
  1871.             riichi_bt=false;
  1872.         }
  1873.         if(chi)
  1874.         {
  1875.             chi_bt=true;
  1876.         }
  1877.         else
  1878.         {
  1879.             chi_bt=false;
  1880.         }
  1881.         if(pon)
  1882.         {
  1883.             pon_bt=true;
  1884.         }
  1885.         else
  1886.         {
  1887.             pon_bt=false;
  1888.         }
  1889.         if(closedkan||latek||daimin)
  1890.         {
  1891.             kan_bt=true;
  1892.         }
  1893.         else
  1894.         {
  1895.             kan_bt=false;
  1896.         }
  1897.         if(ron)
  1898.         {
  1899.             ron_bt=true;
  1900.         }
  1901.         else
  1902.         {
  1903.             ron_bt = false;
  1904.         }
  1905.         send_buttons();
  1906.         if(tsumopai==deftile)
  1907.         {
  1908.             darken_hand();
  1909.             if(mode==0)
  1910.             {
  1911.                 send_player_update(Client,ip);
  1912.                 network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  1913.             }
  1914.  
  1915.         }
  1916.  
  1917.         if(mode==0)
  1918.         {
  1919.             a = receive_clickpos();
  1920.         }
  1921.         else
  1922.         {
  1923.             a = get_clickpos(GameWindow);
  1924.         }
  1925.         if(stopbutton)
  1926.         {
  1927.             return None;
  1928.         }
  1929.  
  1930.         if(tsumopai==deftile)
  1931.         {
  1932.             undarken_hand();
  1933.             if(mode==0)
  1934.             {
  1935.                send_player_update(Client,ip);
  1936.             }
  1937.  
  1938.         }
  1939.         switch(a)
  1940.         {
  1941.         case Tsumo:
  1942.             if(tsumo)
  1943.             {
  1944.  
  1945.                 return Tsumo;
  1946.             }
  1947.             else
  1948.             {
  1949.                 return None;
  1950.             }
  1951.         case Riichi:
  1952.             if(riichi_tempbool)
  1953.             {
  1954.  
  1955.                 works=riichiwk;
  1956.                 return Riichi;
  1957.             }
  1958.             else
  1959.             {
  1960.                 return None;
  1961.             }
  1962.         case Chi:
  1963.             if(chi)
  1964.             {
  1965.  
  1966.                 chiworks=chiwk;
  1967.                 return Chi;
  1968.             }
  1969.             else
  1970.             {
  1971.                 return None;
  1972.             }
  1973.         case Pon:
  1974.             if(pon)
  1975.             {
  1976.  
  1977.                 works=ponwk;
  1978.                 return Pon;
  1979.             }
  1980.             else
  1981.             {
  1982.                 return None;
  1983.             }
  1984.         case Kan:
  1985.             if(closedkan||latek||daimin)
  1986.             {
  1987.  
  1988.                 works=kanwk;
  1989.                 return Kan;
  1990.             }
  1991.             else
  1992.             {
  1993.                 return None;
  1994.             }
  1995.         case Ron:
  1996.             if(ron)
  1997.             {
  1998.  
  1999.                 return Ron;
  2000.             }
  2001.             else
  2002.             {
  2003.                 return None;
  2004.             }
  2005.         case None:
  2006.             if(tsumopai==deftile)
  2007.             {
  2008.                 return None;
  2009.             }
  2010.             else
  2011.             {
  2012.                 return 999;
  2013.             }
  2014.         default:
  2015.             return a+1000;
  2016.         }
  2017.  
  2018.     }
  2019.  
  2020.     int get_maxpri(player& p2, const int& rwind, const int& wturn, const int& tileno, const Tile& kantile)
  2021.     {
  2022.         //0=none, 1=chi, 2=pon/kan, 3=ron
  2023.         if(ai)
  2024.         {
  2025.             return 0;    //AI doesn't call
  2026.         }
  2027.  
  2028.         Tile calltile;
  2029.         if(p2.discards.size())
  2030.         {
  2031.             calltile=p2.discards[p2.discards.size()-1];
  2032.         }
  2033.  
  2034.         bool chi(false),pon(false),closedkan(false),latek(false),daimin(false),ron(false);
  2035.         std::vector<int> riichiwk, ponwk,kanwk;
  2036.         std::vector<std::vector<int> > chiwk;
  2037.  
  2038.  
  2039.         //chi
  2040.         if(tsumopai==deftile&&relpos(p2)==3&&!riichi)
  2041.         {
  2042.             //get valid pairs
  2043.             for(unsigned int a=0; a!=menzen.size(); a++)
  2044.             {
  2045.                 for(unsigned int b=a; b!=menzen.size(); b++)
  2046.                 {
  2047.                     if(a==b||menzen[a].suit!=menzen[b].suit||menzen[a].suit!=calltile.suit||menzen[a].suit==j)
  2048.                     {
  2049.                         continue;
  2050.                     }
  2051.                     std::vector<int> tmp(2);
  2052.                     tmp[0]=a;
  2053.                     tmp[1]=b;
  2054.                     //ryanmen
  2055.                     if(menzen[b].value==menzen[a].value+1&&menzen[a].value!=1&&menzen[a].value!=8&&(calltile.value==menzen[a].value-1||calltile.value==menzen[b].value+1))
  2056.                     {
  2057.                         chiwk.push_back(tmp);
  2058.                     }
  2059.                     //penchan
  2060.                     else if(menzen[b].value==menzen[a].value+1&&menzen[a].value==1&&calltile.value==3)
  2061.                     {
  2062.                         chiwk.push_back(tmp);
  2063.                     }
  2064.                     else if(menzen[b].value==menzen[a].value+1&&menzen[a].value==8&&calltile.value==7)
  2065.                     {
  2066.                         chiwk.push_back(tmp);
  2067.                     }
  2068.                     //kanchan
  2069.                     else if(menzen[b].value==menzen[a].value+2&&calltile.value==menzen[a].value+1)
  2070.                     {
  2071.                         chiwk.push_back(tmp);
  2072.                     }
  2073.                 }
  2074.             }
  2075.             //sort vectors
  2076.             for(unsigned int a=0; a!=chiwk.size(); a++)
  2077.             {
  2078.                 std::sort(chiwk[a].begin(),chiwk[a].end());
  2079.             }
  2080.             //remove same position-pairs
  2081.             for(unsigned int a=0; a!=chiwk.size(); a++)
  2082.             {
  2083.                 for(unsigned int b=a; b!=chiwk.size(); b++)
  2084.                 {
  2085.                     if(a==b)
  2086.                     {
  2087.                         continue;
  2088.                     }
  2089.                     if(chiwk[a]==chiwk[b])
  2090.                     {
  2091.                         chiwk.erase(chiwk.begin()+b);
  2092.                         b--;
  2093.                     }
  2094.                 }
  2095.             }
  2096.             if(chiwk.size())
  2097.             {
  2098.                 chi=true;
  2099.             }
  2100.         }
  2101.  
  2102.         //pon
  2103.         if(tsumopai==deftile&&!riichi)
  2104.         {
  2105.             int poncnt=0;
  2106.             for(unsigned int a=0; a!=menzen.size(); a++)
  2107.             {
  2108.                 if(menzen[a]==calltile)
  2109.                 {
  2110.                     poncnt++;
  2111.                     if(ponwk.size()<2)
  2112.                     {
  2113.                         ponwk.push_back(a);
  2114.                     }
  2115.                 }
  2116.             }
  2117.             if(poncnt>=2)
  2118.             {
  2119.                 pon=true;
  2120.             }
  2121.         }
  2122.  
  2123.         //kan (daimin)
  2124.         if(tsumopai==deftile&&!riichi)
  2125.         {
  2126.             int kancnt=0;
  2127.             for(unsigned int a=0; a!=menzen.size(); a++)
  2128.             {
  2129.                 if(menzen[a]==calltile)
  2130.                 {
  2131.                     kancnt++;
  2132.                     kanwk.push_back(a);
  2133.                 }
  2134.             }
  2135.             if(kancnt>=3)
  2136.             {
  2137.                 daimin=true;
  2138.             }
  2139.         }
  2140.  
  2141.         //kan (chakan)
  2142.  
  2143.         if(tsumopai!=deftile&&!riichi)
  2144.         {
  2145.             for(unsigned int a=0; a!=menzen.size(); a++)
  2146.             {
  2147.                 for(unsigned int b=0; b!=open.size(); b++)
  2148.                 {
  2149.                     if(std::count(open[b].begin(),open[b].end(),menzen[a])==3)
  2150.                     {
  2151.                         kanwk.push_back(a);
  2152.                         latek=true;
  2153.                     }
  2154.                 }
  2155.             }
  2156.             for(unsigned int a=0; a!=open.size(); a++)
  2157.             {
  2158.                 if(std::count(open[a].begin(),open[a].end(),tsumopai)==3)
  2159.                 {
  2160.                     kanwk.push_back(-1);
  2161.                     latek=true;
  2162.                 }
  2163.             }
  2164.         }
  2165.  
  2166.         //kan (closed)
  2167.         if(tsumopai!=deftile)
  2168.         {
  2169.             bool tpai=false;
  2170.             for(unsigned int a=0; a!=menzen.size(); a++)
  2171.             {
  2172.                 int tilecnt=0;
  2173.                 for(unsigned int b=0; b!=menzen.size(); b++)
  2174.                 {
  2175.                     if(menzen[a]==menzen[b])
  2176.                     {
  2177.                         tilecnt++;
  2178.                     }
  2179.                 }
  2180.                 bool tp=false;
  2181.                 if(tsumopai==menzen[a])
  2182.                 {
  2183.                     tilecnt++;
  2184.                     tp=true;
  2185.                 }
  2186.                 if(tilecnt==4)
  2187.                 {
  2188.                     tpai=tp;
  2189.                     kanwk.push_back(a);
  2190.                     closedkan=true;
  2191.                 }
  2192.             }
  2193.             if(tpai)
  2194.             {
  2195.                 kanwk.push_back(-1);
  2196.             }
  2197.  
  2198.             //if riichi, check if config won't be changed
  2199.             if(riichi&&closedkan)
  2200.             {
  2201.                 for(unsigned int a=0; a!=kanwk.size(); a++)
  2202.                 {
  2203.                     if(kanwk[a]!=-1&&menzen[kanwk[a]]!=tsumopai)
  2204.                     {
  2205.                         kanwk.erase(kanwk.begin()+a);
  2206.                         a--;
  2207.                     }
  2208.                 }
  2209.                 if(!kanwk.size())
  2210.                 {
  2211.                     closedkan=false;
  2212.                 }
  2213.                 else
  2214.                 {
  2215.                     handconfig pos_hands;
  2216.                     for(unsigned int a=0; a!=waits.size(); a++)
  2217.                     {
  2218.                         std::vector<Tile> tmphand=menzen;
  2219.                         tmphand.push_back(waits[a]);
  2220.                         std::sort(tmphand.begin(),tmphand.end());
  2221.                         pos_hands.push_back(tmphand);
  2222.                     }
  2223.  
  2224.                     std::vector<handconfig> pos_configs;
  2225.                     for(unsigned int a=0; a!=pos_hands.size(); a++)
  2226.                     {
  2227.                         std::vector<handconfig> tmpconfs = get_config(pos_hands[a]);
  2228.                         for(unsigned int b=0; b!=tmpconfs.size(); b++)
  2229.                         {
  2230.                             pos_configs.push_back(tmpconfs[b]);
  2231.                         }
  2232.                     }
  2233.  
  2234.                     for(unsigned int a=0; a!=pos_configs.size(); a++)
  2235.                     {
  2236.                         for(unsigned int b=0; b!=pos_configs[a].size(); b++)
  2237.                         {
  2238.                             for(unsigned int c=0; c!=pos_configs[a][b].size(); c++)
  2239.                             {
  2240.                                 if(pos_configs[a][b][c]==tsumopai)
  2241.                                 {
  2242.                                     if(m_type(pos_configs[a][b])!=2)
  2243.                                     {
  2244.                                         closedkan=false;
  2245.                                     }
  2246.                                     break;
  2247.                                 }
  2248.                             }
  2249.                         }
  2250.                     }
  2251.                 }
  2252.             }
  2253.         }
  2254.  
  2255.         //ron (chakan)
  2256.         if(tsumopai==deftile&&calltile==kantile&&kantile!=deftile)
  2257.         {
  2258.             if(check_win(calltile, rwind, wturn, tileno, 4))
  2259.             {
  2260.                 ron=true;
  2261.                 if(riichi)
  2262.                 {
  2263.                     riichifuri=true;
  2264.                 }
  2265.             }
  2266.         }
  2267.  
  2268.         //ron (normal)
  2269.         else if(tsumopai==deftile)
  2270.         {
  2271.             if(check_win(calltile, rwind, wturn, tileno, 0))
  2272.             {
  2273.                 ron=true;
  2274.             }
  2275.         }
  2276.  
  2277.  
  2278.         if(!chi&&!pon&&!closedkan&&!daimin&&!latek&&!ron)
  2279.         {
  2280.             return 0;
  2281.         }
  2282.         //0=none, 1=chi, 2=pon/kan, 3=ron
  2283.  
  2284.         if(ron)
  2285.         {
  2286.             return 3;
  2287.         }
  2288.         if(pon||closedkan||daimin||latek)
  2289.         {
  2290.             return 2;
  2291.         }
  2292.         if(chi)
  2293.         {
  2294.             return 1;
  2295.         }
  2296.         return 0;
  2297.  
  2298.     }
  2299.  
  2300.  
  2301.     int call(player& p2, const int& rwind, const int& wturn, const int& tileno, const Tile& kantile, sf::RenderWindow& GameWindow,int button,std::vector<int>& works,std::vector<std::vector<int> >& chiworks)
  2302.     {
  2303.         if(ai) //ai doesn't call
  2304.         {
  2305.             return 0;
  2306.         }
  2307.  
  2308.  
  2309.         //0=none, 1=chi, 2=closedkan, 3=tsumo, 4=ron, 5=chakan/daimin,6=riichi, 7=pon
  2310.  
  2311.         //Tile
  2312.         if(button>100)
  2313.         {
  2314.             return button;
  2315.         }
  2316.         //none
  2317.         else if(button==None)
  2318.         {
  2319.             return 0;
  2320.         }
  2321.         //tsumo
  2322.         else if(button==Tsumo)
  2323.         {
  2324.  
  2325.             if(kantile!=deftile)
  2326.             {
  2327.                 won=4;
  2328.             }
  2329.             else
  2330.             {
  2331.                 won=2;
  2332.             }
  2333.             win_pai=tsumopai;
  2334.             return 3;
  2335.         }
  2336.         //riichi
  2337.         else if(button==Riichi)
  2338.         {
  2339.             darken_hand(works);
  2340.             send_player_update(Client,ip);
  2341.             network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2342.             rdiscard(receive_clickpos(1));
  2343.             undarken_hand();
  2344.             send_player_update(Client,ip);
  2345.             network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2346.             riichi=wturn;
  2347.             pts-=1000;
  2348.             return 6;
  2349.         }
  2350.         //chi
  2351.         else if(button==Chi)
  2352.         {
  2353.             //remove exactly same tiles
  2354.             for(unsigned int a=0; a!=chiworks.size(); a++)
  2355.             {
  2356.                 for(unsigned int b=a; b!=chiworks.size(); b++)
  2357.                 {
  2358.                     if(a==b)
  2359.                     {
  2360.                         continue;
  2361.                     }
  2362.                     if(sametile(menzen[chiworks[a][0]],menzen[chiworks[b][0]])&&sametile(menzen[chiworks[a][1]],menzen[chiworks[b][1]]))
  2363.                     {
  2364.                         chiworks.erase(chiworks.begin()+b);
  2365.                         break;
  2366.                     }
  2367.                 }
  2368.             }
  2369.  
  2370.             //only one possibility
  2371.             if(chiworks.size()==1)
  2372.             {
  2373.                 ponchi(p2,chiworks[0][0],chiworks[0][1]);
  2374.                 return 1;
  2375.             }
  2376.             //several possibilities
  2377.             //get possibilites after first click
  2378.             darken_hand(chiworks);
  2379.             send_player_update(Client,ip);
  2380.             network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2381.             int clickpos=receive_clickpos();
  2382.             undarken_hand();
  2383.             send_player_update(Client,ip);
  2384.             network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2385.             std::vector<std::vector<int> > tint;
  2386.             for(unsigned int a=0; a!=chiworks.size(); a++)
  2387.             {
  2388.                 for(unsigned int b=0; b!=chiworks[a].size(); b++)
  2389.                 {
  2390.                     if(chiworks[a][b]==clickpos)
  2391.                     {
  2392.                         tint.push_back(chiworks[a]);
  2393.                         break;
  2394.                     }
  2395.                 }
  2396.             }
  2397.             //distinct possibility
  2398.             if(tint.size()==1)
  2399.             {
  2400.                 ponchi(p2,tint[0][0],tint[0][1]);
  2401.                 return 1;
  2402.             }
  2403.             //non-distinct, get next click
  2404.             //remove obsolete entries from chiworks
  2405.             for(unsigned int a=0; a!=chiworks.size(); a++)
  2406.             {
  2407.                 bool remain=false;
  2408.                 for(unsigned int b=0; b!=chiworks[a].size(); b++)
  2409.                 {
  2410.                     //check if first click exists within possible group
  2411.                     if(chiworks[a][b]==clickpos)
  2412.                     {
  2413.                         remain=true;
  2414.                         break;
  2415.                     }
  2416.                 }
  2417.                 //remove all groups that didn't contain the first click
  2418.                 if(!remain)
  2419.                 {
  2420.                     chiworks.erase(chiworks.begin()+a);
  2421.                     a--;
  2422.                 }
  2423.             }
  2424.             //create temporary vector chiworks2 that doesn't contain the first click
  2425.             std::vector<std::vector<int> > chiworks2 = chiworks;
  2426.             for(unsigned int a=0; a!=chiworks2.size(); a++)
  2427.             {
  2428.                 for(unsigned int b=0; b!=chiworks2[a].size(); b++)
  2429.                 {
  2430.                     if(chiworks2[a][b]==clickpos)
  2431.                     {
  2432.                         chiworks2[a].erase(chiworks2[a].begin()+b);
  2433.                         break;
  2434.                     }
  2435.                 }
  2436.             }
  2437.             //get second click from temporary vector
  2438.             darken_hand(chiworks2);
  2439.             send_player_update(Client,ip);
  2440.             network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2441.             int click2=receive_clickpos();
  2442.             undarken_hand();
  2443.             send_player_update(Client,ip);
  2444.             network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2445.             //check which group contains second click too (using original vector) and ponchi with it
  2446.             for(unsigned int a=0; a!=chiworks.size(); a++)
  2447.             {
  2448.                 for(unsigned int b=0; b!=chiworks[a].size(); b++)
  2449.                 {
  2450.                     if(chiworks[a][b]==click2)
  2451.                     {
  2452.                         ponchi(p2,chiworks[a][0],chiworks[a][1]);
  2453.                         send_player_update(Client,ip);
  2454.                         network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2455.                         return 1;
  2456.                     }
  2457.                 }
  2458.             }
  2459.         }
  2460.         //pon
  2461.         else if(button==Pon)
  2462.         {
  2463.             //only one possibility
  2464.             if(works.size()==2)
  2465.             {
  2466.                 ponchi(p2,works[0],works[1]);
  2467.                 send_player_update(Client,ip);
  2468.                 network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2469.                 return 7;
  2470.             }
  2471.             //several possibilities
  2472.             //check if exactly the same
  2473.             if(works.size()==3&&sametile(works[0],works[1])&&sametile(works[1],works[2]))
  2474.             {
  2475.                 ponchi(p2,works[0],works[1]);
  2476.                 send_player_update(Client,ip);
  2477.                 network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2478.                 return 7;
  2479.             }
  2480.             //not exactly the same
  2481.             //get first click
  2482.             darken_hand(works);
  2483.             send_player_update(Client,ip);
  2484.             network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2485.             int clickpos=receive_clickpos();
  2486.             undarken_hand();
  2487.             send_player_update(Client,ip);
  2488.             network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2489.             std::vector<int> t_works=works;
  2490.             for(unsigned int a=0; a!=t_works.size(); a++)
  2491.             {
  2492.                 if(t_works[a]==clickpos)
  2493.                 {
  2494.                     t_works.erase(t_works.begin()+a);
  2495.                     break;
  2496.                 }
  2497.             }
  2498.             std::sort(t_works.begin(),t_works.end());
  2499.             //possibilities after first click
  2500.             //other 2 exactly the same
  2501.             if(t_works.size()==2&&sametile(works[0],works[1]))
  2502.             {
  2503.                 std::vector<int> t_tworks;
  2504.                 t_tworks.push_back(works[0]);
  2505.                 t_tworks.push_back(clickpos);
  2506.                 std::sort(t_tworks.begin(),t_tworks.end());
  2507.                 ponchi(p2,t_tworks[0],t_tworks[1]);
  2508.                 send_player_update(Client,ip);
  2509.                 network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2510.                 return 7;
  2511.             }
  2512.             //not exactly the same tiles
  2513.             darken_hand(t_works);
  2514.            send_player_update(Client,ip);
  2515.            network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2516.             int clickpos2=receive_clickpos();
  2517.             undarken_hand();
  2518.             send_player_update(Client,ip);
  2519.             network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2520.             std::vector<int> temp_works;
  2521.             temp_works.push_back(clickpos);
  2522.             temp_works.push_back(clickpos2);
  2523.             std::sort(temp_works.begin(),temp_works.end());
  2524.             ponchi(p2,temp_works[0],temp_works[1]);
  2525.             send_player_update(Client,ip);
  2526.             network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2527.             return 7;
  2528.         }
  2529.  
  2530.         //ron
  2531.         else if(button==Ron)
  2532.         {
  2533.  
  2534.             if(kantile!=deftile)
  2535.             {
  2536.                 won=3;
  2537.             }
  2538.             else
  2539.             {
  2540.                 won=1;
  2541.             }
  2542.             win_pai=p2.discards[p2.discards.size()-1];
  2543.             won_from=p2.pid;
  2544.             return 4;
  2545.         }
  2546.  
  2547.         //kan
  2548.         else if(button==Kan)
  2549.         {
  2550.  
  2551.             //daimin-kan
  2552.             if(tsumopai==deftile)
  2553.             {
  2554.                 daiminkan(p2,works[0],works[1],works[2]);
  2555.                 send_player_update(Client,ip);
  2556.                 network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2557.                 return 5;
  2558.             }
  2559.             //check number of different tile in works
  2560.             std::vector<Tile> counted;
  2561.             int count=0;
  2562.             for(unsigned int a=0; a!=works.size(); a++)
  2563.             {
  2564.                 bool cont=false;
  2565.                 for(unsigned int b=0; b!=counted.size(); b++)
  2566.                 {
  2567.                     if(works[a]==-1&&tsumopai==counted[b])
  2568.                     {
  2569.                         cont=true;
  2570.                         break;
  2571.                     }
  2572.                     if(menzen[works[a]]==counted[b])
  2573.                     {
  2574.                         cont=true;
  2575.                         break;
  2576.                     }
  2577.                 }
  2578.                 if(cont)
  2579.                 {
  2580.                     continue;
  2581.                 }
  2582.                 count++;
  2583.                 if(works[a]==-1)
  2584.                 {
  2585.                     counted.push_back(tsumopai);
  2586.                 }
  2587.                 else
  2588.                 {
  2589.                     counted.push_back(menzen[works[a]]);
  2590.                 }
  2591.             }
  2592.  
  2593.             //only one possibility
  2594.             if(count==1)
  2595.             {
  2596.                 //kan (chakan)
  2597.                 for(unsigned int a=0; a!=open.size(); a++)
  2598.                 {
  2599.                     if(works[0]==-1)
  2600.                     {
  2601.                         if(std::count(open[a].begin(),open[a].end(),tsumopai)==3)
  2602.                         {
  2603.                             latekan(works[0]);
  2604.                             send_player_update(Client,ip);
  2605.                             network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2606.                             return 5;
  2607.                         }
  2608.                     }
  2609.                     else
  2610.                     {
  2611.                         if(std::count(open[a].begin(),open[a].end(),menzen[works[0]])==3)
  2612.                         {
  2613.                             latekan(works[0]);
  2614.                             send_player_update(Client,ip);
  2615.                             network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2616.                             return 5;
  2617.                         }
  2618.                     }
  2619.  
  2620.                 }
  2621.                 //kan (closed)
  2622.                 if(works.size()==4)
  2623.                 {
  2624.                     kan(works[0],works[1],works[2],works[3]);
  2625.                     send_player_update(Client,ip);
  2626.                     network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2627.                     return 2;
  2628.                 }
  2629.             }
  2630.  
  2631.             //several possibilites, get clickpos
  2632.             darken_hand(works);
  2633.             send_player_update(Client,ip);
  2634.             network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2635.             int clickpos=receive_clickpos();
  2636.             undarken_hand();
  2637.             send_player_update(Client,ip);
  2638.             network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2639.  
  2640.             //chakan
  2641.             for(unsigned int a=0; a!=open.size(); a++)
  2642.             {
  2643.                 if(clickpos==-1)
  2644.                 {
  2645.                     if(std::count(open[a].begin(),open[a].end(),tsumopai)==3)
  2646.                     {
  2647.                         latekan(clickpos);
  2648.                         send_player_update(Client,ip);
  2649.                         network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2650.                         return 5;
  2651.                     }
  2652.                 }
  2653.                 else
  2654.                 {
  2655.                     if(std::count(open[a].begin(),open[a].end(),menzen[clickpos])==3)
  2656.                     {
  2657.                         latekan(clickpos);
  2658.                         send_player_update(Client,ip);
  2659.                         network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2660.                         return 5;
  2661.                     }
  2662.                 }
  2663.  
  2664.             }
  2665.             //closed kan
  2666.             works.clear();
  2667.             if(clickpos==-1)
  2668.             {
  2669.                 works.push_back(-1);
  2670.                 for(unsigned int a=0; a!=menzen.size(); a++)
  2671.                 {
  2672.                     if(menzen[a]==tsumopai)
  2673.                     {
  2674.                         works.push_back(a);
  2675.                     }
  2676.                 }
  2677.             }
  2678.             else
  2679.             {
  2680.                 if(tsumopai==menzen[clickpos])
  2681.                 {
  2682.                     works.push_back(-1);
  2683.                 }
  2684.                 for(unsigned int a=0; a!=menzen.size(); a++)
  2685.                 {
  2686.                     if(menzen[a]==menzen[clickpos])
  2687.                     {
  2688.                         works.push_back(a);
  2689.                     }
  2690.                 }
  2691.             }
  2692.             if(works.size()==4)
  2693.             {
  2694.                 kan(works[0],works[1],works[2],works[3]);
  2695.                 send_player_update(Client,ip);
  2696.                 network_stream << std::endl << update_st()  << " SEND PLAYER FROM PLAYER.H" << std::endl;
  2697.                 return 2;
  2698.             }
  2699.         }
  2700.  
  2701.         return 0;
  2702.  
  2703.     }
  2704.  
  2705.  
  2706.     std::string handlog()
  2707.     {
  2708.         std::stringstream sstr;
  2709.  
  2710.         for(unsigned int a=0; a!=menzen.size(); a++)
  2711.         {
  2712.             sstr << menzen[a].tilelog();
  2713.         }
  2714.         if(tsumopai!=deftile)
  2715.         {
  2716.             sstr << " T: ";
  2717.             sstr << tsumopai.tilelog();
  2718.         }
  2719.         sstr << " || ";
  2720.         for(unsigned int a=0; a!=open.size(); a++)
  2721.         {
  2722.             for(unsigned int b=0; b!=open[a].size(); b++)
  2723.             {
  2724.                 sstr << open[a][b].tilelog();
  2725.             }
  2726.             if(a!=open.size()-1)
  2727.             {
  2728.                 sstr<<"|";
  2729.             }
  2730.         }
  2731.         sstr << " __||__ ";
  2732.         for(unsigned int a=0; a!=discards.size(); a++)
  2733.         {
  2734.             sstr << discards[a].tilelog();
  2735.         }
  2736.  
  2737.         return sstr.str();
  2738.     }
  2739.  
  2740.  
  2741.  
  2742.     bool operator==(const player &rhs) const
  2743.     {
  2744.         return wind==rhs.wind;
  2745.     }
  2746.     bool operator!=(const player &rhs) const
  2747.     {
  2748.         return wind!=rhs.wind;
  2749.     }
  2750.  
  2751.  
  2752. };
  2753.  
  2754.  
  2755. #endif // PLAYER_H_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement