using System.Collections.Generic;
using System.Text.RegularExpressions;
public Checker(string color, int[] position)
int openCircleId = int.Parse("25CB", System.Globalization.NumberStyles.HexNumber);
string openCircle = char.ConvertFromUtf32(openCircleId);
int closedCircleId = int.Parse("25CF", System.Globalization.NumberStyles.HexNumber);
string closedCircle = char.ConvertFromUtf32(closedCircleId);
public int[] Position { get; set; }
public string Color { get; set; }
private List<Checker> checkers = new List<Checker>();
public static int[,] whitePositions = new int[12,2];
public static int[,] blackPositions = new int[12,2];
public string[][] Grid { get; private set; }
public List<Checker> Checkers
public void CreateBoard()
for (int i = 0; i < Grid.Length; i ++)
for (int i = 1; i < 9; i ++)
Grid[0][i] = (i).ToString();
for (int i = 1; i < 9; i ++)
for (int j = 0; j < 9; j ++)
Grid[i][j] = i.ToString();
public void GenerateCheckers()
int[][] whitePositions = new int[12][];
int[][] blackPositions = new int[12][];
for (int i = 0; i < 12; i ++)
whitePositions[i] = new int[2];
blackPositions[i] = new int[2];
for (int i = 0; i < 3; i ++)
for (int j = 0; j < 8; j += 2)
if (i % 2 == 0 && j == 0)
whitePositions[@array][0] = i;
whitePositions[@array][1] = j;
for (int i = 5; i < 8; i ++)
for (int j = 0; j < 8; j += 2)
if (i % 2 == 0 && j == 0)
blackPositions[@array][0] = i;
blackPositions[@array][1] = j;
for (int i = 0; i < 12; i ++)
Checker whiteChecker = new Checker("white", whitePositions[i]);
Checker blackChecker = new Checker("black", blackPositions[i]);
this.Checkers.Add(whiteChecker);
this.Checkers.Add(blackChecker);
public void PlaceCheckers()
int nonPlaySquareId = int.Parse("25A4", System.Globalization.NumberStyles.HexNumber);
string nonPlaySquare = char.ConvertFromUtf32(nonPlaySquareId);
for (int i = 1; i < 9; i ++)
for (int j = 1; j < 9; j ++)
if ((i % 2 == 0 && j % 2 != 0) || (i % 2 != 0 && j % 2 == 0))
Grid[i][j] = nonPlaySquare;
for (int i = 0; i < this.Checkers.Count; i ++)
int row = this.Checkers[i].Position[0] + 1;
int column = this.Checkers[i].Position[1] + 1;
this.Grid[row][column] = this.Checkers[i].Symbol;
public void PlaceChecker(Checker checker, int row, int column)
checker.Position[0] = row;
checker.Position[1] = column;
for (int i = 0; i < 9; i ++)
Console.WriteLine(String.Join(" ", this.Grid[i]));
public Checker SelectChecker(int row, int column)
return Checkers.Find(checkr => checkr.Position.SequenceEqual(
new int[] { row, column }));
public void MoveChecker(Checker checker, int row, int column)
if (Checkers.Find(checkr => checkr.Position.SequenceEqual(
new int[] { row, column })) == null)
if ((Math.Abs(row - checker.Position[0]) == 2 &&
Math.Abs(column - checker.Position[1]) == 2))
if (checker.Color == "black" || checker.King)
if (row - checker.Position[0] == -2 &&
column - checker.Position[1] == 2)
JumpChecker(checker, row + 1, column - 1, row, column);
if (row - checker.Position[0] == -2 &&
column - checker.Position[1] == -2)
JumpChecker(checker, row + 1, column + 1, row, column);
Console.WriteLine("Invalid move");
if (checker.Color == "white" || checker.King)
if (row - checker.Position[0] == 2 &&
column - checker.Position[1] == 2)
JumpChecker(checker, row - 1, column - 1, row, column);
if (row - checker.Position[0] == 2 &&
column - checker.Position[1] == -2)
JumpChecker(checker, row - 1, column + 1, row, column);
Console.WriteLine("Invalid move");
else if (Math.Abs(row - checker.Position[0]) == 1 &&
Math.Abs(column - checker.Position[1]) == 1)
if ((row > checker.Position[0] && checker.Color == "white") ||
(row < checker.Position[0] && checker.Color == "black") ||
PlaceChecker(checker, row, column);
Console.WriteLine("Invalid move");
Console.WriteLine("Invalid move");
Console.WriteLine("Invalid move");
public bool jumpAvailable(Game game, string turn)
IEnumerable<Checker> turnCheckers = Checkers.Where(checker => checker.Color == turn);
foreach (Checker checker in turnCheckers)
if (checker.Color == "black" || checker.King)
if (Checkers.Exists(checkr => checkr.Position.SequenceEqual(
new int[] { checker.Position[0] - 1, checker.Position[1] - 1 }) &&
checkr.Color != checker.Color &&
!Checkers.Exists(checkr1 => checkr1.Position.SequenceEqual(
new int[] { checker.Position[0] - 2, checker.Position[1] - 2 })) &&
(checker.Position[0] != 0 && checker.Position[0] != 1)) ||
(Checkers.Exists(checkr => checkr.Position.SequenceEqual(
new int[] { checker.Position[0] - 1, checker.Position[1] + 1 }) &&
checkr.Color != checker.Color) &&
!Checkers.Exists(checkr => checkr.Position.SequenceEqual(
new int[] { checker.Position[0] - 2, checker.Position[1] + 2 }) &&
(checker.Position[0] != 6 && checker.Position[0] != 7))))
game.jumpCheckers.Add(checker);
if (checker.Color == "white" || checker.King)
if (Checkers.Exists(checkr => checkr.Position.SequenceEqual(
new int[] { checker.Position[0] + 1, checker.Position[1] - 1 }) &&
checkr.Color != checker.Color &&
!Checkers.Exists(checkr1 => checkr1.Position.SequenceEqual(
new int[] { checker.Position[0] + 2, checker.Position[1] - 2 })) &&
(checker.Position[1] != 0 && checker.Position[1] != 1)) ||
(Checkers.Exists(checkr => checkr.Position.SequenceEqual(
new int[] { checker.Position[0] + 1, checker.Position[1] + 1 }) &&
checkr.Color != checker.Color) &&
!Checkers.Exists(checkr => checkr.Position.SequenceEqual(
new int[] { checker.Position[0] + 2, checker.Position[1] + 2 })) &&
(checker.Position[1] != 6 && checker.Position[1] != 7)))
game.jumpCheckers.Add(checker);
if (game.jumpCheckers.Count > 0)
foreach (Checker jumpChecker in game.jumpCheckers)
Console.WriteLine($"Checker at {jumpChecker.Position[0] + 1}, {jumpChecker.Position[1] + 1} can jump.");
public void JumpChecker(Checker checker, int row, int column,
int newRow, int newColumn)
Checker deadChecker = Checkers.Find(checkr => checkr.Position.SequenceEqual(
new int[] { row, column }));
if (deadChecker.Color != checker.Color)
Checkers.Remove(deadChecker);
PlaceChecker(checker, newRow, newColumn);
Console.WriteLine("Invalid move");
public void RemoveChecker(int row, int column)
Checkers.Remove(Checkers.Find(checker => checker.Position.SequenceEqual(
new int[] { row, column })));
public void KingCheck(Checker checker, int row)
if ((checker.Color == "white" && row == 7) ||
(checker.Color == "black" && row == 0))
if (checker.Color == "white")
int kingId = int.Parse("25D4", System.Globalization.NumberStyles.HexNumber);
string king = char.ConvertFromUtf32(kingId);
int kingId = int.Parse("25D5", System.Globalization.NumberStyles.HexNumber);
string king = char.ConvertFromUtf32(kingId);
public bool CheckForWin()
if (Checkers.All(checker => checker.Color == "white"))
Console.WriteLine("White wins!");
else if (!Checkers.Exists(checker => checker.Color == "white"))
Console.WriteLine("Black wins!");
private string winner = "";
public List<Checker> jumpCheckers = new List<Checker>();
Board board = new Board();
board.GenerateCheckers();
while (!board.CheckForWin())
Console.WriteLine("Black's turn");
Console.WriteLine("White's turn");
jump = board.jumpAvailable(this, this.turn);
Console.Write("Enter starting row and column, " +
"separated by a comma: ");
string rowAndColumn = Console.ReadLine();
Regex regex = new Regex(@"\d, *\d");
Match match = regex.Match(rowAndColumn);
if (rowAndColumn != match.Value || rowAndColumn == "")
Console.WriteLine("Invalid entry");
string[] coordinates = rowAndColumn.Split(",");
int startingRow = Convert.ToInt32(coordinates[0]) - 1;
int startingColumn = Convert.ToInt32(coordinates[1]) - 1;
if (jump && !(jumpCheckers.Any(
checker => startingRow == checker.Position[0] &&
startingColumn == checker.Position[1])))
Console.WriteLine("Invalid move");
if (board.Checkers.Find(checker => checker.Position.SequenceEqual(
new int[] { startingRow, startingColumn })) != null)
board.Checkers.Find(checker => checker.Position.SequenceEqual(
new int[] { startingRow, startingColumn }));
Console.WriteLine("Invalid selection");
board.SelectChecker(startingRow, startingColumn);
Console.Write("Enter ending row and column, " +
"separated by a comma: ");
rowAndColumn = Console.ReadLine();
match = regex.Match(rowAndColumn);
if (rowAndColumn != match.Value || rowAndColumn == "")
Console.WriteLine("Invalid entry");
coordinates = rowAndColumn.Split(",");
int endingRow = Convert.ToInt32(coordinates[0]) - 1;
int endingColumn = Convert.ToInt32(coordinates[1]) - 1;
if (jump && !(jumpCheckers.Any(
checker => Math.Abs(endingRow - checker.Position[0]) == 2 ||
Math.Abs(endingColumn - checker.Position[1]) == 2)))
Console.WriteLine("Invalid move");
board.MoveChecker(movingChecker, endingRow, endingColumn);
static void Main(string[] args)