public override void MakeMove(ref Board theBoard) { int[] numArray = new int[9] { 4,0,2,6,8,1,3,5,7 }; int move = 0; bool flag = false; while (!flag && move < theBoard.NumofSquares) { if (theBoard.IsLegalMove(move)) { theBoard.ReceiveMove(this.m_Piece, move); flag = theBoard.IsWinner(this.m_Piece); theBoard.ReceiveMove(' ', move); } if (!flag) ++move; } if (!flag) move = 0; while (!flag && move < theBoard.NumofSquares) { if (theBoard.IsLegalMove(move)) { theBoard.ReceiveMove(this.GetOpponentPiece(), move); flag = theBoard.IsWinner(this.GetOpponentPiece()); theBoard.ReceiveMove(' ', move); } if (!flag) ++move; } for (int index = 0; !flag && index < theBoard.NumofSquares; ++index) { move = numArray[index]; if (theBoard.IsLegalMove(move)) flag = true; } theBoard.ReceiveMove(this.m_Piece, move); }
public override void MakeMove(ref Board theBoard) { int result; do { Console.WriteLine("Player " + (object)this.m_Piece + " make your move."); int.TryParse(Console.ReadLine(), out result); if (!theBoard.IsLegalMove(result)) Console.WriteLine("Player " + (object)this.m_Piece + "illegal move! Try again."); } while (!theBoard.IsLegalMove(result)); theBoard.ReceiveMove(this.m_Piece, result); }