跳到正文

休闲·娱乐

骗子酒馆(骰子玩法),可能有BUG

hwc2011约 9 分钟
原文
文章信息与版本

文章信息

发布
2025年3月11日
收录
2025年12月12日
更新
2026年11月17日
篇幅
约 9 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int death[4],num[4][5],sum[4][7];
int random(int n){
	return (long long)rand()*rand()%n;
}
void SetColorAndBackground(int ForgC,int BackC) {
	WORD wColor=((BackC&0x0F)<<4)+(ForgC&0x0F);
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),wColor);
}
void start(){
	system("cls");
	SetColorAndBackground(15,0);
	if(death[0]==1) SetColorAndBackground(13,0);
	if(death[0]>1) SetColorAndBackground(4,0);
	cout<<"         00\n";
	SetColorAndBackground(15,0);
	if(death[1]==1) SetColorAndBackground(13,0);
	if(death[1]>1) SetColorAndBackground(4,0);
	cout<<"01              ";
	SetColorAndBackground(15,0);
	if(death[3]==1) SetColorAndBackground(13,0);
	if(death[3]>1) SetColorAndBackground(4,0);
	cout<<"  03\n";
	SetColorAndBackground(15,0);
	if(death[2]==1) SetColorAndBackground(13,0);
	cout<<"         02\n";
	SetColorAndBackground(15,0);
	for(int i=0;i<5;i++) cout<<num[2][i]<<' ';
	cout<<'\n';
}
void turn(){
	for(int i=0;i<4;i++) for(int j=1;j<=6;j++) sum[i][j]=0;
	for(int i=0;i<4;i++){
		for(int j=0;j<5;j++){
			num[i][j]=random(36)/6+1;
			sum[i][num[i][j]]++;
			if(num[i][j]==1){
				for(int k=2;k<=6;k++) sum[i][k]++;
			}
		}
	}
	start();
	int now=random(4),fst=1,cnt=1,point=0,life=0,lst=-1;
	while(death[now]==2) now=(now+1)%4;
	for(int i=0;i<4;i++){
		if(death[i]<2) life++;
	}
	while(1){
		if(now!=2){
			int op=random(5);
			if(sum[now][point]+life*2-2<cnt){
				cout<<"0"<<now<<"号:LIAR\n";
				Sleep(500);
				int res=0;
				for(int i=0;i<4;i++){
					if(death[i]<2){
						cout<<"0"<<i<<"号有"<<sum[i][point]<<"个"<<point<<'\n';
						Sleep(500);
						res+=sum[i][point];
					}
				}
				cout<<"总共有"<<res<<"个"<<point<<'\n';
				if(res<cnt) death[lst]++;
				else death[now]++;
				return;
			}
			if(sum[now][point]+life*2-2==cnt&&!op){
				cout<<"0"<<now<<"号:SPOT ON\n";
				Sleep(500);
				int res=0;
				for(int i=0;i<4;i++){
					if(death[i]<2){
						cout<<"0"<<i<<"号有"<<sum[i][point]<<"个"<<point<<'\n';
						Sleep(500);
						res+=sum[i][point];
					}
				}
				cout<<"总共有"<<res<<"个"<<point<<'\n';
				if(res==cnt){
					now=(now+3)%4;
					death[now]++;
					now=(now+3)%4;
					death[now]++;
					now=(now+3)%4;
					death[now]++;
				}
				else death[now]++;
				return;
			}
			int maxx=0,id;
			for(int i=1;i<=6;i++){
				if(sum[now][i]>=maxx){
					maxx=sum[now][i];
					id=i;
				}
			}
			int x=max(maxx+random(5)-2,cnt);
			if(id<=point&&x==cnt) cnt++;
			else cnt=x;
			point=id;
			cout<<"0"<<now<<"号:"<<cnt<<"个"<<point<<"\n";
			Sleep(500);
		}
		else{
			cout<<"SPOT ON:0 0\n";
			cout<<"LIAR:1 0\n";
			cout<<"COMMON:X Y,表示X个Y\n";
			int x,y;
			cin>>x>>y;
			if(x==0&&y==0){
				if(fst){
					while(1){
						cout<<"你他妈会不会玩!!!\n";
					}
				}
				cout<<"0"<<now<<"号:SPOT ON\n";
				Sleep(500);
				int res=0;
				for(int i=0;i<4;i++){
					if(death[i]<2){
						cout<<"0"<<i<<"号有"<<sum[i][point]<<"个"<<point<<'\n';
						Sleep(500);
						res+=sum[i][point];
					}
				}
				cout<<"总共有"<<res<<"个"<<point<<'\n';
				if(res==cnt){
					now=(now+3)%4;
					death[now]++;
					now=(now+3)%4;
					death[now]++;
					now=(now+3)%4;
					death[now]++;
				}
				else death[now]++;
				return;
			}
			if(x==1&&y==0){
				if(fst){
					while(1){
						cout<<"你他妈会不会玩!!!\n";
					}
				}
				cout<<"0"<<now<<"号:LIAR\n";
				Sleep(500);
				int res=0;
				for(int i=0;i<4;i++){
					if(death[i]<2){
						cout<<"0"<<i<<"号有"<<sum[i][point]<<"个"<<point<<'\n';
						Sleep(500);
						res+=sum[i][point];
					}
				}
				cout<<"总共有"<<res<<"个"<<point<<'\n';
				if(res<cnt) death[lst]++;
				else death[now]++;
				return;
			}
			if(x<cnt||y<0||y>6||x==cnt&&y<=point){
				while(1){
					cout<<"你他妈会不会玩!!!\n";
				}
			}
			cnt=x;
			point=y;
			cout<<"0"<<now<<"号:"<<cnt<<"个"<<point<<"\n";
			Sleep(500);
		}
		fst=0;
		lst=now;
		do{
			now=(now+1)%4;
		}while(death[now]>1);
		life=0;
		for(int i=0;i<4;i++){
			if(death[i]<2) life++;
		}
	}
}
void game(){
	for(int i=0;i<4;i++) death[i]=0;
	while(death[2]<2&&!(death[0]>1&&death[1]>1&&death[3]>1)){
		Sleep(2000);
		turn();
	}
	Sleep(2000);
	system("cls");
	if(death[2]>1) cout<<"你死了\n";
	else cout<<"你赢了\n";
}
int main(){
	srand((unsigned)time(0));
	while(1){
		cout<<"骗子酒馆C++版(骰子)\n";
		game();
		cout<<"还要继续吗?(y/n)";
		char c;
		cin>>c;
		if(c=='n') return 0;
		if(c!='y'){
			while(1){
				cout<<"你他妈会不会玩!!!\n";
			}
		}
		system("cls");
	}
}
原文