Esempio n. 1
0
        /// <summary>
        ///     Fuknce generujici nejlepsi tah
        /// </summary>
        /// <param name="gb">instance tridy hraci deska</param>
        /// <param name="depth">hloubka minimaxu</param>
        /// <returns>Vraci list dvou hracich poli, kde na 1. miste je tah odkud a na 2. poli kam</returns>
        public List <Fairway> bestMove(Gameboard gb, int depth)
        {
            Gameboard potomek = gb.gameboardCopy();

            rules.generateMoves(potomek);

            List <Fairway> moves    = generateMoves(potomek);
            var            bestMove = new List <Fairway>();
            double         bestRank = -GlobalVariables.MAX;

            for (int i = 0; i < moves.Count; i += 2)
            {
                // potomek <- zahraj(pozice, tah)
                rules.makeMove(moves[i], moves[i + 1], potomek, true);
                double rank;

                if (depth == 0)
                {
                    rank = evalFunction(potomek);
                }
                else
                {
                    rank = -minimax(potomek, depth - 1);
                }

                if (rank > bestRank)
                {
                    bestMove = new List <Fairway>();
                    bestRank = rank;
                    bestMove.Add(moves[i]);
                    bestMove.Add(moves[i + 1]);
                }
                if (rank == bestRank)
                {
                    bestMove.Add(moves[i]);
                    bestMove.Add(moves[i + 1]);
                }
            }
            return(bestMove);
        }
Esempio n. 2
0
        /// <summary>
        ///     Funkce provadejici nacteni hry a zkontrolovani, zda se jedna o korektni ulozeni
        /// </summary>
        /// <param name="filePath">cesta k souboru</param>
        /// <param name="gb">Hraci deska, na niz maji byt zmeny provedeny</param>
        /// <returns>Hraci desku s odehratou hrou</returns>
        public Gameboard loadGame(string filePath, Gameboard gb)
        {
            string  from = "";
            string  to   = "";
            Fairway fwFrom;
            Fairway fwTo;
            var     rules = new Rules();

            gb.Board = gb.newBoard();

            using (XmlReader reader = XmlReader.Create(filePath))
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        switch (reader.Name)
                        {
                        // nacteme si obtiznost bileho hrace a nastavime
                        case "WHITE":
                            if (reader.Read())
                            {
                                int whitePlayer = Convert.ToInt32(reader.Value.Trim());
                                gb.WhitePlayer = whitePlayer;
                            }
                            break;

                        // nacteme si obtiznost cerneho hrace a nastavime
                        case "BLACK":
                            if (reader.Read())
                            {
                                int blackPlayer = Convert.ToInt32(reader.Value.Trim());
                                gb.BlackPlayer = blackPlayer;
                            }
                            break;

                        // nacteme si zacinajiciho hrace a nastavime
                        case "STARTS":
                            if (reader.Read())
                            {
                                bool startsWhite = Convert.ToBoolean(reader.Value.Trim());
                                gb.StartsWhite = startsWhite;
                            }
                            break;

                        //
                        case "SHOWHELP":
                            if (reader.Read())
                            {
                                bool showHelp = Convert.ToBoolean(reader.Value.Trim());
                                gb.ShowMoveHelp = showHelp;
                            }
                            break;

                        case "FROM":
                            if (reader.Read())
                            {
                                from = reader.Value.Trim();
                            }
                            break;

                        case "TO":
                            if (reader.Read())
                            {
                                to = reader.Value.Trim();
                            }
                            fwFrom = gb.getFigure(from);
                            fwTo   = gb.getFigure(to);
                            rules.generateMoves(gb);
                            rules.makeMove(fwFrom, fwTo, gb, false);
                            gb.addHistory(fwFrom, fwTo);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }

            return(gb);
        }
Esempio n. 3
0
        /// <summary>
        /// Funkce provadejici nacteni hry a zkontrolovani, zda se jedna o korektni ulozeni
        /// </summary>
        /// <param name="filePath">cesta k souboru</param>
        /// <param name="gb">Hraci deska, na niz maji byt zmeny provedeny</param>
        /// <returns>Hraci desku s odehratou hrou</returns>
        public Gameboard loadGame(string filePath, Gameboard gb)
        {
            string from = "";
            string to = "";
            Fairway fwFrom;
            Fairway fwTo;
            Rules rules = new Rules();

            gb.Board = gb.newBoard();

            using (XmlReader reader = XmlReader.Create(filePath))
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        switch (reader.Name)
                        {
                            // nacteme si obtiznost bileho hrace a nastavime
                            case "WHITE":
                                if (reader.Read())
                                {
                                    int whitePlayer = Convert.ToInt32(reader.Value.Trim());
                                    gb.WhitePlayer = whitePlayer;
                                }
                                break;
                            // nacteme si obtiznost cerneho hrace a nastavime
                            case "BLACK":
                                if (reader.Read())
                                {
                                    int blackPlayer = Convert.ToInt32(reader.Value.Trim());
                                    gb.BlackPlayer = blackPlayer;
                                }
                                break;

                            // nacteme si zacinajiciho hrace a nastavime
                            case "STARTS":
                                if (reader.Read())
                                {
                                    bool startsWhite = Convert.ToBoolean(reader.Value.Trim());
                                    gb.StartsWhite = startsWhite;
                                }
                                break;
                            //
                            case "SHOWHELP":
                                if (reader.Read())
                                {
                                    bool showHelp = Convert.ToBoolean(reader.Value.Trim());
                                    gb.ShowMoveHelp = showHelp;
                                }
                                break;

                            case "FROM":
                                if (reader.Read())
                                    from = (string)reader.Value.Trim();
                                break;

                            case "TO":
                                if (reader.Read())
                                    to = (string)reader.Value.Trim();
                                fwFrom = gb.getFigure(from);
                                fwTo = gb.getFigure(to);
                                rules.generateMoves(gb);
                                rules.makeMove(fwFrom, fwTo, gb, false);
                                gb.addHistory(fwFrom, fwTo);
                                break;

                            default:
                                break;
                        }
                    }
                }
            }

            return gb;
        }