public void HorizontalMovesO(ITicTacToe g, int row) { int low = 0; int high = 1; switch (row) { case 0: low = 1; high = 2; break; case 1: low = 0; high = 2; break; case 2: low = 0; high = 1; break; default: break; } for (int x = 0; x < 3; ++x) { g.TryPlaceMarkAt(PlayerMark.X, x, x == 1 ? high : low); g.TryPlaceMarkAt(PlayerMark.O, x, row); } }
public void VerticalMovesO(ITicTacToe g, int column) { int low = 0; int high = 1; switch (column) { case 0: low = 1; high = 2; break; case 1: low = 0; high = 2; break; case 2: low = 0; high = 1; break; default: break; } for (int y = 0; y < 3; ++y) { g.TryPlaceMarkAt(PlayerMark.X, y == 1 ? high : low, y); g.TryPlaceMarkAt(PlayerMark.O, column, y); } }
static void TakeTurn(ITicTacToe g) { PlayerMark whoturn = g.GetWhoTurn(); bool placed = false; while (!placed) { bool gotX = false; bool gotY = false; int x, y; x = y = 0; Console.WriteLine("Entering Player Move For: {0}", GetMark(whoturn)); while (!gotX) { Console.WriteLine("Enter Column:"); string lineIn = Console.ReadLine(); gotX = int.TryParse(lineIn, out x); } while (!gotY) { Console.WriteLine("Enter Row:"); string lineIn = Console.ReadLine(); gotY = int.TryParse(lineIn, out y); } placed = g.TryPlaceMarkAt(whoturn, x, y); if (!placed) { Console.WriteLine("Invalid Move!"); } } }
void TestMovesExpectWinner(ITicTacToe g, point[] moves, PlayerMark winner) { foreach (point p in moves) { g.TryPlaceMarkAt(g.GetWhoTurn(), p.x, p.y); } Assert.IsTrue(g.IsGameOver()); Assert.AreEqual <PlayerMark>(winner, g.GetWinner()); }