using System.Collections.Generic;
using System.Threading.Tasks;
static void Main(string[] args)
Dictionary<string,string> pieces = InitPlayerPieces();
public static Dictionary<string, string> InitPlayerPieces()
string input = Console.ReadLine().ToLower();
string piecesPosition = "";
Dictionary<string, string> pieces = InitPlayer1Piece();
pieces = InitPlayer2Piece();
foreach (KeyValuePair<string, string> piece in pieces)
piecesPosition += piece.Key.Substring(0, 3) + "-" + piece.Value + ",";
Console.WriteLine(piecesPosition.Substring(0, piecesPosition.Length - 1));
public static Dictionary<string,string> InitPlayer1Piece()
return new Dictionary<string, string>(){{"GNA", "D5"},
public static Dictionary<string, string> InitPlayer2Piece()
return new Dictionary<string,string>() {{"GNA","H1"},
public static List<string> InitRemainingRanks()
return new List<string> {"GNA",
public static string Moves(List<string> ranks, Dictionary<string, string> pieces)
List<string> possibleMove;
for (int x = 0; x < ranks.Count; x++)
if(pieces.Any(v => v.Key.Contains(ranks[x])))
var rank = pieces.Where(p => p.Key.Contains(ranks[x])).FirstOrDefault();
possibleMove = Move(rank.Value, pieces);
if(possibleMove.Count > 0)
int ndx = r.Next(0, possibleMove.Count - 1);
Console.WriteLine("{0}-{1}", rank.Value, possibleMove[ndx]);
pieces[rank.Key] = possibleMove[ndx];
currentMove = possibleMove[ndx];
public static List<string> Move(string pos, Dictionary<string, string> pieces)
List<string> possibleMove = new List<string>();
int[] test = new int[] {-1, -0 , 1};
for (int x = 0; x < 3; x++)
r = Convert.ToInt32(pos[0])+ test[x];
for (int y = 0; y < 3; y++)
c = (pos[1] + test[y]) - '0';
move = Convert.ToChar(r).ToString() + c.ToString();
if (c <= 10 && c >= 1 && !pieces.ContainsValue(move))
public static void PlayGame(Dictionary<string, string> pieces)
List<string> ranks = InitRemainingRanks();
while (!string.IsNullOrEmpty(checkPiece = Console.ReadLine().ToUpper()) )
opponentMove = checkPiece.Split('-');
if((opponentMove.Length == 1))
removeRank = opponentMove[1];
if ((opponentMove.Length == 3 && (checkPiece.Contains("DRAW"))) || (opponentMove.Length == 3 && (checkPiece.Contains("WIN")) || (( checkPiece == "LOSE") || (checkPiece == "DRAW"))))
var rank = pieces.Where(p => p.Value.Contains(removeRank)).FirstOrDefault();
if (opponentMove.Length == 3)
lastMove = Moves(ranks, pieces);
lastMove = Moves(ranks, pieces);