예제 #1
0
        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 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 override void brain_turn()
    {
        int limit = Math.Min(info_timeout_turn, info_time_left / 10) / 1000;

        ai.dbtimelimit = ai.ddbtimelimit = limit / 4;
        ai.abtimelimit = Math.Max(1, limit - ai.dbtimelimit - ai.ddbtimelimit - 1);

        Console.SetOut(TextWriter.Null);
        Coordinate coord = ai.GetMove();

        Console.SetOut(output);
        do_mymove(coord.X, coord.Y);
    }
예제 #4
0
        //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;
        }
예제 #5
0
    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;
        }