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); } }
private void field_Click(object sender, System.EventArgs e) { MyPicBox box = sender as MyPicBox; Coordinate move = new Coordinate(box.x, box.y); Console.WriteLine("Got click on field: {0}", move); if (!valid(move)) { MessageBox.Show("Invalid move " + move); } else { RegHumanMove(move); if (winning(1)) { MessageBox.Show(this, "You win"); DumpHistory(); ai = new NewAiPlayer(); } else { ai.RegOppMove(move); move = ai.GetMove(); RegAiMove(move); if (winning(-1)) { MessageBox.Show("You lost"); DumpHistory(); ai = new NewAiPlayer(); } } } }
public override void brain_opponents(int x, int y) { Console.SetOut(TextWriter.Null); ai.RegOppMove(new Coordinate(x, y)); Console.SetOut(output); }
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); } }