gpt4 book ai didi

c++ - Connect 4 - 不能编程检查是否有人赢了

转载 作者:行者123 更新时间:2023-11-28 06:09:00 25 4
gpt4 key购买 nike

我已经编写了一个程序,可以让整个游戏完美运行,而我唯一不能做的就是检查是否获胜。我在两个文件中制作了游戏:1.主要2. 功能。这是“主要”文件:

#include <iostream>
#include <sstream>
#include <windows.h>
#include <string>

using namespace std;


void getname();
void scoregiving();
void gamestart();
void boardmaking();
void fullgameplay();

int main()
{
gamestart();
getname();
scoregiving();
fullgameplay();
}

这是函数文件:

#include <iostream>
#include <sstream>
#include <Windows.h>
#include <string>

using namespace std;

string p1, p2;
int tu,
board[6][7],
colomuns[7],
makeboard,
makeboard1,
scoregive,
scoregive1,
input,
colomunss,
check,
check1;

void line()
{
cout << "|=|=|=|=|=|=|=|\n|";
}
void getname()
{
cout << "\n\nPlayer, Please Enter Your Name. You'll Be X\n<< ";
cin >> p1;
cout << "2nd Player, Please Enter Your Name. You'll Be O\n<< ";
cin >> p2;
tu = 1;
}
void gamestart()
{
cout << " (--OOO--OOO---OOO--OOO--)\n";
cout << " |XX========XXX========XX|\n";
cout << " ||CONNECT 4 BY: NETVIZHEN||\n";
cout << " |XX========XXX========XX|\n";
cout << " (--OOO--OOO---OOO--OOO--)";
}
void boardmaking()
{
cout << "\n\nBoard:\n";
cout << "\n 0 1 2 3 4 5 6\n";
line();
for (makeboard = 0; makeboard <= 5; makeboard ++)
for (makeboard1 = 0; makeboard1 <= 6; makeboard1++)
{
if (board[makeboard][makeboard1] == 0)
{
cout << " |";
}
else if (board[makeboard][makeboard1] == 1)
{
cout << "X|";
}
else if (board[makeboard][makeboard1] == 2)
{
cout << "O|";
}
if (makeboard1 == 6)
{
cout << "\n";
line();
}
}
}
void scoregiving()
{
for (scoregive = 0 ; scoregive < 6 ; scoregive++)
for (scoregive1 = 0 ; scoregive1 < 7 ; scoregive1++)
board[scoregive][scoregive1] = 0;
for (colomunss = 0; colomunss <= 6; colomunss++)
colomuns[colomunss] = 0;
}
void wincheck()
{
for (check = 0; check <=5; check++)
for (check1 = 0; check1 <= 6; check1++)
if (board[check][check1] == tu)
if (board[check - 1][check1] == tu && board[check - 2][check1] == tu && board[check - 3][check1] == tu && board[check][check1] == tu)
cout << "ggh";
}
void putin()
{
cout << "\n<< ";
cin >> input;
if (input >= 7)
cout << "\nThis Location Is Outside The Board. Please Retry.";
else if (colomuns[input] > 5 )
cout << "\nThis Column Is Full. Please Retry.";
else
{
board[5-colomuns[input]][input] = tu;
colomuns[input]++;
wincheck();
if (tu == 2)
tu--;
else if (tu == 1)
tu++;
}
}
void fullgameplay()
{
while(true)
{
boardmaking();
putin();
}
}

最佳答案

这是井字游戏吗?但如果是,那么为什么行和列的大小不一样,因为如果他的连胜对角线,那么确定获胜者将是一个问题。

关于c++ - Connect 4 - 不能编程检查是否有人赢了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31674498/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com