C++#include <bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<string.h>
#include<windows.h>
#include<conio.h>
#include<fstream>
#include<winsock.h>
#define LL long long
#define lL unsigned long long
#define ui unsigned
#define F(i, j, k) for (int i = j;i <= k;i++)
#define RF(i, j, k) for (int i = j;i >= k;i--)
#define line(n) for (int i = 1;i <= n;i++) cout << endl
#define space(i) cout << setw(i)
#define alt(x) MessageBox(NULL, x, name, MB_YESNO | MB_ICONINFORMATION)
#define OK(x) MessageBox(NULL, x, name, MB_OK)
#define SC(i) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), i)
#define Rt IDYES
#define Wr IDNO
#define Nocan say("开发中.......\n"), pa
#define cls system("cls")
#define pa system("pause")
#define add(x, y) stract(x, y);
using namespace std;
int sdtime = 20, sz = 10;
char filename[100] = "stone V0.0.1.txt";
char name[100] = "欢乐Stone", place[100][100];
typedef BOOL (WINAPI *PROCSETCONSOLEFONT)(HANDLE, DWORD);
PROCSETCONSOLEFONT SetConsoleFont;
map<int, int>stone;
map<int, bool>bstone;
struct dot{
int x, y, f;
};
POINT Windowpos(){
POINT pt;
GetCursorPos(&pt);
HWND h=GetForegroundWindow();
ScreenToClient(h,&pt);
pt.x/=8;
pt.y/=16;
return pt;
}
void setsaid(){
system("cls");
printf("1.慢 2.超慢 3.正常 4.快 5.超快 6.极速\n");
int k;
cin >> k;
sdtime = abs(k - 6) * 10;
}
int rd(int x){
return rand() % x;
}
void hide(){
HANDLE h_GAME = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursor_info;
GetConsoleCursorInfo(h_GAME,&cursor_info);
cursor_info.bVisible=false;
SetConsoleCursorInfo(h_GAME,&cursor_info);
}
void show()
{
HANDLE h_GAME =GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursor_info;
GetConsoleCursorInfo(h_GAME,&cursor_info);
cursor_info.bVisible=true;
SetConsoleCursorInfo(h_GAME,&cursor_info);
}
int toint(float a){return ((int)(a*10+5))/10;}
void gotoxy(float x,float y){int xx=toint(x),yy=toint(y);COORD pos;pos.X=xx*2,pos.Y=yy;SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);}
bool ctrlmouse(int cmaa,int cmbb,int cmcc,int cmdd){
int mouse;
mouse=GetAsyncKeyState(VK_LBUTTON)&0x8000;
POINT pt=Windowpos();
for(int i=cmaa;i<=cmbb;i++)
for(int j=cmcc;j<=cmdd;j++)
if(pt.y==i && pt.x==j && mouse) return true;
return false;
}
void say(char *s){
while (*s != NULL){
cout << *s;
*s++;
Sleep(sdtime);
}
}
void mouseyi(){
int flag = 0;
hide();
for (int i = 1;i <= 10;i++){
POINT mouse;
bool k = GetCursorPos(&mouse);
int x = mouse.x, y = mouse.y;
if (x < 0) x = 0;if (y < 0) y = 0;
int xx = x / 128, yy = (y + 1) / 72;
for (int i = 0;i <= 10;i++){
for (int j = 0;j <= 10;j++)
if (i == yy and j == xx) cout << ".";
else cout << " ";
cout << endl;
}
cls;
}
}
void cl(){
gotoxy(0, 0);
F(i, 0, 100){
F(j, 0, 100) cout << setw(200);
cout << endl;
}
gotoxy(0, 0);
}
void init(){
int now = 1;
for (int i = 1;i <= 3 * 1e3;i++){
while (bstone[now] == 1) now++;
int nex = now + i;
bstone[now] = 1;
bstone[nex] = 1;
stone[nex] = now;
//stone[now] = nex;
now ++;
}
}
void game(int f){
int ls = rand() % 100 + 10, rs = rand() % 100 + 10, win = 0;
while (!win){
kkkssss:
system("cls");
cout << "左石子 右石子\n";
cout << ls << " " << rs << endl;
cout << "请输入取法\n\t1.取左堆\n\t2.取右堆\n\t3.取两堆\n";
char www = getch();
cout << "取多少个?\n";
int k;
cin >> k;
if (www == '1'){
if (ls >= k) ls -= k;
else {cout << "左边不够\n";goto kkkssss;}
}
if (www == '2'){
if (rs >= k) rs -= k;
else {cout << "右边不够\n";goto kkkssss;}
}
if (www == '3'){
if (ls >= k and rs >= k) ls -= k, rs -= k;
else {cout << "有一堆或两堆不够\n";goto kkkssss;}
}
system("cls");
cout << "你取完了\n左石子 右石子\n";
cout << ls << " " << rs << endl;
cout << "人机开始取\n";
int can = rand() % 100;
short righ = 0;
if (f == 1) righ = (can <= 20);
if (f == 2) righ = (can <= 50);
if (f == 3) righ = (can <= 80);
if (f == 4) righ = (can <= 90);
if (f == 5) righ = 2;
cout << can << " " << righ << endl;
if (righ != 2){
if (righ == 1){
if (ls != rs){
int cl = stone[ls], cr = stone[rs], wr = 0;
//if (cl )
//cout << "";
}
}
}
}
}
void play(){
while (1){
system("cls");
cout << "模式:\n";
cout << "\t1.普通取石子\n";
cout << "\t2.奇怪博弈(暂未开通)\n";
char c = getch();
if (c == '1'){
system("cls");
cout << "难度:\n";
cout << "\t1.普通难度\n";
cout << "\t\t人机是新手\n";
cout << "\t2.经典难度\n";
cout << "\t\t人机还算聪明\n";
cout << "\t3.普通难度\n";
cout << "\t\t巨佬人机\n";
char ccf;
ccf = getch();
game(ccf - '0');
}
//if ()
}
}
int main()
{
srand((unsigned long long)time(NULL));
//system("MODE CON COLS=100 LINES=20");
system("color a");
cout << " 欢迎来到Happy Stone(取石子),它可以让你更明白博弈论\n\n\n";
cout << " 按下任意键开始";
getch();
init();
while (1){
cout << "\t\tHappy Stone\n";
cout << "\t1.开始\n\n";
cout << "\t2.查看规则\n\n";
int proud = getch();
if (proud == '1') play();
if (proud == '2') ;
system("cls");
}
/*
for (int i = 1;i <= 40;i++){
cout << i << " " << stone[i] << endl;
}*/
return 0;
}