Tic tac toe

Discover the Ultimate Tic Tac Toe Experience with C#

Sukhpinder Singh
C# Programming

--

Tic Tac Toe, also known as Noughts and Crosses, is a classic two-player strategy game that people of all ages have enjoyed for many generations. The game is simple to play and requires only a few moves. This article will look at implementing the Tic Tac Toe game in C# programming language.
To begin with, let’s understand the basic rules of the game.

Photo by Jon Tyson on Unsplash

Tic Tac Toe is played on a 3x3 grid, where each player takes turns to place their mark (either an “X” or an “O”) on the grid. The game’s objective is to get three of your marks in a row, either horizontally, vertically, or diagonally, before your opponent does. The game is considered a draw if all of the squares on the grid are filled, and neither player has achieved the required three-in-a-row.

Let’s create a console application in Visual Studio, and then we’ll set up the game board. We’ll create a char array called “board” and initialize it with the numbers 0 to 8, representing the nine spaces on the grid. We’ll also create a variable “turns” that will keep track of the number of turns taken in the game.

using System;
namespace TicTacToe
{
class Program
{
static char[] board = { '0', '1', '2', '3', '4', '5', '6', '7', '8' };
static int turns = 0;

--

--

Sukhpinder Singh
C# Programming

Programmer by heart | C# | .Net 6 | .Net 8 | dotnet | dotnetcore | Kubernetes | Angular | AWS | Remember to 👏 Linktree: https://linktr.ee/sukhpindersingh