写完井字棋游戏(链接见文末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