using System.Collections.Generic;
public static void Main(String[] args)
int openCircleID = int.Parse("25CB", System.Globalization.NumberStyles.HexNumber);
String openCircle = char.ConvertFromUtf32(openCircleID);
else if (Color == "white")
int closedCircleID = int.Parse("25CF", System.Globalization.NumberStyles.HexNumber);
String closedCircle = char.ConvertFromUtf32(closedCircleID);
public String Color { get; set; }
public Checker(String color)
public override String ToString()
public Checker[][] Grid { get; set; }
public List<Checker> Checkers { get; set; }
public void CreateBoard()
Checkers = new List<Checker>();
for (int row = 0; row < 3; row++)
for (int column = 0; column < 8; column++)
if ((row == 0 || row == 2) && (column % 2 != 0))
checker = new Checker("white");
Grid[row][column] = checker;
else if ((row == 1) && (column % 2 == 0))
checker = new Checker("white");
Grid[row][column] = checker;
for (int row = 5; row < 8; row++)
for (int column = 0; column < 8; column++)
if ((row == 5 || row == 7) && (column % 2 == 0))
checker = new Checker("black");
Grid[row][column] = checker;
else if ((row == 6) && (column % 2 != 0))
checker = new Checker("black");
Grid[row][column] = checker;
public String DrawBoard()
String formattedBoard = " 0 1 2 3 4 5 6 7" + "\n";
for (int row = 0; row < 8; row++)
formattedBoard += Convert.ToString(row) + " ";
for (int column = 0; column < 8; column++)
if (Grid[row][column] != null)
if (Grid[row][column].Symbol != "")
formattedBoard += Grid[row][column] + " ";
public Checker SelectChecker(int row, int column, String color)
if (Grid[row][column].Color == color)
return Grid[row][column];
String invalidPiece = Grid[row][column].Color;
throw new Exception("$It is not {invalidPiece}'s turn");
public void PlaceChecker(int originRow, int originColumn, int destinationRow, int destinationColumn, Checker checker)
if (Grid[destinationRow][destinationColumn] == null)
if (checker.Color == "white")
if ((destinationRow == originRow + 1) && (destinationColumn == originColumn - 1 || destinationColumn == originColumn + 1))
Grid[destinationRow][destinationColumn] = checker;
else if ((destinationRow == originRow + 2) && (destinationColumn == originColumn - 2 || destinationColumn == originColumn + 2))
if ((destinationColumn > originColumn) && (Grid[destinationRow - 1][destinationColumn - 1].Color != "white"))
Grid[destinationRow][destinationColumn] = checker;
else if ((destinationColumn < originColumn) && (Grid[destinationRow - 1][destinationColumn + 1].Color != "white"))
Grid[destinationRow][destinationColumn] = checker;
throw new Exception("invalid move");
throw new Exception("Cannot move here");
if (checker.Color == "black")
if ((destinationRow == originRow - 1) && (destinationColumn == originColumn - 1 || destinationColumn == originColumn + 1))
Grid[destinationRow][destinationColumn] = checker;
else if ((destinationRow == originRow - 2) && (destinationColumn == originColumn - 2 || destinationColumn == originColumn + 2))
if ((destinationColumn > originColumn) && (Grid[destinationRow + 1][destinationColumn - 1].Color != "black"))
Grid[destinationRow][destinationColumn] = checker;
else if ((destinationColumn < originColumn) && (Grid[destinationRow + 1][destinationColumn + 1].Color != "black"))
Grid[destinationRow][destinationColumn] = checker;
throw new Exception("invalid move");
throw new Exception("Cannot move here");
throw new Exception("There is a checker there.");
public bool RemoveChecker(int originRow, int originColumn, int destinationRow, int destinationColumn, Checker checker)
if (checker.Color == "white")
if (destinationRow == originRow + 2)
if (destinationColumn == originColumn + 2)
Checkers.Remove(Grid[destinationRow - 1][destinationColumn - 1]);
Grid[originRow][originColumn] = null;
Grid[destinationRow - 1][destinationColumn - 1] = null;
else if (destinationColumn == originColumn - 2)
Checkers.Remove(Grid[destinationRow - 1][destinationColumn + 1]);
Grid[originRow][originColumn] = null;
Grid[destinationRow - 1][destinationColumn + 1] = null;
if (checker.Color == "black")
if (destinationRow == originRow - 2)
if (destinationColumn == originColumn + 2)
Checkers.Remove(Grid[destinationRow + 1][destinationColumn - 1]);
Grid[originRow][originColumn] = null;
Grid[destinationRow + 1][destinationColumn - 1] = null;
else if (destinationColumn == originColumn - 2)
Checkers.Remove(Grid[destinationRow + 1][destinationColumn + 1]);
Grid[originRow][originColumn] = null;
Grid[destinationRow + 1][destinationColumn + 1] = null;
Grid[originRow][originColumn] = null;
public bool CheckForWin()
return Checkers.All(x => x.Color == "white") || !Checkers.Exists(x => x.Color == "white");
Board boardgame = new Board();
Console.WriteLine(boardgame.DrawBoard());
Console.WriteLine("${color}, please enter a row to move from:");
int originRow = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("${color}, please enter a column to move from:");
int originColumn = Convert.ToInt32(Console.ReadLine());
Checker checker = boardgame.SelectChecker(originRow, originColumn, color);
Console.WriteLine(boardgame.DrawBoard());
Console.WriteLine("Please enter the row to move to: ");
int destinationRow = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please enter the column to move to: ");
int destinationColumn = Convert.ToInt32(Console.ReadLine());
boardgame.PlaceChecker(originRow, originColumn, destinationRow, destinationColumn, checker);
Console.WriteLine(boardgame.DrawBoard());
removedChecker = boardgame.RemoveChecker(originRow, originColumn, destinationRow, destinationColumn, checker);
Console.WriteLine(boardgame.DrawBoard());
if (removedChecker && !boardgame.CheckForWin())
Console.WriteLine("Do you have another move you can make with the same checker? [Y/N]");
userInput = Console.ReadLine().ToLower();
}while (userInput != "y" && userInput != "n");
else if (!removedChecker)
Console.WriteLine("Invalid selection.");
}while(!boardgame.CheckForWin());
Console.WriteLine("${color} wins!");