【C++ 程序】 五子棋游戏(人 VS 人)

写完井字棋游戏(链接见文末See also)忽然对这种小程序很感兴趣,于是就又写了五子棋的小程序。

程序

//This program is a simple gobang game.

#include <iostream>
#include <string>
#include <vector>
#include <cstddef>
using namespace std;

char player = 'X';
unsigned step_count = 0;
vector<vector<char>> p_n; // struct an undefined board;

void def_empty_board(vector<vector<char>>& p) // define an empty 15X15 board
{
   
    vector<char> p_n_temp;
	for (size_t i = 0; i != 15; i++) p_n_temp.push_back(' '); // the inner vector
	for (size_t i = 0; i != 15; i++) p.push_back(p_n_temp);   // the outer vector(i.e. the board)
}

void print_board(vector<vector<char>> p)
{
   
	char ch_15[15];
	for (size_t i = 0; i != 15; i++) ch_15[i] = 65 + i; // A-O ~ 65-79 (according to ASCII)
	cout << "| |0|0|0|0|0|0|0|0|0|1|1|1|1|1|1|" << endl;
	cout << "| |1|2|3|4|5|6|7|8|9|0|1|2|3|4|5|" << endl;
	for (size_t i = 0; i != 15; i++) // print 15 lines from A to O
	{
   
		cout << '|' << ch_15[i] << '|';
		for (size_t j = 0; j != 15; j++)
			cout << p[i][j] << '|';
		cout << endl;
	}
	cout << endl;
}

int change_board(vector<vector<char>>& p, string l)
{
   
	size_t location_letter, location_number;
	if 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值