1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933
| #include<bits/stdc++.h> #include<Winsock2.h> #include<windows.h> #pragma comment (lib,"ws2_32") #define port 0x3390 #define sz 6400 #define people 10 #define PEOPLE 2 #define setcolor(x) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),x) #define spacenum 60 #define tablepos 50 #define tablehigh 8 #define maxmoney 10000ll #define slt 750 #define PR {cout<<"+--+";for(int i=1;i<=num;i++){for(int j=1;j<=Nlen;j++) cout<<"-";cout<<"+";}} using namespace std; typedef long long ll; mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); namespace init{ #define kd(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000)?1:0) #define sl(n) Sleep(n) void gotoxy(int y,int x){x--,y--;COORD pos={(short)x,(short)y};HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleCursorPosition(hOut,pos);return;} void noedit(){HANDLE hStdin=GetStdHandle(STD_INPUT_HANDLE);DWORD mode;GetConsoleMode(hStdin,&mode);mode&=~ENABLE_QUICK_EDIT_MODE;mode&=~ENABLE_INSERT_MODE;mode&=~ENABLE_MOUSE_INPUT;SetConsoleMode(hStdin,mode);} void hide(){CONSOLE_CURSOR_INFO cur={1,0};SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cur);} void show(){CONSOLE_CURSOR_INFO cur={1,1};SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cur);} } using namespace init; struct Card{ int x,co; Card():x(0),co(0){} Card(int xx,int col):x(xx),co(col){} const bool operator <(const Card &a)const{ if(x==a.x) return co>a.co; return x<a.x; } const bool operator >(const Card &a)const{ if(x==a.x) return co>a.co; return x<a.x; } string tostring(){return to_string(co)+to_string(x);} }; struct Pile{ vector<Card>v; int pos; void init(){ v.clear(); for(int i=2;i<=14;i++) for(int j=1;j<=4;j++) v.emplace_back(i,j); shuffle(v.begin(),v.end(),rng); pos=0; } Pile(){init();} Card getcard(){return v[pos++];} }; namespace Checker{ set <Card> st; inline bool query(int x, int co) { if (x==1) x = 14; return st.find(Card(x, co)) != st.end(); } inline int get_cnt1(int x) { int res = 0; for (int i = 1; i <= 4; ++i) res += query(x, i); return res; } inline int get_cnt2(int co) { int res = 0; for (int i = 2; i <= 14; ++i) res += query(i, co); return res; } inline bool check9(vector <Card> vec, vector <Card> &res) { for (int j = 1; j <= 4; ++j) { bool flg = true; for (int i = 10; i <= 14; ++i) if (!query(i, j)) {flg = false;break;} if (flg) {for (int i = 10; i <= 14; ++i) res.emplace_back(Card(i, j));return true;} } return false; } inline bool check8(vector <Card> vec, vector <Card> &res) { for (int j = 1; j <= 4; ++j) for (int l = 9; l; --l) { bool flg = true; for (int i = l; i < l + 5; ++i) if (!query(i, j)) {flg = false;break;} if (flg) { for (int i = l; i < l + 5; ++i) { if (i == 1) res.emplace_back(Card(14, j)); else res.emplace_back(Card(i, j)); } return true; } } return false; } inline bool check7(vector <Card> vec, vector <Card> &res) { for (int i = 2; i <= 14; ++i) { if (get_cnt1(i) == 4) { for (int j = 1; j <= 4; ++j) res.emplace_back(Card(i, j)); sort(vec.begin(), vec.end(), [](Card x, Card y) {return x > y;}); for (auto card: vec) if (card.x != i) {res.emplace_back(card);break;} return true; } } return false; } inline bool check6(vector <Card> vec, vector <Card> &res) { int cnt2 = 0, cnt3 = 0; for (int i = 2; i <= 14; ++i) { int t = get_cnt1(i); if (t == 3) ++cnt3; else if (t == 2) ++cnt2; } if (cnt3 < 1 || cnt2 + cnt3 < 2) return false; for (int i = 14; i >= 2; --i) { int t = get_cnt1(i); if (t >= 3) { for (int j = 1; j <= 4; ++j) if (query(i, j)) res.emplace_back(Card(i, j)); break; } } for (int i = 14; i >= 2; --i) { if (i == res[0].x) continue; int t = get_cnt1(i); if (t >= 2) { for (int j = 1; j <= 4; ++j) if (query(i, j) && res.size() < 5) res.emplace_back(Card(i, j)); break; } } return true; } inline bool check5(vector <Card> vec, vector <Card> &res) { res.clear(); int tmp = 0; for (int i = 1; i <= 4; i++) if (get_cnt2(i) >= 5) {tmp = i;break;} if (!tmp) return 0; sort(vec.begin(), vec.end()); for (int i = 6; i >= 0; i--) if (vec[i].co == tmp && res.size() < 5) res.emplace_back(vec[i]); return 1; } inline bool check4(vector <Card> vec, vector <Card> &res) { res.clear(); sort(vec.begin(), vec.end()); stack <Card> st1; st1.push(vec[6]); for (int i = 5; i >= 0; i--) { if (vec[i].x == st1.top().x) continue; if (vec[i].x == st1.top().x - 1) { st1.push(vec[i]); if (st1.size() == 5) break; } else { while (!st1.empty()) st1.pop(); st1.push(vec[i]); } } if (st1.size() < 5 && st1.top().x == 2 && vec[6].x == 14) st1.push(vec[6]); if (st1.size() != 5) return 0; while (!st1.empty()) res.emplace_back(st1.top()),st1.pop(); return 1; } inline bool check3(vector <Card> vec, vector <Card> &res) { res.clear(),sort(vec.begin(), vec.end()); int tmp = 0; for (int i = 6; i > 1; i--) if (vec[i].x == vec[i - 1].x && vec[i].x == vec[i - 2].x) { res.emplace_back(vec[i]); res.emplace_back(vec[i - 1]); res.emplace_back(vec[i - 2]); tmp = vec[i].x; break; } if (!tmp) return 0; for (int i = 6; i >= 0; i--) if (vec[i].x != tmp) { res.emplace_back(vec[i]); if (res.size() == 5) break; } return 1; } inline bool check2(vector <Card> vec, vector <Card> &res) { res.clear(),sort(vec.begin(), vec.end()); int cnt = 0,tmp[2]; for (int i = 6; i > 0; i--) if (vec[i].x == vec[i - 1].x) { res.emplace_back(vec[i]); res.emplace_back(vec[i - 1]); tmp[cnt++] = vec[i].x; if (cnt == 2) break; } if (cnt != 2) return 0; for (int i = 6; i >= 0; i--) if (vec[i].x != tmp[0] && vec[i].x != tmp[1]) { res.emplace_back(vec[i]); if (res.size() == 5) break; } return 1; } inline bool check1(vector <Card> vec, vector <Card> &res) { res.clear(),sort(vec.begin(), vec.end()); bool flg = 0; int tmp = 0; for (int i = 0; i < 6; i++) if (vec[i].x == vec[i + 1].x) { res.emplace_back(vec[i + 1]); res.emplace_back(vec[i]); flg = 1,tmp = vec[i].x; break; } if (!flg) return 0; for (int i = 6; i >= 0; i--) if (vec[i].x != tmp) { res.emplace_back(vec[i]); if (res.size() == 5) return 1; } return 1; } inline void check0(vector <Card> vec, vector <Card> &res) { res.clear(),sort(vec.begin(), vec.end()); for (int i = 6; i >=2; i--) res.emplace_back(vec[i]); } inline pair <int, vector <Card> > Choice(vector <Card> vec) { st.clear(); for (auto card: vec) st.insert(card); vector <Card> res; if (check9(vec, res)) return make_pair(9, res); if (check8(vec, res)) return make_pair(8, res); if (check7(vec, res)) return make_pair(7, res); if (check6(vec, res)) return make_pair(6, res); if (check5(vec, res)) return make_pair(5, res); if (check4(vec, res)) return make_pair(4, res); if (check3(vec, res)) return make_pair(3, res); if (check2(vec, res)) return make_pair(2, res); if (check1(vec, res)) return make_pair(1, res); check0(vec, res); return make_pair(0, res); } inline int cmp(pair <int, vector <Card> > p, pair <int, vector <Card> > q) { if (p.first != q.first) { if (p.first < q.first) return -1; return 1; } vector <Card> a = p.second, b = q.second; for (int i = 0; i < 5; ++i) { if (a[i].x < b[i].x) return -1; if (a[i].x > b[i].x) return 1; } return 0; } } using namespace Checker; namespace Server{ bool Hi=0; const int N=1e5+10; queue<char*> sent; char a[N][105]; SOCKET server,lt[N],ltt[N]; int t_lt[N],t,online; bool p1,p2=1; DWORD WINAPI recvs(LPVOID param){ SOCKET sclient=lt[t]; p1=0; int reg,flag=0; char rc[10000]; memset(rc,0,sizeof(rc)); while(1){ memset(rc,0,sizeof(rc)); reg=recv(sclient,rc,sz,0); if(reg==-1) break; else if(!flag){ for(int i=0;i<strlen(rc);i++) a[sclient][i]=rc[i]; flag=1; return 0; } } return 0; } DWORD WINAPI whide(LPVOID param){ HWND hWnd=GetConsoleWindow(); while(1){ if(kd(VK_ESCAPE)) Hi^=1; if(Hi) ShowWindow(hWnd,SW_HIDE); else ShowWindow(hWnd,SW_SHOW); Sleep(100); } } string tostring(ll x){ if(x==0) return "0"; string tmp=""; while(x) tmp=char(x%10+'0')+tmp,x/=10; return tmp; } ll stringto(string s){ int v=0; for(int i=0;i<s.length();i++) v=v*10+s[i]-'0'; return v; } string tostr(char *a){ string tmp=""; for(int i=0;i<strlen(a);i++) tmp+=a[i]; return tmp; } void Sen(int id,string s){ cout<<"Sen: "<<id<<" "<<s<<'\n'; send(lt[id],s.c_str(),s.size(),0); } string Rec(int id){ string tmp="";char tmpp[10000];memset(tmpp,0,sizeof(tmpp)); recv(lt[id],tmpp,sz,0); for(int i=0;i<strlen(tmpp);i++) tmp+=tmpp[i]; cout<<"Rec: "<<id<<" "<<tmp<<"\n"; return tmp; } string pastuser(int t){ string tmp=""; for(int i=1;i<=t;i++) tmp+=tostr(a[lt[i]])+";"; return tmp; } int at[20],denum=0; ll ma=10; Pile p; void getbet(){ int cntt=0; for(int i=1;cntt<t;i=i%t+1){ if(denum==t-1) break; if(at[i]){cntt++;continue;} string tmp=Rec(i);Sleep(300); if(stringto(tmp)>ma){ ma=stringto(tmp); cntt=1; } else cntt++; for(int j=1;j<=t;j++) Sen(j,"getbet:"+tmp);Sleep(slt); if(tmp=="0"){ at[i]=1,denum++; for(int j=1;j<=t;j++) Sen(j,"getcard:"+p.v[i-1].tostring());Sleep(slt); for(int j=1;j<=t;j++) Sen(j,"getcard:"+p.v[i-1+t].tostring());Sleep(slt); } } } void givecard(int x){ for(int j=1;j<=x;j++){ string tmpp=p.getcard().tostring(); for(int i=1;i<=t;i++) Sen(i,"getcard:"+tmpp);Sleep(slt); } } void Game(){ memset(at,0,sizeof(at)); denum=0,ma=10; for(int i=1;i<=t;i++) Sen(i,"fsb:"); Sleep(slt); Pile pp;p=pp; int idd[20]; for(int i=1;i<=t;i++) idd[i]=i; shuffle(idd+1,idd+t+1,rng); for(int i=1;i<=t;i++) lt[i]=ltt[idd[i]]; for(int i=1;i<=t;i++){ for(int j=1;j<=t;j++) Sen(j,to_string(idd[i])); Sleep(slt); } for(int i=1;i<=t;i++) Sen(i,"start:"); Sleep(slt); for(int j=1;j<=2;j++){ for(int i=1;i<=t;i++) Sen(i,"getcard:"+p.getcard().tostring()); Sleep(slt); } getbet();givecard(3);getbet();givecard(1);getbet();givecard(1);getbet(); for(int i=1;i<=t;i++) Sen(i,"then:");Sleep(slt); for(int i=1;i<=t;i++) if(!at[i]){ for(int j=1;j<=t;j++) Sen(j,"open:"+p.v[i-1].tostring());Sleep(slt); for(int j=1;j<=t;j++) Sen(j,"open:"+p.v[i-1+t].tostring());Sleep(slt); } for(int i=1;i<=t;i++) lt[i]=ltt[i]; for(int i=1;i<=t;i++) Rec(i); for(int i=1;i<=t;i++) Sen(i,"then:");Sleep(slt); for(int i=1;i<=t;i++){ string deb=Rec(i); for(int j=1;j<=t;j++) Sen(j,"sb:"+to_string(i));Sleep(slt); } for(int i=1;i<=t;i++) Sen(i,"then:");Sleep(slt); } void find_socket(){ sockaddr_in client; int client_len=sizeof(client); CreateThread(NULL,0,whide,NULL,0,NULL); cout<<"Socket connection has been opened!\nPress Esc to hide/show your process."; while(1){ if(t>N-10){t=0;memset(lt,0,sizeof lt);} if(online>=people){ puts("Online people limit exceeded.\nPlease wait until any player quits.\n\n"); while(online>=people); } if(t==PEOPLE) break; lt[++t]=accept(server,(sockaddr FAR*)&client,&client_len); ltt[t]=lt[t]; p2=0; if(lt[t]==(SOCKET)(~0)){puts("Failed to connect!\n");t--;continue;} t_lt[lt[t]]=t; online++; CreateThread(NULL,0,recvs,NULL,0,NULL); Sleep(slt); Sen(t,"userlist:"+pastuser(t-1));Sleep(300); printf("from: %s, name: %s!\n",inet_ntoa(client.sin_addr),a[lt[t]]); for(int i=1;i<=t;i++) Sen(i,"newuser:"+tostr(a[lt[t]]));Sleep(slt); p1=p2=1; } Sleep(slt); for(int i=1;i<=t;i++) Sen(i,"start:"); while(1) Game(); while(1); } bool open_socket(){ WSADATA wsaData; if(WSAStartup(MAKEWORD(2,2),&wsaData)!=0) puts("Failed to create Winsock connection!"),exit(0); server=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); if(server==(SOCKET)(~0)){ puts("Failed to initialize socket!"); WSACleanup(); exit(0); } sockaddr_in bindser; bindser.sin_family=AF_INET; bindser.sin_port=htons(port); bindser.sin_addr.s_addr=htonl(INADDR_ANY); if(bind(server,(const struct sockaddr*)&bindser,sizeof(bindser))==(SOCKET)(~0)){ puts("Failed to bind because a server has been set up!"); WSACleanup(); closesocket(server); return 1; } if(listen(server,people)==(SOCKET)(~0)){ puts("Failed to listen!"); WSACleanup(); closesocket(server); exit(0); } return 0; } void main(bool&f){ f=open_socket(); if(!f)find_socket(); } } namespace User{ SOCKET server; string namm[20]; char a[1000],ipv4[1000]; string nam[1005]; int num,my,myy,high,from[25]; string number=" 23456789TJQKA"; string color[5]={" ","Spade","Heart","Club","Diamond"}; string suit[15]={"No Pair","One Pair","Two Pairs","Three-of-a-kind","Straight","Flush","Full House","Four-of-a-kind","Straight Flush","Royal Flush"}; int mul[15]={1,1,2,3,5,8,13,21,34,55}; void Sen(string s){send(server,s.c_str(),s.size(),0);} int Hi; DWORD WINAPI whide(LPVOID param){ HWND hWnd=GetConsoleWindow(); while(1){ if(kd(VK_CONTROL)&&kd(VK_SPACE)){ if(Hi) Hi=0; else Hi=1; } if(Hi) ShowWindow(hWnd,SW_HIDE); else ShowWindow(hWnd,SW_SHOW); Sleep(100); } } string Rec(){ string tmp="";char tmpp[10000];memset(tmpp,0,sizeof(tmpp)); recv(server,tmpp,sz,0); for(int i=0;i<strlen(tmpp);i++) tmp+=tmpp[i]; return tmp; } int stringto(string s){ ll ans=0; for(int i=0;s[i];i++) if('0'<=s[i]&&s[i]<='9') ans=ans*10+s[i]-'0'; return ans; } string rem(string s){ return s.substr(s.find(":")+1); } string getop(string s){ string t=""; for(int i=0;s[i]!=':';i++) t+=s[i]; return t; } Card stringtocard(string s){ return (Card){(s.size()==3? 10+s[2]-'0':s[1]-'0'),s[0]-48}; } void print(vector<Card>p){ int tmp=0; for(auto x:p){ gotoxy(num*3+2+tmp+(tmp>=2),1); cout<<"Card "<<++tmp<<": "<<number[x.x]<<" "<<color[x.co]<<"\n"; } } ll sum=0,mon[20],at[20],dinum=0,nowmon[20]; int nlen,Nlen; string _tostring(ll x,int len=0){ if(!len) len=Nlen; string s=""; int flag=(x<0);x=abs(x); if(x==0) s="0"; else while(x) s=char(x%10+'0')+s,x/=10; if(len==2){ while(s.length()!=len) s+=" "; return s; } if(flag) s="-"+s; else s="+"+s; while(s.length()!=len) s+=" "; return s; } vector<Card>p; bool ishide,isend; DWORD WINAPI Hide(LPVOID param){ int flag=0; while(!isend){ if(!kd(VK_F8)) flag=0; if(kd(VK_F8)&&!flag){ if(p.size()>=2){ ishide^=1; if(ishide==1){ gotoxy(num*3+2,1);cout<<" \n "; } else{ for(int i=0;i<2;i++){ Card x=p[i]; gotoxy(num*3+2+i,1); cout<<"Card "<<i+1<<": "<<number[x.x]<<" "<<color[x.co]<<"\n"; } } } flag=1; } } return 0; } int calcline(int rn){ rn=(rn-1)%20+1; return rn*2+5; } void raise_bet(int op,int rn){ ll ma=10,isra=0,cntt=0; ll flag=0,fir=0; if(op==0){ for(int i=1;i<=num;i++) mon[i]+=10,sum+=10; } else{ for(int i=1;i<=num;i++) ma=max(ma,mon[i]); } for(int i=1;cntt<num;i=i%num+1){ if(dinum==num-1) break; if(at[i]){cntt++;continue;} setcolor(13); gotoxy(i*3-2,1); cout<<"Player "<<i<<" "<<nam[i]<<":\n"; setcolor(7); if(i==my){ gotoxy(3*i-1,5); if(isra||ma==maxmoney)cout<<"You bet: "<<ma<<" (Input \"dc\" to discard):\n"; else if(ma*2>=maxmoney)cout<<"You bet: "<<ma<<" or "<<maxmoney<<" (Input \"dc\" to discard):\n"; else cout<<"You bet: "<<ma<<" or "<<ma*2<<" - "<<min(maxmoney*1ll,isra?ma:(mon[i]+1ll*sum*2))<<" (Input \"dc\" to discard):\n"; show(); gotoxy(3*i,5); string ss="";int v=0; while(getline(cin,ss)){ if(ss=="dc"){v=0;break;} if(ss.length()>6){ gotoxy(3*i,5); for(int g=1;g<=40+nlen;g++) cout<<" "; gotoxy(3*i,5); continue; } int flag=0;v=0; for(int i=0;ss[i];i++) if(ss[i]<'0'||ss[i]>'9'){flag=1;break;} if(stringto(ss)>maxmoney){ gotoxy(3*i,5); for(int g=1;g<=40+nlen;g++) cout<<" "; gotoxy(3*i,5); continue; } if(flag){ gotoxy(3*i,5); for(int g=1;g<=spacenum+nlen;g++) cout<<" "; gotoxy(3*i,5); continue; } for(int i=0;ss[i];i++) v=v*10+ss[i]-'0'; if(v==ma) break; if(v<ma||v>mon[i]+sum*2||(isra&&v!=ma)||v<min(ma*2,maxmoney*1ll)){ gotoxy(3*i,5); for(int g=1;g<=spacenum+nlen;g++) cout<<" "; gotoxy(3*i,5); continue; } break; } hide(); Sen(to_string(v)); gotoxy(3*i,5);for(int g=1;g<=spacenum+nlen;g++) cout<<" "; gotoxy(3*i-1,5);for(int g=1;g<=spacenum+nlen;g++) cout<<" "; } string debu=Rec(); int v=stringto(rem(debu)); if(v==0){ cntt++; setcolor(8); gotoxy(3*i-2,1); cout<<"Player "<<i<<" "<<nam[i]<<": The bet is "<<mon[i]<<". (Discard)";at[i]=1,dinum++; for(int g=1;g<=20;g++) cout<<" "; for(int j=1;j>=0;j--){ Card tt=stringtocard(rem(Rec())); gotoxy(i*3-j,5); cout<<"Card "<<2-j<<": "<<number[tt.x]<<" "<<color[tt.co]<<"\n"; } setcolor(7); } else{ if(!fir) fir=i; gotoxy(3*i-2,12+nlen); cout<<"The bet is "<<v<<".";sum-=mon[i],mon[i]=v,sum+=v,cntt++; if(v>ma){ ma=v,cntt=1; if(i==my&&(!(i==fir&&flag==0&&!op))) isra=1; flag=1; } gotoxy(i*3-2,1); cout<<"Player "<<i<<" "<<nam[i]<<":\n"; } } } void Play(int rn){ hide(); memset(mon,0,sizeof(mon)),memset(at,0,sizeof(at)); sum=dinum=ishide=isend=0;
p.clear(); int rr=tablepos+21+nlen; for(int i=1;i<=max(3*num+10,high);i++){ gotoxy(i,1); for(int j=1;j<=rr;j++) cout<<" "; } if(rn==1){ Nlen=max(nlen,10); gotoxy(2,rr+3);PR; gotoxy(3,rr+3);cout<<"|RN|"; for(int i=1;i<=num;i++){ cout<<nam[i]; for(int j=1;j<=Nlen-nam[i].length();j++) cout<<" "; cout<<"|"; } gotoxy(4,rr+3);PR; gotoxy(5,rr+3);cout<<"|0 |";for(int i=1;i<=num;i++) cout<<_tostring(20000)<<"|";cout<<"\n"; gotoxy(6,rr+3);PR; gotoxy(7,rr+3);cout<<"|# |";for(int i=1;i<=num;i++) setcolor(14),cout<<_tostring(20000),setcolor(7),cout<<"|";cout<<"\n"; gotoxy(8,rr+3);PR; for(int i=1;i<=num;i++) nowmon[i]=20000; } string tmp; while(1){ tmp=Rec(); if(tmp=="fsb:") break; } for(int i=1;i<=num;i++){ tmp=Rec();from[stringto(tmp)]=i; nam[i]=namm[stringto(tmp)]; if(stringto(tmp)==myy) my=i; } Rec(); gotoxy(1,1); for(int i=1;i<=num;i++) cout<<"Player "<<i<<" "<<nam[i]<<": \n\n\n"; for(int i=1;i<=2;i++) p.emplace_back(stringtocard(rem(Rec())));print(p);raise_bet(0,rn); for(int i=1;i<=3;i++) p.emplace_back(stringtocard(rem(Rec())));print(p);raise_bet(1,rn); for(int i=1;i<=1;i++) p.emplace_back(stringtocard(rem(Rec())));print(p);raise_bet(1,rn); for(int i=1;i<=1;i++) p.emplace_back(stringtocard(rem(Rec())));print(p);raise_bet(1,rn); while(1){ tmp=Rec(); if(getop(tmp)=="then") break; } pair<int,Card> cr[20][2];int cnt=0; for(int i=1;i<=num;i++)if(!at[i]){ cnt++; for(int j=1;j>=0;j--){ Card tt=stringtocard(rem(Rec()));cr[cnt][1-j]=make_pair(i,tt); gotoxy(i*3-j,5); cout<<"Card "<<2-j<<": "<<number[tt.x]<<" "<<color[tt.co]<<"\n"; } } Sen("then"); while(1){ tmp=Rec(); if(getop(tmp)=="then") break; } isend=1; pair<int,vector<Card> >minn; vector<int> winner;winner.clear(); bool iswin[20];memset(iswin,0,sizeof(iswin)); int sui[20]; for(int i=1;i<=cnt;i++){ vector<Card>tt;tt.clear(); for(int j=2;j<7;j++) tt.emplace_back(p[j]); for(int j=0;j<2;j++) tt.emplace_back(cr[i][j].second); if(i==1){minn=Choice(tt),winner.emplace_back(i),sui[i]=minn.first;continue;} pair<int,vector<Card> > t=Choice(tt);sui[i]=t.first; int tmp=cmp(minn,t); if(tmp==0) winner.emplace_back(i); else if(tmp==-1) minn=t,winner.clear(),winner.emplace_back(i); } for(auto x:winner) iswin[x]=1; gotoxy(25,1); ll zf[20]; for(int i=1;i<=cnt;i++){ gotoxy(tablehigh*i-6,tablepos); cout<<"+";for(int i=1;i<=20+nlen;i++) cout<<"-";cout<<"+"; vector<Card>tt;tt.clear(); string name=nam[cr[i][0].first]; for(int j=2;j<7;j++) tt.emplace_back(p[j]); for(int j=0;j<2;j++) tt.emplace_back(cr[i][j].second); pair<int,vector<Card> >t=Choice(tt);vector<Card>ttt=t.second; int flag=0; for(auto x:winner) if(x==i){flag=1;break;} gotoxy(tablehigh*i-5,tablepos); cout<<"|"<<" "; if(flag) setcolor(13); cout<<name<<": "<<suit[t.first];gotoxy(tablehigh*i-5,rr); if(flag) setcolor(7); cout<<"|"; for(int j=0;j<5;j++){ gotoxy(tablehigh*i+j-4,tablepos); cout<<"| "; if(flag) setcolor(13); cout<<number[ttt[j].x]<<" "<<color[ttt[j].co];gotoxy(tablehigh*i+j-4,rr); if(flag) setcolor(7); cout<<"|"; } gotoxy(tablehigh*i+1,tablepos);cout<<"| "; ll val=0; if(iswin[i]){ int cnttt=0; for(int j=1;j<=num;j++){ if(!at[j]) cnttt++; if(at[j]||!iswin[cnttt]){ if(at[j]) val+=mon[j]; else if(sui[cnttt]!=minn.first) val+=mon[j]*mul[minn.first]; else val+=mon[j]; } } val/=winner.size(); val/=10,val*=10;zf[cr[i][0].first]=val; setcolor(10); cout<<"+ "<<val; setcolor(7); gotoxy(tablehigh*i+1,rr); cout<<"|"; } else{ int id=cr[i][0].first; if(sui[i]!=minn.first&&!at[id]) val=mon[id]*mul[minn.first]; else val+=mon[id]; setcolor(8);zf[cr[i][0].first]=-val; cout<<"- "<<val; setcolor(7); gotoxy(tablehigh*i+1,rr); cout<<"|"; } } int now=tablehigh*cnt-1,cnttt=0; for(int i=1;i<=num;i++) if(at[i]){ cnttt++; gotoxy(now+3*cnttt,tablepos); cout<<"+";for(int i=1;i<=20+nlen;i++) cout<<"-";cout<<"+"; gotoxy(now+3*cnttt+1,tablepos); cout<<"| "; setcolor(8); cout<<nam[i]<<" (Discard):"; gotoxy(now+3*cnttt+2,tablepos+2); cout<<"- "<<mon[i]; zf[i]=-mon[i]; setcolor(7); gotoxy(now+3*cnttt+1,rr);cout<<"|"; gotoxy(now+3*cnttt+2,tablepos);cout<<"|"; gotoxy(now+3*cnttt+2,rr);cout<<"|"; } gotoxy(now+3*cnttt+3,tablepos);high=now+3*cnttt+3; cout<<"+";for(int i=1;i<=20+nlen;i++) cout<<"-";cout<<"+"; ll zff[20]; for(int i=1;i<=num;i++) zff[i]=zf[i]; for(int i=1;i<=num;i++) zf[i]=zff[from[i]]; for(int i=1;i<=num;i++) nowmon[i]+=zf[i]; int cln=calcline(rn); if(rn%20==1){ for(int i=calcline(20)+2;i<=calcline(20)+3;i++){ gotoxy(i,rr+3); for(int j=rr+3;j<150;j++) cout<<" "; } } gotoxy(cln,rr+3); cout<<"|"<<_tostring(rn,2)<<"|"; for(int i=1;i<=num;i++){ if(zf[i]<=0) setcolor(8); else setcolor(10); cout<<_tostring(zf[i]); setcolor(7);cout<<"|"; } gotoxy(cln+2,rr+3); cout<<"|# |"; for(int i=1;i<=num;i++){ setcolor(14); cout<<_tostring(nowmon[i]); setcolor(7);cout<<"|"; } gotoxy(cln+3,rr+3);PR; gotoxy(3*num+10,1);cout<<"Press F3 to the next round.\n"; while(!kd(VK_F3)); Sleep(rng()%500+250);Sen("OK"); int visss[20];memset(visss,0,sizeof(visss)); while(1){ tmp=Rec(); gotoxy(28,1); if(tmp=="then:") break; visss[stringto(rem(tmp))]=1; int tmpp=0; for(int i=1;i<=num;i++)if(!visss[i]){tmpp=i;break;} if(!tmpp) continue; gotoxy(3*num+10,1); cout<<"Waiting player "<<namm[tmpp]<<"."; for(int i=17+nlen;i<=30;i++) cout<<" "; } Sleep(1000); } void try_join(){ CreateThread(NULL,0,whide,NULL,0,NULL); WSADATA wsaData; if(WSAStartup(MAKEWORD(2,2),&wsaData)!=0) exit(0); server=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); if(server==(SOCKET)(~0)) WSACleanup(),exit(0); set_name: puts("Input your username (length less than 10):\n"); show(); gets(a); puts(""); auto check=[](string s){ for(int i=0;i<s.size();i++) if(s[i]=='\0'||s[i]=='\n'||s[i]<0||s[i]==':'||s[i]==';') return 0; return s.size()>0?1:0; }; if(strlen(a)>=10||check(a)==0) { printf("Illegal username!\n\n"); Sleep(1000); system("cls"); goto set_name; exit(0); } puts("Input server IP (input return to input username again):\n"); set_ipv4: show(); gets(ipv4); puts(""); if(strlen(ipv4)==6&&ipv4[0]=='r'&&ipv4[1]=='e'&&ipv4[2]=='t'&&ipv4[3]=='u'&&ipv4[4]=='r'&&ipv4[5]=='n'){ system("cls"); goto set_name; exit(0); } Sleep(300); cout<<"Tips:\nPress F8 to hide your cards;\nPress Ctrl & Space to hide/show your process.\n\nPress Enter to the next step:"; while(!kd(VK_RETURN)); getchar(); cout<<"\nWaiting for server connection...";hide(); sockaddr_in conser; conser.sin_family=AF_INET; conser.sin_port=htons(port); conser.sin_addr.S_un.S_addr=inet_addr(ipv4); for(int i=1;i<=10;i++){ if(connect(server,(LPSOCKADDR)&conser,sizeof(conser))==(SOCKET)(~0)){ if(i==10){ for(int j=9;j<=15;j++){ gotoxy(j,1); cout<<" "; } gotoxy(9,1);gotoxy(9,1); cout<<"Illegal server IP!"; Sleep(1300); gotoxy(9,1);cout<<" "; gotoxy(7,1); for(int j=1;j<=strlen(ipv4);j++) cout<<" "; gotoxy(7,1); goto set_ipv4; exit(0); } } else break; } system("cls"); send(server,a,strlen(a),0); Sleep(slt); string tmp=Rec(),tmpp="";int tmppp=0; for(int i=9;i<tmp.length();i++){ if(tmp[i]==';') nam[++tmppp]=tmpp,tmpp=""; else tmpp+=tmp[i]; } num=tmppp,myy=tmppp+1; for(int i=1;i<=tmppp;i++) cout<<"Player "<<i<<" "<<nam[i]<<"\n"; while(1){ tmp=Rec(); if(tmp=="start:") break; num++; for(int i=8;tmp[i];i++) nam[num]+=tmp[i]; cout<<"Player "<<num<<" "<<nam[num]<<"\n"; } for(int i=1;i<=num;i++) nlen=max(nlen,(int)nam[i].length()); for(int i=1;i<=num;i++) while(nam[i].length()<nlen) nam[i]+=" "; for(int i=1;i<=num;i++) namm[i]=nam[i]; system("cls"); int flaggg=0; while(1) Play(++flaggg); while(1); closesocket(server); WSACleanup(); } } int main(){ system("mode con cols=155 lines=50"); noedit();show(); bool f=0,F=0; puts("Is this process going to be a server? (0/1):"); string strr; while(getline(cin,strr)){ if(strr.length()==1&&(strr[0]=='0'||strr[0]=='1')) break; else{ gotoxy(2,1); for(int i=0;i<strr.length();i++) cout<<" "; gotoxy(2,1); } } f=(strr[0]=='1'),f=!f,F=f; system("cls"); if(!f) Server::main(f); if(F!=f) assert(!!"Are you FSB? Don't set up two servers!"); if(f) system("cls"),User::try_join(); return 0; }
|