Пример #1
0
        static void Main(string[] args)
        {
            Board board = new Board();

            board.putPawn(new Pawn(BoardSide.MAX));
            board.putPawn(new Pawn(BoardSide.MAX));
            board.putPawn(new Pawn(BoardSide.MAX));
            board.putPawn(new Pawn(BoardSide.MAX));
            board.putPawn(new Pawn(BoardSide.MAX));
            board.putPawn(new Pawn(BoardSide.MAX));

            board.putPawn(new Pawn(BoardSide.MIN));
            board.putPawn(new Pawn(BoardSide.MIN));
            board.putPawn(new Pawn(BoardSide.MIN));

            System.Console.WriteLine("before: ");
            board.printBoard();


            Move nextMove = Minmax.getNextMove(board);

            System.Console.WriteLine("after: ");
            nextMove.executeMove();
            nextMove.getBoard().printBoard();
            System.Console.ReadLine();

            /*
             * board.toggleTurnOwner();
             * System.Console.WriteLine("possible: ");
             * board.printPossibleBoards();
             * System.Console.ReadLine();*/
        }
Пример #2
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Move nextMove = Minmax.getNextMove(board);

            Board.delete = false;
            int returned = nextMove.executeMove();

            while (returned == 1)
            {
                nextMove     = Minmax.getNextMove(board);
                Board.delete = false;
                returned     = nextMove.executeMove();
            }
            board = nextMove.getBoard();
            checkpawn();
        }
Пример #3
0
        void button_Click(object sender, MouseButtonEventArgs e)
        {
            if (putpawns == true)
            {
                if (board.getMinSidePawnCount() < 12)
                {
                    BoardSide who = board.getTurnOwner();
                    String    a   = Convert.ToString(who);
                    if (a == "MAX")
                    {
                        String   b  = (String)(sender as Image).Tag;
                        String[] bb = b.Split(' ');

                        int returned = board.putPawn(new BoardSquare(Convert.ToInt32(bb[1]), Convert.ToInt32(bb[0])), new Pawn(BoardSide.MAX));
                        checkpawn();
                        // MessageBox.Show(string.Format("Kliknęłeś pionek na pozycji: {0}", (sender as Image).Tag));
                        if (returned == 2)
                        {
                            MessageBox.Show("Niedozwolony ruch!");
                        }
                        else
                        if (returned == 1)
                        {
                            MessageBox.Show("Pionek na tym polu już istnieje!");
                        }
                        else
                        {
                            board.putPawn(new Pawn(BoardSide.MIN));
                            checkpawn();
                        }
                    }
                }
                if (board.getMinSidePawnCount() == 12)
                {
                    putpawns = false;
                }
            }
            else
            {
                int testtocheck    = 0;
                int checkStateGame = board.isEnd(testtocheck);
                if (checkStateGame == 0)
                {
                    int returned  = -1;
                    int returneed = -1;
                    if (click == true)
                    {
                        String   b  = (String)(sender as Image).Tag;
                        String[] bb = b.Split(' ');

                        Move mv = new Move(board, board.getBoardSquare(x, y), board.getBoardSquare(Convert.ToInt32(bb[0]), Convert.ToInt32(bb[1])));
                        returned = mv.executeMove();
                        if (returned == 1)
                        {
                            MessageBox.Show("Niemożliwy ruch!");
                        }

                        checkpawn();



                        click = false;
                        this.images[x, y].Tag = x + " " + y + " " + "a";
                    }
                    if (click == false)
                    {
                        String   b  = (String)(sender as Image).Tag;
                        String[] bb = b.Split(' ');
                        //MessageBox.Show(images[Convert.ToInt32(bb[0]), Convert.ToInt32(bb[1])].Tag.ToString());
                        this.images[Convert.ToInt32(bb[0]), Convert.ToInt32(bb[1])].Tag = bb[0] + " " + bb[1] + " " + "b";
                        // MessageBox.Show(images[Convert.ToInt32(bb[0]), Convert.ToInt32(bb[1])].Tag.ToString());
                        x     = Convert.ToInt32(bb[0]);
                        y     = Convert.ToInt32(bb[1]);
                        click = true;
                    }


                    if (Board.delete == true)
                    {
                        if (canDelete == true)
                        {
                            String   b  = (String)(sender as Image).Tag;
                            String[] bb = b.Split(' ');
                            returneed = deletePawn(Convert.ToInt32(bb[0]), Convert.ToInt32(bb[1]));
                            if (returneed == 1)
                            {
                                MessageBox.Show("Tego pionka nie można usunąć!");
                            }
                        }
                        else
                        {
                            if (board.getTurnOwner().ToString() == "MAX")
                            {
                                MessageBox.Show("Usuń pionek!");
                                canDelete = true;
                            }
                            else
                            {
                                List <BoardSquare> AllMaxPawns = board.findAllMax();
                                Random             rand        = new Random();
                                int a = rand.Next(AllMaxPawns.Count - 1);
                                int i = 1;
                                while (i == 1)
                                {
                                    if (i == 1)
                                    {
                                        i = deletePawn(AllMaxPawns[a].getRowCoord(), AllMaxPawns[a].getColumnCoord());
                                        a = rand.Next(AllMaxPawns.Count - 1);
                                    }
                                }
                            }
                        }
                    }
                    bool enemydel = false;
                    if (Board.delete != true)
                    {
                        if (returned == 0 || returneed == 0)
                        {
                            board.toggleTurnOwner();
                            Move nextMove = Minmax.getNextMove(board);
                            //Board.delete = false;
                            int returnedd = nextMove.executeMove();
                            while (returnedd == 1)
                            {
                                nextMove     = Minmax.getNextMove(board);
                                Board.delete = false;
                                returnedd    = nextMove.executeMove();
                            }
                            board = nextMove.getBoard();
                            board.toggleTurnOwner();

                            checkpawn();
                            if (Board.delete == true)
                            {
                                enemydel = true;
                            }
                        }
                    }
                    if (Board.delete == true)
                    {
                        if (enemydel == true)
                        {
                            if (board.getTurnOwner().ToString() == "MAX")
                            {
                                List <BoardSquare> AllMaxPawns = board.findAllMax();
                                Random             rand        = new Random();
                                int a = rand.Next(AllMaxPawns.Count - 1);
                                int i = 1;
                                while (i == 1)
                                {
                                    if (i == 1)
                                    {
                                        i = deletePawn(AllMaxPawns[a].getRowCoord(), AllMaxPawns[a].getColumnCoord());
                                        a = rand.Next(AllMaxPawns.Count - 1);
                                    }
                                }
                                enemydel = false;
                            }
                        }
                    }
                }
                if (checkStateGame == 1)
                {
                    MessageBox.Show("KONIEC! WYGRAŁEŚ!!!!");
                }
                if (checkStateGame == 2)
                {
                    MessageBox.Show("KONIEC! PRZEGRAŁEŚ...");
                }
            }
        }