public static void Main(string[] args) { Console.WriteLine("GoBang 0.001"); string host; int port; if (args.Length < 2) { host = "localhost"; port = 7777; } else { host = args[0]; port = int.Parse(args[1]); } Player one = new NewAiPlayer(); //Player two = new NewAiPlayer(); Player two = new Communicator(host, port); string color = two.AskColor(); int size = two.AskSize(); if (color == "white") { one.SetColor("white"); two.SetColor("black"); } else { Player tmp = one; one = two; two = tmp; one.SetColor("white"); two.SetColor("black"); } one.SetSize(size); two.SetSize(size); int[,] board = new int[size, size]; Coordinate move; while (true) { move = one.GetMove(); Console.WriteLine("Got move from player 1: {0}", move); if (!valid(board,move)) throw new Exception("Invalid move " + move); board[move.X, move.Y] = 1; printBoard(board); if (winning(board, 1)) throw new Exception("white has won"); two.RegOppMove(move); move = two.GetMove(); Console.WriteLine("Got move from player 2: {0}", move); if (!valid(board,move)) throw new Exception("Invalid move " + move); board[move.X, move.Y] = -1; printBoard(board); if (winning(board, -1)) throw new Exception("black has won"); one.RegOppMove(move); } }
public static void Main(string[] args) { Console.WriteLine("GoBang 0.001"); string host; int port; if (args.Length < 2) { host = "localhost"; port = 7777; } else { host = args[0]; port = int.Parse(args[1]); } Player one = new NewAiPlayer(); //Player two = new NewAiPlayer(); Player two = new Communicator(host, port); string color = two.AskColor(); int size = two.AskSize(); if (color == "white") { one.SetColor("white"); two.SetColor("black"); } else { Player tmp = one; one = two; two = tmp; one.SetColor("white"); two.SetColor("black"); } one.SetSize(size); two.SetSize(size); int[,] board = new int[size, size]; Coordinate move; while (true) { move = one.GetMove(); Console.WriteLine("Got move from player 1: {0}", move); if (!valid(board, move)) { throw new Exception("Invalid move " + move); } board[move.X, move.Y] = 1; printBoard(board); if (winning(board, 1)) { throw new Exception("white has won"); } two.RegOppMove(move); move = two.GetMove(); Console.WriteLine("Got move from player 2: {0}", move); if (!valid(board, move)) { throw new Exception("Invalid move " + move); } board[move.X, move.Y] = -1; printBoard(board); if (winning(board, -1)) { throw new Exception("black has won"); } one.RegOppMove(move); } }