I have finished my code for Conway's Game of Life. I am looking for any advice on how to improve it. I am a C++ beginner, so I used only basic libraries. I am accepting all suggestions.
/*
Author: Stevan Milic
Date: April 2018
Class: COSC 1560
Description: Game Of Life
*/
#include <iostream>
#include <cstdlib> // Library needed for CLS command
#include <iomanip>
using namespace std;
const int boardsize = 10;
void Display(bool board[boardsize + 1][boardsize + 1])
{
for (int x = 1; x < boardsize; x++)
{
for (int y = 1; y < boardsize; y++)
{
if (board[x][y] == true)
{
cout << " * ";
}
else
{
cout << " - ";
}
if (y == boardsize - 1)
{
cout << endl;
}
}
}
}
// Copying the board in order to compare the existing cells
void CopyBoard(bool board[boardsize + 1][boardsize + 1], bool board2[boardsize + 1][boardsize + 1])
{
for (int x = 0; x < boardsize; x++)
{
for (int y = 0; y < boardsize; y++)
{
board2[x][y] = board[x][y];
}
}
}
//Calculates function to determine if the cell is alive or dead
void Calc(bool board[boardsize + 1][boardsize + 1])
{
bool board2[boardsize + 1][boardsize + 1] = {};
CopyBoard(board, board2);
for (int x = 1; x < boardsize; x++)
{
for (int y = 1; y < boardsize; y++)
{
int alive = 0;
for (int z = -1; z < 2; z++)
{
for (int t = -1; t < 2; t++)
{
if (!(z == 0 && t == 0))
{
if (board2[x + z][y + t])
{
alive++;
}
}
}
}
if (alive < 2)
{
board[x][y] = false;
}
else if (alive == 3)
{
board[x][y] = true;
}
else if (alive > 3)
{
board[x][y] = false;
}
}
}
}
int main()
{
//const int boardsize = 10;
bool board[boardsize + 1][boardsize + 1] = {};
// Starting cells
board[5][4] = true;
board[5][5] = true;
board[5][6] = true;
board[4][4] = true;
board[4][5] = true;
board[4][6] = true;
board[3][4] = true;
board[3][5] = true;
board[3][6] = true;
while (true)
{
Display(board); // Displaying function
Calc(board); // Calculating function
system("CLS"); // Clearing the Screen
}
}