Example #1
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); }
        }
Example #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));
        }
Example #3
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));
        }
Example #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); }
        }
Example #5
0
 public static void Make_move_and_display_boards(ref Draughts_checkers game, int player_secret_key, Coordinates origin, Coordinates destination)
 {
     Console.WriteLine("\n" + origin.ToString() + " -> " + destination.ToString());
     game.Make_move(player_secret_key, origin, destination);
     Display_Board.Display_board_of_game(game, game.Check_player_color(player_secret_key));
     Display_Board.Display_board_of_game(game, game.Check_active_player());
 }
Example #6
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
        }
Example #7
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());
        }
Example #8
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));
        }
Example #9
0
        public static Coordinates[] DetectMove(Color moving_player_color, Draughts_checkers game_before, Checkers_piece[,] real_black_board_after)
        {
            var board_before = game_before.Get_copy_of_board(game_before.Check_active_player());

            Checkers_piece[,] board_after;// = new Checkers_piece[game_before.Number_of_fields_in_row, game_before.Number_of_fields_in_row];
            if (moving_player_color == Color.Black)
            {
                board_after = real_black_board_after;
            }
            else
            {
                board_after = Rotate_board(real_black_board_after, game_before.Number_of_fields_in_row);
            }

            List <Coordinates> possible_origins      = new List <Coordinates>();
            List <Coordinates> possible_destinations = new List <Coordinates>();

            for (int i = 0; i < game_before.Number_of_fields_in_row; i++)     //i is row
            {
                for (int j = 0; j < game_before.Number_of_fields_in_row; j++) //j is column
                {
                    if (board_before[i, j] != board_after[i, j])
                    {
                        if (board_before[i, j] != null && board_after[i, j] == null)
                        {
                            possible_origins.Add(new Coordinates(j, i));
                        }
                        else if (board_before[i, j] == null && board_after[i, j] != null)
                        {
                            possible_destinations.Add(new Coordinates(j, i));
                        }
                        else
                        {
                            throw new Exception("Incompatible state of origin end final board!");
                        }
                    }
                }
            }
            if (possible_origins.Count == 0 && possible_destinations.Count == 0)
            {
                throw new Exception("No move detected!");
            }
            if (possible_destinations.Count != 1)
            {
                throw new Exception("You have to move exactly one piece!");
            }

            //szukanie pionka o kolorze tego, ktory sie pojawil na nowym polu
            List <Coordinates> moved_pieces = new List <Coordinates>();

            foreach (var position in possible_origins)
            {
                if (board_before[position.Y, position.X].Color == board_after[possible_destinations[0].Y, possible_destinations[0].X].Color)
                {
                    moved_pieces.Add(position);
                }
            }
            if (moved_pieces.Count != 1)
            {
                throw new Exception("You have to move exactly one piece!");
            }

            //symulowanie ruchu
            var after_simulation_board = Simulate_a_move(moving_player_color, game_before, moved_pieces[0], possible_destinations[0]);

            for (int i = 0; i < game_before.Number_of_fields_in_row; i++)     //i is row
            {
                for (int j = 0; j < game_before.Number_of_fields_in_row; j++) //j is column
                {
                    if (after_simulation_board[i, j] != board_after[i, j])
                    {
                        throw new Exception("Wrong state of final board!");
                    }
                }
            }
            return(new Coordinates[2] {
                moved_pieces[0], possible_destinations[0]
            });
        }