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); } }
//Player starts private void menuItem4_Click(object sender, System.EventArgs e) { next_turn.Image = own.Image; ai = new NewAiPlayer(); ai.SetColor("black"); ai.SetSize(15); ResetGame(); }
public override void brain_restart() { output = Console.Out; Console.SetOut(TextWriter.Null); ai = new NewAiPlayer(); ai.SetSize(width); Console.SetOut(output); Console.WriteLine("OK"); }
//Computer starts button private void menuItem3_Click(object sender, System.EventArgs e) { next_turn.Image = opp.Image; ai = new NewAiPlayer(); ai.SetColor("white"); ai.SetSize(15); ResetGame(); Coordinate move; move = ai.GetMove(); Console.WriteLine("Got move from player 1: {0}", move); if (!valid(move)) { throw new Exception("Invalid move " + move); } RegAiMove(move); next_turn.Image = opp.Image; }
public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // InitBoard(); // Let the player start by default ai = new NewAiPlayer(); ai.SetColor("black"); ai.SetSize(15); my_color.Image = opp.Image; your_color.Image = own.Image; next_turn.Image = own.Image; }
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); } }
//Computer starts button private void menuItem3_Click(object sender, System.EventArgs e) { next_turn.Image = opp.Image; ai = new NewAiPlayer(); ai.SetColor("white"); ai.SetSize(15); ResetGame(); Coordinate move; move = ai.GetMove(); Console.WriteLine("Got move from player 1: {0}", move); if (!valid(move)) throw new Exception("Invalid move " + move); RegAiMove(move); next_turn.Image = opp.Image; }