using System.Collections.Generic;
public static void Main()
Matrix Board = new Matrix(NrOfSides);
while(CheckWin(Board) == SignOptions.empty)
Console.Write("Row: "); string ReadRow = Console.ReadLine();
Console.Write("Column: "); string ReadCol = Console.ReadLine();
int RowNr = Convert.ToInt32(ReadRow);
int ColNr = Convert.ToInt32(ReadCol);
if(Board.Rows[RowNr - 1].Symbols[ColNr - 1].Sign == SignOptions.empty)
Board.Rows[RowNr - 1].Symbols[ColNr - 1].Sign = SignOptions.X;
throw new Exception("This coordinate is already taken!");
Console.WriteLine("Let me think of a countermove.....");
Console.WriteLine(e.Message);
Console.WriteLine("X has won");
Console.WriteLine("O has won");
Console.WriteLine("Its a draw");
public static SignOptions CheckWin(Matrix _board)
SignOptions ReturnValue = SignOptions.empty;
foreach(RowSymbols r in _board.Rows)
foreach(Symbol s in r.Symbols)
if(s.Sign == SignOptions.X) StreakX +=1;
if(s.Sign == SignOptions.O) StreakO +=1;
SignOptions Outcome = WhoWins(StreakX, StreakO, _board.Sides);
if(Outcome != SignOptions.empty)
if(ReturnValue != SignOptions.empty)
for(int i = 0; i < _board.Sides; i++)
foreach(Symbol s in _board.Rows[i].Symbols)
if(s.Sign == SignOptions.X) StreakX +=1;
if(s.Sign == SignOptions.O) StreakO +=1;
SignOptions Outcome = WhoWins(StreakX, StreakO, _board.Sides);
if(Outcome != SignOptions.empty)
private static SignOptions WhoWins(int _x, int _o, int _sides)
SignOptions ReturnValue = SignOptions.empty;
ReturnValue = SignOptions.X;
ReturnValue = SignOptions.O;
public List<RowSymbols> Rows {get; set;}
public int Sides {get; set;}
public Matrix(int _nrOfSides)
this.Rows = new List<RowSymbols>();
for(int i = 1; i <= _nrOfSides; i++)
this.Rows.Add(new RowSymbols(i, _nrOfSides));
public void CounterMove()
Console.WriteLine("done");
PrintHeaderFooter(this.Sides);
foreach(RowSymbols r in this.Rows)
string PrintSpaceLine = "";
foreach(Symbol c in r.Symbols)
case SignOptions.X: PrintLine += "X"; break;
case SignOptions.O: PrintLine += "O"; break;
case SignOptions.empty: PrintLine += " "; break;
Console.WriteLine(PrintSpaceLine);
Console.WriteLine(PrintLine);
Console.WriteLine(PrintSpaceLine);
PrintHeaderFooter(this.Sides);
private void PrintHeaderFooter(int _nrOfSides)
for(int i = 0; i < _nrOfSides; i++)
Console.WriteLine(PrintLine);
public List<Symbol> Symbols {get; set;}
public int RowNumber {get; set;}
public RowSymbols(int _rowNumber, int _nrOfSides)
this.Symbols = new List<Symbol>();
for(int i = 1; i <= _nrOfSides; i++)
this.Symbols.Add(new Symbol(SignOptions.empty, _rowNumber, i));
public SignOptions Sign {get; set;}
public int Row {get; set;}
public int Col {get; set;}
public Symbol (SignOptions _sign, int _row, int _col)