Exemplo n.º 1
0
        private static void test_Piotrka()
        {
            const int         r    = 8;  // number_of_fields_in_row = 8;
            const int         pcs  = 12; // number_of_pieces_per_player = 12;
            Draughts_checkers game = new Draughts_checkers(r, pcs);
            var white_key          = game.Generate_player_key(Color.White);

            Console.WriteLine("White key: " + white_key);

            var black_key = game.Generate_player_key(Color.Black);

            Console.WriteLine("Black key: " + black_key);
            Checkers_piece[,] board = new Checkers_piece[game.Number_of_fields_in_row, game.Number_of_fields_in_row];
            board[0, 1]             = new Checkers_piece(Color.White, Type.Man);
            board[0, 3]             = new Checkers_piece(Color.White, Type.Man);
            board[0, 5]             = new Checkers_piece(Color.Black, Type.King);
            board[0, 7]             = new Checkers_piece(Color.White, Type.Man);
            board[1, 0]             = new Checkers_piece(Color.Black, Type.Man);
            board[0, 3]             = new Checkers_piece(Color.Black, Type.Man);
            board[4, 7]             = new Checkers_piece(Color.White, Type.Man);
            board[6, 1]             = new Checkers_piece(Color.Black, Type.Man);
            board[6, 3]             = new Checkers_piece(Color.Black, Type.Man);
            board[6, 7]             = new Checkers_piece(Color.Black, Type.Man);
            board[7, 0]             = new Checkers_piece(Color.Black, Type.Man);
            board[7, 2]             = new Checkers_piece(Color.Black, Type.Man);
            game.Set_board(Color.Black, board);

            Display_Board.Display_board_of_game(game, game.Check_active_player());
            Make_move_and_display_boards(ref game, black_key, new Coordinates(5, 0), new Coordinates(0, 5));
        }
Exemplo n.º 2
0
        private static Checkers_piece[,] Simulate_a_move(Color moving_player_color, Draughts_checkers original_game, Coordinates origin, Coordinates destination)//does nor change original_board
        {
            //Console.WriteLine("Ruch probuje wykonac gracz " + moving_player_color);
            Draughts_checkers simulate_game = new Draughts_checkers(original_game.Number_of_fields_in_row, original_game.Number_of_pieces_per_player);

            var white_key = simulate_game.Generate_player_key(Color.White);

            var black_key = simulate_game.Generate_player_key(Color.Black);

            simulate_game.Set_board(original_game.Check_active_player(), original_game.Get_copy_of_board(original_game.Check_active_player()));
            simulate_game.Last_moved_piece_coords       = original_game.Last_moved_piece_coords;
            simulate_game.Last_moved_piece_coords_color = original_game.Last_moved_piece_coords_color;

            //Console.WriteLine("Aktywny gracz to " + simulate_game.Check_active_player());

            int active_simulation_player_key = 0;

            if (moving_player_color == Color.Black)
            {
                active_simulation_player_key = black_key;
            }
            else
            {
                active_simulation_player_key = white_key;
            }
            simulate_game.Make_move(active_simulation_player_key, origin, destination);
            //Console.WriteLine("Tu sie powiodlo.");
            return(simulate_game.Get_copy_of_board(moving_player_color));
        }
Exemplo n.º 3
0
        private static void test_move_detector_2()
        {
            const int         r    = 8;  // number_of_fields_in_row = 8;
            const int         pcs  = 12; // number_of_pieces_per_player = 12;
            Draughts_checkers game = new Draughts_checkers(r, pcs);
            var white_key          = game.Generate_player_key(Color.White);
            var black_key          = game.Generate_player_key(Color.Black);

            Draughts_checkers game2 = new Draughts_checkers(r, pcs);
            var white_key2          = game2.Generate_player_key(Color.White);
            var black_key2          = game2.Generate_player_key(Color.Black);

            Make_move_and_display_boards(ref game2, white_key2, new Coordinates(0, 5), new Coordinates(1, 4));

            //Display_board(game, Color.White);
            //Display_board(game2, Color.White);
            //Console.WriteLine("\ntry\n");
            try
            {
                var move = Move_Detector.DetectMove(game.Check_active_player(), game, game2.Get_copy_of_board(Color.Black));
                Console.WriteLine("Wykryto ruch");
                Make_move_and_display_boards(ref game, white_key, new Coordinates(move[0].X, move[0].Y), new Coordinates(move[1].X, move[1].Y));

                Make_move_and_display_boards(ref game2, black_key2, new Coordinates(0, 5), new Coordinates(1, 4));
                move = Move_Detector.DetectMove(game.Check_active_player(), game, game2.Get_copy_of_board(Color.Black));
            }
            catch (Exception e)
            { Console.WriteLine(e.Message); }
        }
Exemplo n.º 4
0
        private static void test_move_detector_1_no_move_detected()
        {
            const int         r    = 8;  // number_of_fields_in_row = 8;
            const int         pcs  = 12; // number_of_pieces_per_player = 12;
            Draughts_checkers game = new Draughts_checkers(r, pcs);
            var white_key          = game.Generate_player_key(Color.White);

            Console.WriteLine("White key: " + white_key);

            var black_key = game.Generate_player_key(Color.Black);

            Console.WriteLine("Black key: " + black_key);
            Checkers_piece[,] board_black = new Checkers_piece[game.Number_of_fields_in_row, game.Number_of_fields_in_row];
            {
                Draughts_checkers game_temp = new Draughts_checkers(r, pcs);
                board_black = game_temp.Get_copy_of_board(Color.Black);
            }
            Display_Board.Display_board_of_game(game, game.Check_active_player());
            try
            {
                var move = Move_Detector.DetectMove(Color.White, game, board_black);
                Make_move_and_display_boards(ref game, black_key, new Coordinates(5, 0), new Coordinates(0, 5));
            }
            catch (Exception e)
            { Console.WriteLine(e.Message); }
        }
Exemplo n.º 5
0
        private static void test_capturing_multiple_oponents_pieces_by_one_king()
        {
            const int         r    = 8;  // number_of_fields_in_row = 8;
            const int         pcs  = 12; // number_of_pieces_per_player = 12;
            Draughts_checkers game = new Draughts_checkers(r, pcs);
            var white_key          = game.Generate_player_key(Color.White);

            Console.WriteLine("White key: " + white_key);

            var black_key = game.Generate_player_key(Color.Black);

            Console.WriteLine("Black key: " + black_key);
            Checkers_piece[,] board = new Checkers_piece[game.Number_of_fields_in_row, game.Number_of_fields_in_row];
            board[4, 1]             = new Checkers_piece(Color.White, Type.Man);
            board[5, 2]             = new Checkers_piece(Color.White, Type.King);
            board[2, 1]             = new Checkers_piece(Color.Black, Type.Man);
            board[6, 5]             = new Checkers_piece(Color.Black, Type.Man);
            board[1, 4]             = new Checkers_piece(Color.Black, Type.Man);
            game.Set_board(Color.White, board);

            Display_Board.Display_board_of_game(game, game.Check_active_player());
            Make_move_and_display_boards(ref game, white_key, new Coordinates(2, 5), new Coordinates(3, 4));
            Make_move_and_display_boards(ref game, black_key, new Coordinates(6, 5), new Coordinates(5, 4));
            //Make_move_and_display_boards(ref game, white_key, new Coordinates(3, 4), new Coordinates(2, 5));//runs exception
            Make_move_and_display_boards(ref game, white_key, new Coordinates(3, 4), new Coordinates(6, 7));//not run exception

            //Make_move_and_display_boards(ref game, white_key, new Coordinates(0, 1), new Coordinates(6, 7));//not run exception
            Make_move_and_display_boards(ref game, white_key, new Coordinates(1, 4), new Coordinates(3, 2));// runs exception
        }
Exemplo n.º 6
0
        private static void test_of_reference_in_functions() //now result is no//bcoz function set_board has been changed to load a copy, not a reference
        {
            const int         r    = 8;                      // number_of_fields_in_row = 8;
            const int         pcs  = 12;                     // number_of_pieces_per_player = 12;
            Draughts_checkers game = new Draughts_checkers(r, pcs);
            var white_key          = game.Generate_player_key(Color.White);

            Console.WriteLine("White key: " + white_key);

            var black_key = game.Generate_player_key(Color.Black);

            Console.WriteLine("Black key: " + black_key);
            Checkers_piece[,] board = new Checkers_piece[game.Number_of_fields_in_row, game.Number_of_fields_in_row];
            board[4, 3]             = new Checkers_piece(Color.White, Type.King);
            board[3, 2]             = new Checkers_piece(Color.Black, Type.Man);
            board[6, 5]             = new Checkers_piece(Color.Black, Type.Man);
            game.Set_board(Color.Black, board);
            Display_Board.Display_board_of_game(game, game.Check_active_player());

            board[1, 0] = new Checkers_piece(Color.Black, Type.King);
            Display_Board.Display_board_of_game(game, game.Check_active_player());
        }
Exemplo n.º 7
0
        private static void test_capturing_oponent_piece_by_multiple_pieces()
        {
            const int         r    = 8;  // number_of_fields_in_row = 8;
            const int         pcs  = 12; // number_of_pieces_per_player = 12;
            Draughts_checkers game = new Draughts_checkers(r, pcs);
            var white_key          = game.Generate_player_key(Color.White);

            Console.WriteLine("White key: " + white_key);

            var black_key = game.Generate_player_key(Color.Black);

            Console.WriteLine("Black key: " + black_key);
            //Display_board(game, Color.White);
            //Display_board(game, Color.Black);
            Make_move_and_display_boards(ref game, white_key, new Coordinates(2, 5), new Coordinates(3, 4));
            Make_move_and_display_boards(ref game, black_key, new Coordinates(0, 5), new Coordinates(1, 4));
            Make_move_and_display_boards(ref game, white_key, new Coordinates(6, 5), new Coordinates(5, 4));
            Make_move_and_display_boards(ref game, black_key, new Coordinates(6, 5), new Coordinates(5, 4));
            //Make_move_and_display_boards(ref game, white_key, new Coordinates(7, 6), new Coordinates(6, 5));//runs wrong way exception
            Make_move_and_display_boards(ref game, white_key, new Coordinates(5, 4), new Coordinates(7, 2));//not run exception
            //Make_move_and_display_boards(ref game, black_key, new Coordinates(5, 4), new Coordinates(6, 3));
        }
Exemplo n.º 8
0
        private static void test_capturing_oponents_piece()
        {
            const int         r    = 8;  // number_of_fields_in_row = 8;
            const int         pcs  = 12; // number_of_pieces_per_player = 12;
            Draughts_checkers game = new Draughts_checkers(r, pcs);
            var white_key          = game.Generate_player_key(Color.White);

            Console.WriteLine("White key: " + white_key);

            var black_key = game.Generate_player_key(Color.Black);

            Console.WriteLine("Black key: " + black_key);
            Display_Board.Display_board_of_game(game, Color.White);
            //Display_board(game, Color.Black);
            Coordinates f1 = new Coordinates(0, 5);
            Coordinates f2 = new Coordinates(1, 4);

            Make_move_and_display_boards(ref game, white_key, f1, f2);
            Make_move_and_display_boards(ref game, black_key, new Coordinates(6, 5), new Coordinates(5, 4));
            Make_move_and_display_boards(ref game, white_key, new Coordinates(2, 5), new Coordinates(3, 4));
            Make_move_and_display_boards(ref game, black_key, new Coordinates(5, 4), new Coordinates(7, 2));
        }
Exemplo n.º 9
0
        private static void test_NOT_change_man_to_king_and_capturings()
        {
            const int         r    = 8;  // number_of_fields_in_row = 8;
            const int         pcs  = 12; // number_of_pieces_per_player = 12;
            Draughts_checkers game = new Draughts_checkers(r, pcs);
            var white_key          = game.Generate_player_key(Color.White);

            Console.WriteLine("White key: " + white_key);

            var black_key = game.Generate_player_key(Color.Black);

            Console.WriteLine("Black key: " + black_key);

            Checkers_piece[,] board = new Checkers_piece[game.Number_of_fields_in_row, game.Number_of_fields_in_row];
            board[2, 7]             = new Checkers_piece(Color.White, Type.Man);
            board[1, 6]             = new Checkers_piece(Color.Black, Type.Man);
            board[1, 4]             = new Checkers_piece(Color.Black, Type.Man);
            game.Set_board(Color.White, board);

            Display_Board.Display_board_of_game(game, game.Check_active_player());
            Make_move_and_display_boards(ref game, white_key, new Coordinates(7, 2), new Coordinates(5, 0));
            Make_move_and_display_boards(ref game, white_key, new Coordinates(5, 0), new Coordinates(3, 2));
        }